zk · 2022-03-02 0

docker 搭建 zookeeper 3.6 集群

1.拉取镜像

docker pull zookeeper:3.6.0

2.创建网络

创建网络,使得容器都在此网络内,容器间可以通过容器名互联

docker network create -d bridge my-net

3.创建容器

ZOO_MY_ID 值会写入 /data/myid
ZOO_SERVERS 值会写入 /conf/zoo.cfg

docker run -itd -e ZOO_SERVERS="server.1=zk-2191:2888:3888;2181 server.2=zk-2192:2888:3888;2181 server.3=zk-2193:2888:3888;2181" --net my-net -p 2191:2181 -e ZOO_MY_ID=1 --name zk-2191 zookeeper:3.6.0

docker run -itd -e ZOO_SERVERS="server.1=zk-2191:2888:3888;2181 server.2=zk-2192:2888:3888;2181 server.3=zk-2193:2888:3888;2181" --net my-net -p 2192:2181 -e ZOO_MY_ID=2 --name zk-2192 zookeeper:3.6.0

docker run -itd -e ZOO_SERVERS="server.1=zk-2191:2888:3888;2181 server.2=zk-2192:2888:3888;2181 server.3=zk-2193:2888:3888;2181" --net my-net -p 2193:2181 -e ZOO_MY_ID=3 --name zk-2193 zookeeper:3.6.0

查看容器 /conf/zoo.cfg 文件内容如下:

dataDir=/data
dataLogDir=/datalog
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=true
server.1=zk-2191:2888:3888;2181
server.2=zk-2192:2888:3888;2181
server.3=zk-2193:2888:3888;2181