集群角色
zookeeper 集群中的机器分为一下三种角色
leader:为客户端提供读写服务(事务性操作),并维护集群状态,它是由集群选举所产生的;
follower:为客户端提供读(非事务性操作),转发给leader写(事务性操作),参与选举操作;
observer:角色与follower类型,但无选举操作;
zookeeper端口
1:2181:对client端提供服务
2:2888:集群内机器通讯使用(leadre监听此端口)
1:3888:选举leader使用
docker-compose.yml文件
yml
version: '3'
services:
zoo1:
image: zookeeper:latest
restart: always
container_name: zoo1
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper:latest
restart: always
container_name: zoo2
ports:
- "2182:2181"
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper:latest
restart: always
container_name: zoo3
ports:
- "2183:2181"
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoonavigator:
image: elkozmon/zoonavigator:latest
ports:
- "9000:9000"
environment:
ZKUI_ZK_SERVER: "zoo1:2181,zoo2:2181,zoo3:2181"
通过一下命令查看那个zk是leader活着follower
bash
[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