本文介绍了Elasticsearch 5.1和Docker-如何正确配置网络以从主机访问Elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using Elasticsearch:latest (v5.1) from the Docker public repo, I created my own image containing Cerebro. I am now attempting to get Elasticsearch networking properly configured so that I can connect to Elasticsearch from Cerebro. Cerebro running inside of the container I created, renders properly on my host at: http://localhost:9000.

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

After committing my image, I created my Docker container with the following:

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.yml在〜/ elasticsearch / 5.1 / config当前指定了以下网络和发现条目:

my elasticsearch.yml in ~/elasticsearch/5.1/config currently has the following network and discovery entries specified:

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

我也尝试了0.0。 0.0,并且未指定这些设置的默认值,即默认为环回。另外,我尝试使用值的组合指定network.host。无论我如何设置,elasticsearch都会在启动时登录:

I have also tried 0.0.0.0 and not specifying the values to default to the loopback for these settings. In addition, I've tried specifying network.host with a combination of values. No matter how I set this, elasticsearch logs on startup:

[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容器中提取了。请告知我该配置是否有误。

No matter how I set the elasticsearch.yml networking, the error message on Elasticsearch startup does not change. I verified that the elasticsearch.yml is being picked-up inside of the Docker container. Please let me know were I'm going wrong with this configuration.

推荐答案

完全不需要使用超级用户。解决此问题的一种非常简单的方法是使用docker-compose并将Elasticsearch和Cerebro捆绑在一起,如下所示:

No need to use supervisor at all. A very simple way to solve this is to use docker-compose and bundle Elasticsearch and Cerebro together, like this:

docker-compose.yml:

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

elasticse arch / Dockerfile:

elasticsearch/Dockerfile:

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

cerebro / Dockerfile:

cerebro/Dockerfile:

FROM yannart/cerebro

然后您运行 docker-compose build docker-compose up 。一切开始后,您可以通过访问ES,并通过

Then you run docker-compose build and docker-compose up. When everything is started, you can access ES at http://localhost:9200 and Cerebro at http://localhost:9000

这篇关于Elasticsearch 5.1和Docker-如何正确配置网络以从主机访问Elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:34