- 参考资料
- 下载镜像
docker pull zookeeper
- 单机安装
docker run --name zk -h zk -p 2181:2181 --network my-bridge --ip 192.168.17.1 --restart always -d zookeeper
docker exec -it zk /bin/bash
# 三种连接方式
## wget https://downloads.apache.org/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
## tar zxf apache-zookeeper-3.6.2-bin.tar.gz
## cd apache-zookeeper-3.6.2-bin
## 宿主机 IP:2181
[root@mytest apache-zookeeper-3.6.2-bin]# bin/zkCli.sh -server localhost:2181
## 容器 IP:2181
[root@mytest apache-zookeeper-3.6.2-bin]# bin/zkCli.sh -server 192.168.17.1:2181
## 其它容器通过 hostname::2181
docker run --rm --network my-bridge -it zookeeper /bin/bash
root@e179d72a2d7a:/apache-zookeeper-3.6.2-bin# bin/zkCli.sh -server zk:2181
- 集群安装
- ~/docker/zookeeper/docker-compose.yml
version: '3.1'
networks:
default:
name: my-bridge
services:
zoo1:
image: zookeeper
restart: unless-stopped
hostname: zoo1
container_name: zoo1
ports:
- 2182:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper
restart: unless-stopped
hostname: zoo2
container_name: zoo2
ports:
- 2183:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper
restart: unless-stopped
hostname: zoo3
container_name: zoo3
ports:
- 2184:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
# 创建容器
docker-compose -f ~/docker/zookeeper/docker-compose.yml up -d
# 查看日志
docker-compose -f ~/docker/zookeeper/docker-compose.yml logs zoo1
docker-compose -f ~/docker/zookeeper/docker-compose.yml logs zoo2
docker-compose -f ~/docker/zookeeper/docker-compose.yml logs zoo3
# 查看节点状态
docker exec -it zoo1 /bin/sh
docker exec -it zoo2 /bin/sh
docker exec -it zoo3 /bin/sh
zkServer.sh status
# 客户端连接
./zkCli.sh -server 127.0.0.1:2181
网友评论