在docker swarm中部署多个Zookeeper

umuewwlo  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(378)

我正在尝试使用DockerSwarm部署多个Zookeeper(每个管理员都在自己的容器中)。
最终我想用3个Zookeeper,但现在我只是想让2个示例工作。
我现在的docker-compose.yml:

version: '3'

services:
  zoo1:
    image: zookeeper
    restart: unless-stopped
    hostname: zoo1
    ports:
      - 2181:2181
    environment:
        ZOO_MY_ID: 1
        ZOO_SERVERS: server.1=0.0.0.0:2888:3888;server.2=zoo2:2888:3888
    volumes:
      - ./full-stack/zoo1/data:/data
      - ./full-stack/zoo1/datalog:/datalog
    networks:
      - kafka_network

  zoo2:
    image: zookeeper
    restart: unless-stopped
    hostname: zoo2
    ports:
      - 2182:2181
    environment:
        ZOO_MY_ID: 2
        ZOO_SERVERS: server.1=zoo1:2888:3888;server.2=0.0.0.0:2888:3888
    volumes:
      - ./full-stack/zoo2/data:/data
      - ./full-stack/zoo2/datalog:/datalog
    networks:
      - kafka_network

  visualizer:
    image: dockersamples/visualizer:stable
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    ports:
      - "8080:8080"
    deploy:
      placement:
        constraints: [node.role == manager]

networks:
  kafka_network:
    external:
      name: kafkaNetwork

kafkanetwork是我使用命令创建的覆盖网络

docker network create -d overlay --attachable kafkaNetwork

我发现下面的docker论坛帖子https://forums.docker.com/t/cannot-get-zookeeper-to-work-running-in-docker-using-swarm-mode/27109/3 但我的zookeeper示例无法成功运行。

sxpgvts3

sxpgvts31#

解决了的。

version: '3.2'

services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    ports:
      - 2181:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

  zoo2:
    image: zookeeper
    restart: always
    hostname: zoo2
    ports:
      - 2182:2181
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888

  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888

相关问题