【问题标题】:Elasticsearch 5.1 and Docker - How to get networking configured properly to reach Elasticsearch from the hostElasticsearch 5.1 和 Docker - 如何正确配置网络以从主机访问 Elasticsearch
【发布时间】:2017-06-04 19:01:42
【问题描述】:

使用 Docker 公共存储库中的 Elasticsearch:latest (v5.1),我创建了自己的包含 Cerebro 的图像。我现在正在尝试正确配置 Elasticsearch 网络,以便我可以从 Cerebro 连接到 Elasticsearch。 Cerebro 在我创建的容器内运行,在我的主机上正确呈现:http://localhost:9000

提交映像后,我使用以下内容创建了 Docker 容器:

sudo docker run -d -it --privileged --name es5.1 --restart=always \
-p 9200:9200 \
-p 9300:9300 \
-p 9000:9000 \
-v ~/elasticsearch/5.1/config:/usr/share/elasticsearch/config \
-v ~/elasticsearch/5.1/data:/usr/share/elasticsearch/data \
-v ~/elasticsearch/5.1/cerebro/conf:/root/cerebro-0.4.2/conf \
elasticsearch_cerebro:5.1 \
/root/cerebro-0.4.2/bin/cerebro

我在 ~/elasticsearch/5.1/config 中的 elasticsearch.yml 当前指定了以下网络和发现条目:

network.publish_host: 192.168.1.26
discovery.zen.ping.unicast.hosts: ["192.168.1.26:9300"]

我也尝试过 0.0.0.0 并且没有指定这些设置的默认环回值。此外,我尝试使用值组合指定 network.host。无论我如何设置,elasticsearch 都会在启动时登录:

[info] play.api.Play - Application started (Prod)
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
[error] p.c.s.n.PlayDefaultUpstreamHandler - Cannot invoke the action
java.net.ConnectException: Connection refused: localhost/127.0.0.1:9200
… cascading errors because of this connection refusal...

无论我如何设置 elasticsearch.yml 网络,Elasticsearch 启动时的错误消息都不会改变。我验证了 elasticsearch.yml 是否在 Docker 容器内被拾取。请让我知道我的配置是否有问题。

【问题讨论】:

    标签: elasticsearch docker


    【解决方案1】:

    好吧,经过几天的战斗,看起来我正在回答我自己的问题!问题是弹性搜索没有在容器内启动。为了确定这一点,我在容器中安装了一个终端:

    docker exec -it es5.1 bash
    

    进入容器后,我检查了服务状态:

    service elasticsearch status
    

    对此,操作系统回应:

    [FAIL] elasticsearch 没有运行...失败!

    我是这样开始的:

    service elasticsearch start
    

    我添加了一个脚本,我将从 docker run 调用它来启动 elasticsearch 和 cerebro,这应该可以解决问题。但是,我仍然想知道是否有更好的方法来配置它。

    【讨论】:

    • 您绝对不希望服务在 Docker 容器中运行。您真的希望 Elasticsearch 进程作为唯一进程在前台运行。服务和 cron 作业不会在容器内运行。
    • 谢谢。我认为您已经解决了这个问题,我正在尝试将 ES 作为服务运行在容器中。
    【解决方案2】:

    我创建了一个 github docker-compose 存储库,它将启动 elasticsearch、kibana、logstash、cerebro 集群

    https://github.com/Shuliyey/elkc

    ================================================ ==========================

    另一方面,关于实际问题(elasticsearch_cerebro 不工作)。

    让 elasticsearch 和 cerebro 在一个 docker 容器中工作。需要使用主管

    https://docs.docker.com/engine/admin/using_supervisord/

    将更新更多细节

    【讨论】:

    • 谢谢你,舒利耶!这正是我所需要的。
    【解决方案3】:

    根本不需要使用主管。解决这个问题的一个非常简单的方法是使用 docker-compose 并将 Elasticsearch 和 Cerebro 捆绑在一起,如下所示:

    docker-compose.yml:

    version: '2'
    
    services:
    
      elasticsearch:
        build: elasticsearch
        volumes:
          - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - ./elasticsearch/data:/usr/share/elasticsearch/data
        ports:
          - "9200:9200"
          - "9300:9300"
        environment:
          ES_JAVA_OPTS: "-Xmx1500m -Xms1500m"
        networks:
          - elk
    
      cerebro:
        build: cerebro
        volumes:
          - ./cerebro/config/application.conf:/opt/cerebro/conf/application.conf
        ports:
          - "9000:9000"
        networks:
          - elk
        depends_on:
          - elasticsearch
    
    networks:
      elk:
        driver: bridge
    

    弹性搜索/Dockerfile:

    FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.1
    

    脑/Dockerfile:

    FROM yannart/cerebro
    

    然后运行docker-compose builddocker-compose up。一切启动后,您可以访问http://localhost:9200 的ES 和http://localhost:9000 的Cerebro

    【讨论】:

      猜你喜欢
      • 2019-03-18
      • 2018-04-21
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 2021-09-13
      • 2018-01-06
      • 2018-11-14
      • 1970-01-01
      相关资源
      最近更新 更多