Docker Compose 安装 ZooKeeper 集群

1. 新建docker-compose.yml

version: '3.1'

services:
  zoo1:
    container_name: zoo1
    image: zookeeper
    restart: always
    hostname: zoo1
    ports:
      - 2181:2181
    volumes:
      - "/opt/zookeeper/zoo1/data:/data"
      - "/opt/zookeeper/zoo1/datalog:/datalog"
    environment:
      TZ: Asia/Shanghai
      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:
    container_name: zoo2
    image: zookeeper
    restart: always
    hostname: zoo2
    ports:
      - 2182:2181
    volumes:
      - "/opt/zookeeper/zoo2/data:/data"
      - "/opt/zookeeper/zoo2/datalog:/datalog"
    environment:
      TZ: Asia/Shanghai
      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:
    container_name: zoo3  
    image: zookeeper
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    volumes:
      - "/opt/zookeeper/zoo3/data:/data"
      - "/opt/zookeeper/zoo3/datalog:/datalog"
    environment:
      TZ: Asia/Shanghai
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888

2. 创建并启动容器

docker-compose up -d

未经允许不得转载:君子如兰 » Docker Compose 安装 ZooKeeper 集群

赞 (0)