【发布时间】:2020-03-17 07:26:09
【问题描述】:
我有 2 台服务器,并在 2 台服务器中创建弹性搜索节点。 docker-compose.yml 文件的内容如下:
es0:
image: elasticsearch:7.6.0
container_name: es0
environment:
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- 9200:9200
- 9300:9300
volumes:
- "/mnt/docker/es0/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
- "/mnt/docker/es0/data:/usr/share/elasticsearch/data"
- "/mnt/docker/es0/plugins:/usr/share/elasticsearch/plugins"
- "/mnt/docker/es0/config/cert:/usr/share/elasticsearch/config/cert"
es1:
image: elasticsearch:7.6.0
container_name: es1
environment:
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- 9200:9200
- 9300:9300
volumes:
- "/mnt/docker/es1/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
- "/mnt/docker/es1/data:/usr/share/elasticsearch/data"
- "/mnt/docker/es1/plugins:/usr/share/elasticsearch/plugins"
- "/mnt/docker/es1/config/cert:/usr/share/elasticsearch/config/cert"
我像这样配置了 elasticsearch.yml:
cluster.name: hs-cluster
node.name: es-00
node.master: true
node.data: true
http.host: 0.0.0.0
http.port: 9200
transport.host: 0.0.0.0
transport.tcp.port: 9300
#network.host: 0.0.0.0
network.bind_host: ["192.168.0.2", "101.xx.xx.136"]
network.publish_host: 192.168.0.2
gateway.recover_after_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["es-00", "es-01"]
discovery.seed_hosts: [ "192.168.0.2:9300", "192.168.0.3:9300" ]
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
cluster.name: hs-cluster
node.name: es-01
node.master: true
node.data: true
http.host: 0.0.0.0
http.port: 9200
transport.host: 0.0.0.0
transport.tcp.port: 9300
#network.host: 0.0.0.0
network.bind_host: ["192.168.0.3", "101.xx.xx.137"]
network.publish_host: 192.168.0.3
gateway.recover_after_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
cluster.initial_master_nodes: ["es-00", "es-01"]
discovery.seed_hosts: [ "192.168.0.2:9300", "192.168.0.3:9300" ]
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
当我运行实例时,它们都已成功启动。但是当我调用_cluster/state?pretty时,他们都给出了错误信息:
{
"error" : {
"root_cause" : [
{
"type" : "master_not_discovered_exception",
"reason" : null
}
],
"type" : "master_not_discovered_exception",
"reason" : null
},
"status" : 503
}
这意味着他们找不到彼此。
我也尝试设置 network.host: 0.0.0.0
但结果是一样的。
谁知道这位大师没有发现异常的原因?如何解决?
顺便说一句,我可以使用 docker compose 在同一台服务器上运行集群。但是在不同的服务器中,它是失败的。我还在每台服务器上运行了 telnet xxx 9300,它们都连接了。
【问题讨论】:
-
在你的 docker compose 文件中,你没有网络部分?
-
如果我不设置任何网络,是否使用默认桥接网络?其实我对它并不熟悉。我尝试将网络设置为桥:网络:-弹性网络:弹性:驱动程序:桥但结果是一样的。
-
我将网络模式设置为主机,然后就可以了。谢谢!接下来我会尝试桥接模式。
-
是的,确实,如果您使用主机网络,容器将共享主机的网络命名空间,并且它们可以互相看到。
-
@LiuTao - 可以分享一下正确的配置吗?
标签: elasticsearch docker-compose cluster-computing