如何在不同服务器上使用docker compose创建Elasticsearch集群?

时间:2020-03-17 07:26:09

标签: elasticsearch docker-compose cluster-computing

我有2台服务器,并在2台服务器中创建elasticsearch节点。 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,它们都已连接。

1 个答案:

答案 0 :(得分:0)

<块引用>

您的默认 docker-engine 网络配置是什么?

有时多台服务器具有相同的网络,因此 docker 不会从一台服务器路由到另一台服务器。

要解决此问题,您必须将 daemon.json 文件修改为以下内容:

node1
{
    "bip": "10.40.18.1/28"
}
node2
{
    "bip": "10.40.18.65/28"
}
相关问题