Think before you speak, read before you think.

判断 zookeeper 健康状态

echo stat | nc localhost 2181 | grep Mode
You will get the response if the node is acting as a leader:

Mode: leader
If it is a follower, you will see:

Mode: follower
Alternatively, you can use the zkServer.sh located in /opt/zookeeper/bin:

./zkServer.sh status

[root@misc010-prod ~]# echo mntr |nc  10.16.1.60 2181
zk_version	3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
zk_avg_latency	0
zk_max_latency	2
zk_min_latency	0
zk_packets_received	36275
zk_packets_sent	36274
zk_num_alive_connections	2
zk_outstanding_requests	0
zk_server_state	leader
zk_znode_count	488
zk_watch_count	3
zk_ephemerals_count	4
zk_approximate_data_size	40646
zk_open_file_descriptor_count	33
zk_max_file_descriptor_count	65536
zk_followers	2
zk_synced_followers	2
zk_pending_syncs	0

[root@misc010-prod ~]# echo mntr |nc  10.16.1.21 2181
zk_version	3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
zk_avg_latency	0
zk_max_latency	10
zk_min_latency	0
zk_packets_received	685
zk_packets_sent	686
zk_num_alive_connections	1
zk_outstanding_requests	0
zk_server_state	follower
zk_znode_count	488
zk_watch_count	0
zk_ephemerals_count	4
zk_approximate_data_size	40646
zk_open_file_descriptor_count	30
zk_max_file_descriptor_count	1048576
[root@misc010-prod ~]# echo mntr |nc  10.16.1.22 2181
zk_version	3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
zk_avg_latency	0
zk_max_latency	13
zk_min_latency	0
zk_packets_received	73614
zk_packets_sent	73622
zk_num_alive_connections	3
zk_outstanding_requests	0
zk_server_state	follower
zk_znode_count	488
zk_watch_count	37
zk_ephemerals_count	4
zk_approximate_data_size	40646
zk_open_file_descriptor_count	32
zk_max_file_descriptor_count	1048576

在 leader 输出中
zk_followers 2
zk_synced_followers 2
zk_pending_syncs 0
表示 zk 正常


Comments

Leave a Reply

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