集群角色
zookeeper 集群中的机器分为一下三种角色
leader:为客户端提供读写服务(事务性操作),并维护集群状态,它是由集群选举所产生的;
follower:为客户端提供读(非事务性操作),转发给leader写(事务性操作),参与选举操作;
observer:角色与follower类型,但无选举操作;
zookeeper端口
1:2181:对client端提供服务
2:2888:集群内机器通讯使用(leadre监听此端口)
1:3888:选举leader使用
docker-compose.yml文件
version: '3'
services:zoo1:image: zookeeper:latestrestart: alwayscontainer_name: zoo1ports:- "2181:2181"environment:ZOO_MY_ID: 1ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181zoo2:image: zookeeper:latestrestart: alwayscontainer_name: zoo2 ports:- "2182:2181" environment:ZOO_MY_ID: 2ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181zoo3:image: zookeeper:latestrestart: alwayscontainer_name: zoo3ports:- "2183:2181"environment:ZOO_MY_ID: 3ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181zoonavigator:image: elkozmon/zoonavigator:latestports:- "9000:9000"environment:ZKUI_ZK_SERVER: "zoo1:2181,zoo2:2181,zoo3:2181"
如果是部署在不同的服务器可以在每个容器设置network_mode: bridge或者network_mode: host
通过一下命令查看那个zk是leader活着follower
[root@localhost zookeeperDocker]# docker exec -it zoo1 ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@localhost zookeeperDocker]# docker exec -it zoo2 ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@localhost zookeeperDocker]# docker exec -it zoo3 ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader