需要发出什么命令来检查ZooKeeper服务器是领导者还是跟随者?


23

已创建由三个ZooKeeper服务器组成的ZooKeeper法定人数。

zoo.cfg所有三个ZooKeeper服务器上的位置如下:

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

分析

显然,三个ZooKeeper服务器之一将成为,Leader而其他服务器将成为Followers。如果LeaderZooKeeper服务器已关闭,则Leader选举将再次开始。其目的是检查其他的ZooKeeper服务器将成为Leader如果Leader服务器已经被关闭。


需要发出什么命令来检查ZooKeeper服务器是领导者还是跟随者?

Answers:


50

可以使用软件包中nc包含的命令来检查ZooKeeper服务器是引导服务器还是跟随服务器netcat

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

如果ZooKeeper服务器是引导服务器,则命令将返回:Mode: leader否则:Mode: follower


2
standalone
zinking

@bsd,有什么方法可以在zookeeper集群中找到节点?
murarisumit's

2
@sumit这可能需要它自己的SO问题,但是一种方法是简单地读取zoo.cfg文件。
何塞·莱昂

3

或者,可以使用以下内容:

bin/zkServer.sh status

它将在输出中打印模式:

ZooKeeper JMX enabled by default
Using config: /home/kafka/zookeeper/bin/../conf/zoo.cfg
Mode: follower
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.