Zookeeper deployment:
Zookeeper There are three ways to deploy, stand-alone mode, the cluster mode, pseudo-cluster mode.
- Stand-alone mode : single point of failure
- Cluster-Mode : Zookeeper cluster deployed on multiple machines, suitable for online environments.
- Pseudo cluster mode : simultaneously running a plurality of machine Zookeeper instances, still have single points of failure, of course, wherein the configuration port number to be shifted, for experiments using simulated cluster environment.
Note: The
cluster is three or more odd number, such as 3,5,7, not too much, more than a cluster machine and election data synchronization time-consuming, unstable
Using cluster mode installation Zookeeper.
Because it is docker, so it is not a pseudo-cluster
docker-compose.yml
version: '3.1'
services:
zoo1:
image: zookeeper:3.4.13
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
zoo2:
image: zookeeper:3.4.13
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
zoo3:
image: zookeeper:3.4.13
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
Elections: According to the latest transaction ID (ZXID) to elect, who was the greatest, who as leader. In theory. so, directly test the third service is not a leader?
start up
docker-compose up -d
Interactive into the container
docker exec -it zookeeper_zoo3_1 /bin/bash
./bin/zkServer.sh status
Then a problem, this is a pit. fuck. Because with the latest version, 3.4.13 or 3.4.14 is recommended
to try to resolve this bug, chose silence. Down version number is 3.4.14
guess wrong, the service is not 3 leader, test, two other
service 1 also follow, so the service for the leader 2