承接Docker部署单机Zookeeper: Docker部署单机Zookeeper
配置Zookeeper安装目录
-
配置单机Zookeeper的时候我们建立了/docker/developer/zookeeper 目录,类比一下,我们部署zookeeper集群需要至少zookeeper容器,所以建立三个目录:
/docker/developer/zookeeper01 /docker/developer/zookeeper02 /docker/developer/zookeeper03 -
三个目录的配置参照部署单机Zookeeper,都包含conf ,data ,logs 目录
安装和部署zookeeper集群
-
开启三个容器
docker run -d --privileged=true \
-v /docker/develop/zookeeper01/conf:/conf \
-v /docker/develop/zookeeper01/data:/data \
-v /docker/develop/zookeeper01/logs:/datalog \
zookeeper:3.4.9
docker run -d --privileged=true \
-v /docker/develop/zookeeper02/conf:/conf \
-v /docker/develop/zookeeper02/data:/data \
-v /docker/develop/zookeeper02/logs:/datalog \
zookeeper:3.4.9
docker run -d --privileged=true \
-v /docker/develop/zookeeper03/conf:/conf \
-v /docker/develop/zookeeper03/data:/data \
-v /docker/develop/zookeeper03/logs:/datalog \
zookeeper:3.4.9
-
查询三个zookeeper容器的IPAddress docker inspect zookeeper01 | grep IPAddress
docker inspect zookeeper02 | grep IPAddress
docker inspect zookeeper03 | grep IPAddress
-
更改zookeeper01,02,03的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
4lw.commands.whitelist=*
clientPort=2181
server.1=172.17.0.2:2888:3888
server.2=172.17.0.3:2888:3888
server.3=172.17.0.4:2888:3888
-
分别更改/docker/developer/zookeeper01/data/myid ,/docker/developer/zookeeper02/data/myid ,/docker/developer/zookeeper03/data/myid 为1 ,2 ,3
进行测试
-
全部重新开始 docker restart zookeeper01的id
docker restart zookeeper02的id
docker restart zookeeper03的id
-
进入三个容器中 docker exec -it zookeeper01的id /bin/bash
docker exec -it zookeeper02的id /bin/bash
docker exec -it zookeeper03的id /bin/bash
-
分别运行zookeeper Server
bin/zkServer.sh start
-
分别查看一下状态 bin/zkServer.sh status
|