docker 使用compose安装zookeeper集群
Posted bronk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker 使用compose安装zookeeper集群相关的知识,希望对你有一定的参考价值。
此基础镜像使用的为zookeeper的官方镜像
docker pull zookeeper
新建文件 docker-compose.yml
version: \'2\' services: zookeeper1: image: zookeeper container_name: zk1.cloud ports: - "2181:2181" environment: ZOO_MY_ID: 1 ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zk2.cloud:2888:3888 server.3=zk3.cloud:2888:3888 zookeeper2: image: zookeeper container_name: zk2.cloud ports: - "2182:2181" environment: ZOO_MY_ID: 2 ZOO_SERVERS: server.1=zk1.cloud:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zk3.cloud:2888:3888 zookeeper3: image: zookeeper container_name: zk3.cloud ports: - "2183:2181" environment: ZOO_MY_ID: 3 ZOO_SERVERS: server.1=zk1.cloud:2888:3888 server.2=zk2.cloud:2888:3888 server.3=0.0.0.0:2888:3888
启动集群
docker-compose up
后台启动
docker-compose up -d
查看启动状态
docker-compose ps
查看主从关系:
echo stat | nc www.wenbronk.com 2181
可看另外两个端口 2182, 2183
还可以在启动时直接指定
docker run -d \\ -p 2181:2181 \\ --name zk1 \\ --link zk2:zknode2 \\ --link zk3:zknode3 \\ --net foo \\ -e SERVER_ID=1 \\ -e ADDITIONAL_ZOOKEEPER_1=server.1=0.0.0.0:2888:3888 \\ -e ADDITIONAL_ZOOKEEPER_2=server.2=zknode2:2888:3888 \\ -e ADDITIONAL_ZOOKEEPER_3=server.3=zknode3:2888:3888 \\ zookeeper
docker run -d \\ -p 2182:2181 \\ --name zk2 \\ --link zk1:zknode1 \\ --link zk3:zknode3 \\ --net foo \\ -e SERVER_ID=1 \\ -e ADDITIONAL_ZOOKEEPER_1=server.1=zknode1:2888:3888 \\ -e ADDITIONAL_ZOOKEEPER_2=server.2=0.0.0.0:2888:3888 \\ -e ADDITIONAL_ZOOKEEPER_3=server.3=zknode3:2888:3888 \\ zookeeper
docker run -d \\ -p 2183:2181 \\ --name zk3 \\ --link zk2:zknode2 \\ --link zk1:zknode1 \\ --net foo \\ -e SERVER_ID=1 \\ -e ADDITIONAL_ZOOKEEPER_1=server.1=zknode1:2888:3888 \\ -e ADDITIONAL_ZOOKEEPER_2=server.2=zknode2:2888:3888 \\ -e ADDITIONAL_ZOOKEEPER_3=server.3=0.0.0.0:2888:3888 \\ zookeeper
以上是关于docker 使用compose安装zookeeper集群的主要内容,如果未能解决你的问题,请参考以下文章