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
Related videos on Youtube
![030](https://i.stack.imgur.com/tQaGa.png?s=256&g=1)
030
Updated on September 18, 2022Comments
-
030 almost 2 years
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 othersFollowers
. If theLeader
ZooKeeper server has been shutdown, theLeader
election will start again. The aim is to check if another ZooKeeper server will become theLeader
if theLeader
server has been shut down. -
zinking over 8 yearsand
standalone
-
Sumit Murari almost 8 years@bsd , is there any way to find the nodes in zookeeper cluster ??
-
Jose Leon over 7 years@sumit That probably needs its own SO question, but one way is to simply read the zoo.cfg file.