What command could be issued to check whether a ZooKeeper server is a Leader or a Follower?

Solution 1:

It is possible to check whether a ZooKeeper server is a leader or follower using the nc command that is included in the netcat package:

echo stat | nc localhost 2181 | grep Mode
echo srvr | nc localhost 2181 | grep Mode #(From 3.3.0 onwards)

If the ZooKeeper server is a leader then the command will return: Mode: leader and otherwise: Mode: follower

Solution 2:

Alternatively the following could be used:

bin/zkServer.sh status

It will print the mode in the output:

ZooKeeper JMX enabled by default
Using config: /home/kafka/zookeeper/bin/../conf/zoo.cfg
Mode: follower