繁体   English   中英

Elasticsearch 5.1和Docker - 如何正确配置网络以从主机访问Elasticsearch

[英]Elasticsearch 5.1 and Docker - How to get networking configured properly to reach Elasticsearch from the host

使用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容器中被拾取。 如果我的配置错误,请告诉我。

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

docker exec -it es5.1 bash

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

service elasticsearch status

对此,操作系统回复:

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

我开始时:

service elasticsearch start

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

我做了一个github docker-compose repo,它将启动弹性搜索,kibana,logstash,cerebro cluster

https://github.com/Shuliyey/elkc

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

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

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

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

将更新更多详细信息

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

泊坞窗,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

elasticsearch / Dockerfile:

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

脑/ Dockerfile:

FROM yannart/cerebro

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM