侧边栏壁纸
  • 累计撰写 47 篇文章
  • 累计创建 32 个标签
  • 累计收到 19 条评论
隐藏侧边栏

Docker-compose搭建zookeeper集群

凛冬王昭君
2020-03-02 / 0 评论 / 0 点赞 / 300 阅读 / 0 字
温馨提示:
本文最后更新于 2020-03-02,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1 环境准备

image.png

2 安装zookeeper集群

2.1 创建zookeeper配置文件目录

cd /usr/local/docker/deploy/
mkdir zookeeper
touch docker-compose.yaml

2.2 编写docker-compose.yaml文件

version: '3.7'
services:
  zoo1:
    image: zookeeper
    restart: always
    hostname: zoo1
    container_name: zookeeper_1
    #domainname: 
    ports:
      - 2181:2181
    volumes:
      - /usr/local/docker/volumes/zookeeper/zoo1/data:/data
      - /usr/local/docker/volumes/zookeeper/zoo1/datalog:/datalog
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
 
  zoo2:
    image: zookeeper
    restart: always
    hostname: zoo2
    container_name: zookeeper_2
    ports:
      - 2182:2181
    volumes:
      - /usr/local/docker/volumes/zookeeper/zoo2/data:/data
      - /usr/local/docker/volumes/zookeeper/zoo2/datalog:/datalog
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
 
  zoo3:
    image: zookeeper
    restart: always
    hostname: zoo3
    container_name: zookeeper_3
    ports:
      - 2183:2181
    volumes:
      - /usr/local/docker/volumes/zookeeper/zoo3/data:/data
      - /usr/local/docker/volumes/zookeeper/zoo3/datalog:/datalog
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181

2.3 创建启动zookeeper集群

docker-compose -f docker-compose.yaml up -d

2.4 检查zookeeper集群是否成功

  • 容器启动情况
docker ps -a

image.png

  • 集群状态

image.png

0

评论区