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

前端之家收集整理的这篇文章主要介绍了linux – 需要发出什么命令来检查ZooKeeper服务器是领导者还是追随者?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
已创建由三个ZooKeeper服务器组成的ZooKeeper仲裁.

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

  1. maxClientCnxns=50
  2. # The number of milliseconds of each tick
  3. tickTime=2000
  4. # The number of ticks that the initial
  5. # synchronization phase can take
  6. initLimit=10
  7. # The number of ticks that can pass between
  8. # sending a request and getting an acknowledgement
  9. syncLimit=5
  10. # the directory where the snapshot is stored.
  11. dataDir=/var/lib/zookeeper
  12. # the port at which the clients will connect
  13. clientPort=2181
  14.  
  15. server.1=<ip-address-1>:2888:3888
  16. server.2=<ip-address-2>:2888:3888
  17. server.3=<ip-address-3>:2888:3888

分析

很明显,三个ZooKeeper服务器中的一个将成为领导者和其他粉丝.如果Leader ZooKeeper服务器已关闭,则Leader选举将重新开始.目的是检查Leader服务器是否已关闭,另一个ZooKeeper服务器是否会成为Leader.

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

解决方法

可以使用netcat包中包含的nc命令检查ZooKeeper服务器是否是领导者或关注者:
  1. echo stat | nc localhost 2181 | grep Mode
  2. echo srvr | nc localhost 2181 | grep Mode #(From 3.3.0 onwards)

如果ZooKeeper服务器是领导者,那么命令将返回:模式:领导者和否则:模式:关注者

猜你在找的Linux相关文章