Elasticsearch 集群不能在 swarm (stack) 中工作,但可以与 compose 一起使用
Posted
技术标签:
【中文标题】Elasticsearch 集群不能在 swarm (stack) 中工作,但可以与 compose 一起使用【英文标题】:Elasticsearch cluster not working in swarm (stack) , but works with compose 【发布时间】:2021-12-30 21:23:15 【问题描述】:我有一个 elasticsearch & kibana docker compose 文件,可以使用 docker compose up
命令,但不能使用 docker stack deploy
命令。我也尝试过使用带有覆盖驱动程序的网络。当我使用curl localhost:9200/_cluster/health
检查集群运行状况时,出现以下错误:
"error":"root_cause":["type":"master_not_discovered_exception","reason":null],"type":"master_not_discovered_exception","reason":null,"status": 503
version: '3.4'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
hostname: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
hostname: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
hostname: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic
kib01:
image: docker.elastic.co/kibana/kibana:7.15.2
hostname: kib01
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: '["http://es01:9200","http://es02:9200","http://es03:9200"]'
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: overlay
internal: true
【问题讨论】:
【参考方案1】:删除端口就可以了。
不确定端口是如何导致问题的。有知道的朋友请分享一下。
这是更新后的工作组合:
version: '3.4'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
hostname: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- data01:/usr/share/elasticsearch/data
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
hostname: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
hostname: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic
kib01:
image: docker.elastic.co/kibana/kibana:7.15.2
hostname: kib01
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: '["http://es01:9200","http://es02:9200","http://es03:9200"]'
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: overlay
internal: true
【讨论】:
在添加了不必要的端口、容器名称和其他指令的 swarm(和 compose)上编写文件时,似乎有很多货物崇拜。一般来说,这些事情是个坏主意。对于服务到服务的通信端口,不需要发布,因为服务可以在它们的私有覆盖网络上看到彼此。发布不需要接受来自 swarm 外部的流量的端口会导致潜在的冲突,因为整个 swarm 上只有一个服务可以使用该端口。以上是关于Elasticsearch 集群不能在 swarm (stack) 中工作,但可以与 compose 一起使用的主要内容,如果未能解决你的问题,请参考以下文章