How to find Zookeeper Leader in zookeeper ensemble ?

To identify a Zookeeper leader or follower there are many ways. Mentioned below are the two of those way’s I generally use :

# echo stat | nc localhost 2181
Zookeeper version: 3.4.6-3485--1, built on 09/26/2018 04:30 GMT
Clients:
/192.168.12.20:41200[1](queued=0,recved=61,sent=61)
/192.168.12.156:44680[1](queued=0,recved=71,sent=71)
/192.168.12.14:58749[1](queued=0,recved=209,sent=209)
/192.168.12.156:58745[1](queued=0,recved=53,sent=53)

Latency min/avg/max: 0/1/362
Received: 627
Sent: 626
Connections: 4
Outstanding: 0
Zxid: 0x200000006
Mode: leader
Node count: 280

# echo stat | nc localhost 2181 | grep Mode
Mode: leader

# echo stat | nc localhost 2181 | grep Mode
Mode: follower
Grep for LEAD in zookeeper logs :
# grep LEAD /var/log/zookeeper/zookeeper-zookeeper-server-akshaym.out
2018-09-26 10:14:23,47 - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2181:QuorumPeer@829] - LEADING
2018-09-26 10:14:23,47 - INFO [QuorumPeer[myid=3]/0:0:0:0:0:0:0:0:2181:Leader@358] - LEADING - LEADER ELECTION TOOK - 4024

Leave a Reply

Your email address will not be published. Required fields are marked *