简体   繁体   English

具有弹性集群的 docker swarm

[英]docker swarm with elastic cluster

I am beginner with elastic and docker swarm.我是弹性和 docker swarm 的初学者。 I have spent two weeks to learn and try to prepare a docker swarm with elastic.我花了两周时间学习并尝试准备一个弹性的 docker swarm。 I would like to prepare an elastic cluster with docker swarm.我想用 docker swarm 准备一个弹性集群。 Where we can use scale up and down easily.我们可以轻松使用放大和缩小的地方。 I thought we need swarm to do this and elastic cluster to keep data in sync between swarm nodes.我认为我们需要 swarm 来做到这一点,并且需要弹性集群来保持 swarm 节点之间的数据同步。 I also thought for the full automatism I would like to use Zen configured with container host name.我还考虑了完全自动化,我想使用配置了容器主机名的 Zen。 Because of swarm round rubin "elasticsearch" hostname should return all of the ip.由于 swarm round rubin "elasticsearch" 主机名应该返回所有的 ip。

  • docker version is: 17.06.2-ce docker 版本为:17.06.2-ce
  • elastic docker image version is: elasticsearch:latest弹性泊坞窗图像版本为:elasticsearch:latest
  • docker-compose version >= 3 docker-compose 版本 >= 3

First I tried to follow this instruction: sematext.com/blog/2016/12/12/docker-elasticsearch-swarm首先,我尝试按照此说明进行操作:sematext.com/blog/2016/12/12/docker-elasticsearch-swarm

Here nginx-proxy is not working as a service (part of docker-compose file), but It is working as container.这里 nginx-proxy 不是作为服务工作(docker-compose 文件的一部分),而是作为容器工作。 (docker run). (码头运行)。 I have no idea what could be the difference.我不知道有什么区别。 But the idea itself has been prepared earlier version of docker and it is not working for me.但是这个想法本身已经准备好了 docker 的早期版本,它对我不起作用。

The main idea behind this instruction is, discovery.zen.ping.unicast.hosts has the container name.该指令背后的主要思想是,discovery.zen.ping.unicast.hosts 具有容器名称。 Docker swarm itself load balancing and then elastic can find the another nodes. Docker swarm 本身负载均衡,然后弹性可以找到另一个节点。

Because nginx-proxy doesn't work as a service I tried to follow this instruction: derpturkey.com/elasticsearch-cluster-with-docker-engine-swarm-mode/因为 nginx-proxy 不能作为服务工作,所以我尝试按照以下说明进行操作:derpturkey.com/elasticsearch-cluster-with-docker-engine-swarm-mode/

I have defined nginx service to connect elastic and I configured all of the parameters here.我已经定义了 nginx 服务来连接弹性,我在这里配置了所有参数。

version: '3'  
  services:  
    elasticsearch:
    image: 'elasticsearch:5'
    command: [ elasticsearch, -E, network.host=0.0.0.0, -E, discovery.zen.ping.unicast.hosts=elasticsearch, -E, discovery.zen.minimum_master_nodes=1 ]
  nginx:
    image: 'nginx:1'
    ports:
      - '9200:9200'
    command: |
      /bin/bash -c "echo '
      server {
        listen 9200;
        add_header X-Frame-Options "SAMEORIGIN";
        location / {
          proxy_pass http://elasticsearch:9200;
          proxy_http_version 1.1;
          proxy_set_header Connection keep-alive;
          proxy_set_header Upgrade $$http_upgrade;
          proxy_set_header Host $$host;
          proxy_set_header X-Real-IP $$remote_addr;
          proxy_cache_bypass $$http_upgrade;
      }
   }' | tee /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

It didn't work.它没有用。 Later I made some changes:后来我做了一些改动:

  • I have created an own image and set nginx parameters directly in nginx config file.我已经创建了一个自己的图像并直接在 nginx 配置文件中设置了 nginx 参数。
  • Here is my new config of docker-compose file.这是我的 docker-compose 文件的新配置。

I tested it.我测试了它。 Nginx is working. Nginx 正在工作。 curl -XGET http://elastic:changeme@127.0.0.1:9200/_cluster/state?pretty return with the data. curl -XGET http://elastic:changeme@127.0.0.1:9200/_cluster/state?pretty返回数据。

version: '3'  
  services:  
    elasticsearch:
      image: elasticsearch:latest
      deploy:
        replicas: 2
      ports: ["9300:9300"]
      command: [elasticsearch, -E, network.bind_host=0.0.0.0, -E, discovery.zen.ping.unicast.hosts=elasticsearch, -E, discovery.zen.minimum_master_nodes=1]
    nginx:
      image: 'dodi1983/nginx:0.1'
      ports:
        - 9200:9200
      depends_on: 
        - elasticsearch

Consequences:后果:

  • nginx is working. nginx 正在工作。
  • From nginx container elasticsearch resolve dns is working and load balancing between to node.从 nginx 容器 elasticsearch 解析 dns 正在工作并在节点之间进行负载平衡。

Unfortunately When I ask elastic about available nodes.不幸的是,当我询问有关可用节点的弹性时。 Elastic always returns with the current node info (load balancing). Elastic 始终返回当前节点信息(负载平衡)。 I can see the different ids.我可以看到不同的ID。 Only one node is available, but I thought ZEN discovery should have found both.只有一个节点可用,但我认为 ZEN discovery 应该同时找到这两个节点。 I logged in nginx container and try to get cluster info.我登录了 nginx 容器并尝试获取集群信息。 you can see here, they are different nodes and they are not in cluster.你可以在这里看到,它们是不同的节点,它们不在集群中。 curl -XGET http://elastic:changeme@elasticsearch:9200/_cluster/state?pretty curl -XGET http://elastic:changeme@elasticsearch:9200/_cluster/state?pretty

Does anyone has any idea or solution?有没有人有任何想法或解决方案? Thank you.谢谢。

for me helped official docs对我来说帮助官方文档

https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.4.1
    container_name: es01
    environment:
      - node.name=es01
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=es01,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.4.1
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=es01
      - cluster.initial_master_nodes=es01,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata02:/usr/share/elasticsearch/data
    networks:
      - esnet

volumes:
  esdata01:
    driver: local
  esdata02:
    driver: local

networks:
  esnet:

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

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