docker搭建zookeeper集群

筅森魡賤 提交于 2021-02-02 05:16:08

1、在官网拉取镜像

docker pull zookeeper

2、根据镜像启动zookeeper容器

docker run -itd --name zookeeper1 -h zookeeper1 -e ZOO_MY_ID=1 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:28881:38881 server.3=zookeeper3:28882:38882" -p 2181:2181 -p 2888:2888 -p  3888:3888 --add-host=zookeeper1:172.17.0.5 --add-host=zookeeper2:172.17.0.6 --add-host=zookeeper3:172.17.0.7 zookeeper

docker run -itd --name zookeeper2 -h zookeeper2 -e ZOO_MY_ID=2 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:28881:38881 server.3=zookeeper3:28882:38882" -p 2182:2181 -p 28881:2888 -p 38881:3888 --add-host=zookeeper1:172.17.0.5 --add-host=zookeeper2:172.17.0.6 --add-host=zookeeper3:172.17.0.7 zookeeper

docker run -itd --name zookeeper3 -h zookeeper3 -e ZOO_MY_ID=3 -e ZOO_SERVERS="server.1=zookeeper1:2888:3888 server.2=zookeeper2:28881:38881 server.3=zookeeper3:28882:38882" -p 2183:2181 -p 28882:2888 -p 38882:3888 --add-host=zookeeper1:172.17.0.5 --add-host=zookeeper2:172.17.0.6 --add-host=zookeeper3:172.17.0.7 zookeeper

3、启动zookeeper集群命令行

docker run -it --rm --link zookeeper1:zookeeper1 --link zookeeper2:zookeeper2 --link zookeeper3:zookeeper3 zookeeper zkCli.sh -server zookeeper1:2181,zookeeper2:2181,zookeeper3:2181

然后就可以使用了。

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!