Elasticsearch 是否有能力仅使用一个 ES docker 服务在 Docker-Swarm 中运行其多个副本来形成 ES 集群

Elasticsearch 是否有能力仅使用一个 ES docker 服务在 Docker-Swarm 中运行其多个副本来形成 ES 集群

我只想在 docker-swarm 中运行一个 elasticsearch 服务,并且该服务有多个副本。

Elasticsearch 是否有能力仅使用一个 ES docker 服务在 Docker-Swarm 中运行其多个副本来形成 ES 集群。以下是我的 elasticsearch.yml 配置。

是否可能?如果是,需要在 elasticsearch.yml 文件中进行哪些调整才能获得所需的结果。

http.host: 0.0.0.0
transport.host: 0.0.0.0

network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
node.name: elasticsearch-node1
discovery.zen.ping.unicast.hosts: ["elasticsearch"]
cluster.name: elasticsearch
transport.publish_port: 9300
transport.publish_host: elasticsearch
node.master: true

#node.data: true

答案1

是的,这是可以实现的。只需在 docker-compose.yaml 文件中像下面这样将 endpoint_mode 添加为 dnsrr。要在所有 docker-swarm 节点上部署一个实例/容器,请在 docker-compose.yaml 文件中使用“mode: global”。要在一台机器上部署所有 ES 集群实例/容器,请使用“mode: replicated”并在 docker-compose.yaml 文件中指定要部署的副本,例如“replicas: 3”。

使用“endpoint_mode: dnsrr”时,我们将无法公开服务端口。为此,我们应该使用外部负载平衡器,如 nginx 或 haproxy。如下所示 nginx docker-compose.yaml 文件

version: '3.5'
services:

    elasticsearch:
       image: elasticsearch:5
       deploy:
#          mode: replicated
#          replicas: 3
          mode: global
          endpoint_mode: dnsrr
          restart_policy:
             condition: on-failure
             delay: 5s
             max_attempts: 3
             window: 120s
#       placement:
#           constraints: [node.role == manager]
       environment:
         - ES_JAVA_OPTS=${ELASTICSEARCH_MEM} 
       volumes:
         - esdata:/usr/share/elasticsearch/data
       configs:
         - source: elasticsearch.yml
           target: /usr/share/elasticsearch/config/elasticsearch.yml

#     ports:
#       - 9200:9200
#       - 9300:9300
    nginx-lb:
       image: "nginx:1.15.4"
       deploy:
           restart_policy:
              condition: on-failure
             delay: 5s
             max_attempts: 3
             window: 120s
           placement:
                constraints: [node.role == manager]
      volumes:
          - ./nginx.conf:/etc/nginx/nginx.conf
      ports:
          - 9200:9200
          - 9300:9300

volumes:
  esdata:
configs:
  elasticsearch.yml:
    external: true

# elasticsearch.yaml file
transport.host: 0.0.0.0
http.host: 0.0.0.0
network.host: 0.0.0.0
cluster.name: elasticsearch
discovery.zen.ping.unicast.hosts: elasticsearch  
discovery.zen.minimum_master_nodes: 1 
node.max_local_storage_nodes: 20

# nginx.conf file
events {}
stream {
    upstream stream_backend {
        server elasticsearch:9300;

    }


    server {
        listen        9300;
        proxy_pass    stream_backend;
        proxy_timeout 3s;
        proxy_connect_timeout 1s;
    }


}

http {

  upstream elasticsearch9200 {
      server elasticsearch:9200;


  }

  server {
      listen 9200;
      server_name _;

      location / {
        proxy_pass http://elasticsearch9200;
      }

  }

}

相关内容