简体   繁体   English

使用 Docker 进行弹性搜索

[英]Elastic Search with Docker

I ran the following docker compose script and I am expecting two nodes to be up, however this only one.我运行了以下 docker 撰写脚本,我希望有两个节点启动,但只有一个。 There seems to be some obvious error.似乎有一些明显的错误。

Taken from the documentation取自文档

version: '2.2'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.8.12
    container_name: elasticsearch
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  elasticsearch2:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.8.12
    container_name: elasticsearch2
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - "discovery.zen.ping.unicast.hosts=elasticsearch"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata2:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata1:
    driver: local
  esdata2:
    driver: local

networks:
  esnet:

http://127.0.0.1:9200/_cat/health http://127.0.0.1:9200/_cat/health

1598033352 18:09:12 docker-cluster green 1 1 0 0 0 0 0 0 - 100.0% 1598033352 18:09:12 码头工人集群绿色 1 1 0 0 0 0 0 0 - 100.0%

docker-compose ps docker-compose ps

Name                   Command               State                Ports              
------------------------------------------------------------------------------------------
elasticsearch    /usr/local/bin/docker-entr ...   Up      0.0.0.0:9200->9200/tcp, 9300/tcp
elasticsearch2   /usr/local/bin/docker-entr ...   Up      9200/tcp, 9300/tcp

Ok, I found out the issue.好的,我发现了这个问题。 It seems both the containers are somehow not aware of each other and trying to create the clusters on their own.似乎两个容器都不知道彼此并试图自己创建集群。 I introduced delay with depends, it works fine now.我引入了依赖的延迟,它现在工作正常。 Thanks谢谢

It is up.它起来了。 But you need to map the port to some local unused port.但是您需要将端口 map 到一些本地未使用的端口。 Like you have mapped for first one 9200:9200 .就像您为第一个9200:9200映射的一样。 Add the same for other one too like 8200:9200 .为其他人添加相同的内容,例如8200:9200 Then try hitting second one from local at 8200 port.然后尝试在 8200 端口从本地点击第二个。 It should work.它应该工作。

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

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