Docker-compose搭建zookeeper集群
in Zookeeper with 0 comment

Docker-compose搭建zookeeper集群

in Zookeeper with 0 comment

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