Reputation: 39810
Assume that I have an ensemble Zookeeper which is up and running to facilitate and serve Apache Kafka (Confluent's distribution).
3 instances (clientPorts: 2181
, 2182
and 2183
) have been configured and started as shown below:
./bin/zookeeper-server-start etc/kafka/zookeeper.properties
./bin/zookeeper-server-start etc/kafka/zookeeper1.properties
./bin/zookeeper-server-start etc/kafka/zookeeper2.properties
At any given time, how can I check which Zookeeper instance is the leader of the ensemble?
Upvotes: 4
Views: 17968
Reputation: 524
These are the following commands and output to check the Leader or follower in 3 Node zookeeper cluster. There maybe error when you try to use srvr you will get error like.
[administrator@centos-aes1 kafka_2.12-2.4.0]$ echo srvr | nc localhost 2181
srvr is not executed because it is not in the whitelist.
Then either you have to whitelist srvr or you can try for the next 4 letter command which are given below:-
The list of known four letter word commands is :
[{1936881266=srvr, 1937006964=stat, 2003003491=wchc, 1685417328=dump, 1668445044=crst, 1936880500=srst, 1701738089=envi, 1668247142=conf, -720899=telnet close, 2003003507=wchs, 2003003504=wchp, 1684632179=dirs, 1668247155=cons, 1835955314=mntr, 1769173615=isro, 1920298859=ruok, 1735683435=gtmk, 1937010027=stmk}]
you can use it for more Information too.
###############################First Node#############################
[administrator@centos-aes1 kafka_2.12-2.4.0]$ echo srvr | nc localhost 2181
Zookeeper version: 3.5.6-c11b7e26bc554b8523dc929761dd28808913f091, built on 10/08/2019 20:18 GMT
Latency min/avg/max: 0/0/0
Received: 34
Sent: 32
Connections: 1
Outstanding: 0
Zxid: 0x5000000b8
**Mode: follower**
Node count: 28
###############################Second Node#############################
[root@centos-aes2 administrator]# echo srvr | nc localhost 2181
Zookeeper version: 3.5.6-c11b7e26bc554b8523dc929761dd28808913f091, built on 10/08/2019 20:18 GMT
Latency min/avg/max: 0/0/6
Received: 10233
Sent: 10232
Connections: 4
Outstanding: 0
Zxid: 0x800000000
**Mode: leader**
Node count: 28
Proposal sizes last/min/max: -1/-1/-1
###############################Third Node#############################
[administrator@centos-aes3 ~]$ echo srvr | nc localhost 2181
Zookeeper version: 3.5.6-c11b7e26bc554b8523dc929761dd28808913f091, built on 10/08/2019 20:18 GMT
Latency min/avg/max: 0/0/0
Received: 32
Sent: 30
Connections: 1
Outstanding: 0
Zxid: 0x5000000b8
**Mode: follower**
Node count: 28
Upvotes: 2
Reputation: 26885
There are a few ways to find the leader of an ensemble. The easiest is probably to simply ask the Zookeeper instances using:
echo stat | nc ZOOKEEPER_IP ZOOKEEPER PORT | grep Mode
that will print whether this instance is a leader
, follower
or standalone
.
This page also shows how to find this out from Zookeeper's logs
Upvotes: 9