A ZooKeeper Quorum consisting of three ZooKeeper servers has been created.
The zoo.cfg
located on all three ZooKeeper servers looks as follows:
maxClientCnxns=50
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
dataDir=/var/lib/zookeeper
# the port at which the clients will connect
clientPort=2181
server.1=<ip-address-1>:2888:3888
server.2=<ip-address-2>:2888:3888
server.3=<ip-address-3>:2888:3888
Analysis
It is clear that one of the three ZooKeeper servers will become the Leader
and the others Followers
. If the Leader
ZooKeeper server has been shutdown, the Leader
election will start again. The aim is to check if another ZooKeeper server will become the Leader
if the Leader
server has been shut down.
It is possible to check whether a ZooKeeper server is a leader or follower using the
nc
command that is included in thenetcat
package:If the ZooKeeper server is a leader then the command will return:
Mode: leader
and otherwise:Mode: follower
Alternatively the following could be used:
It will print the mode in the output:
echo "srvr" | nc localhost 2181 | grep "Mode"
using
bin/zkServer.sh status
:If you set
ZOO_4LW_COMMANDS_WHITELIST: "*"
, you can useecho "stat" | nc localhost 2181
see The Four Letter Words
using
http://localhost:8080/commands/srvr
or
see The AdminServer
using
http://localhost:8080/commands/leader