ZooKeeper3.4.6支持某些特定的四字命令字母與其的交互桃移。它們大多是查詢命令,用來獲取 ZooKeeper 服務(wù)的當(dāng)前狀態(tài)及相關(guān)信息蹂析。用戶在客戶端可以通過 telnet 或 nc 向 ZooKeeper 提交相應(yīng)的命令舔示。
使用方式:
在shell終端輸入:echo xxxx | nc localhost 2181
1、conf:輸出相關(guān)服務(wù)配置的詳細(xì)信息电抚。比如端口惕稻、zk數(shù)據(jù)及日志配置路徑、最大連接數(shù)蝙叛,session超時時間俺祠、serverId等
[hadoop2@demain1 ~]$ echo conf | nc localhost 2181
clientPort=2181
dataDir=/usr/local/zookeeper/data/version-2
dataLogDir=/usr/local/zookeeper/data/version-2
tickTime=2000
maxClientCnxns=60
minSessionTimeout=4000
maxSessionTimeout=40000
serverId=1
initLimit=10
syncLimit=5
electionAlg=3
electionPort=13888
quorumPort=12888
peerType=0
2、cons:列出所有連接到這臺服務(wù)器的客戶端連接/會話的詳細(xì)信息。包括“接受/發(fā)送”的包數(shù)量蜘渣、session id 淌铐、操作延遲、最后的操作執(zhí)行等信息
[hadoop2@demain1 ~]$ echo cons | nc localhost 2181
/10.1.2.207:50745[1](queued=0,recved=777960,sent=777960,sid=0x15bc6dd624d0002,lop=PING,est=1493690139000,to=5000,lcxid=0x4,lzxid=0xffffffffffffffff,lresp=1494987119388,llat=0,minlat=0,avglat=0,maxlat=142)
/127.0.0.1:57495[0](queued=0,recved=1,sent=0)
/10.1.2.217:45858[1](queued=0,recved=777714,sent=777714,sid=0x15bc6dd624d0003,lop=PING,est=1493690170605,to=5000,lcxid=0x2,lzxid=0xffffffffffffffff,lresp=1494987120268,llat=0,minlat=0,avglat=0,maxlat=190)
3蔫缸、crst:重置當(dāng)前這臺服務(wù)器所有連接/會話的統(tǒng)計信息
[hadoop2@demain1 ~]$ echo crst | nc localhost 2181
Connection stats reset.
4腿准、dump:列出未經(jīng)處理的會話和臨時節(jié)點(只在leader上有效)
[hadoop2@demain1 ~]$ echo dump | nc localhost 2181
SessionTracker dump:
org.apache.zookeeper.server.quorum.LearnerSessionTracker@7c224ac7
ephemeral nodes dump:
Sessions with Ephemerals (2):
0x25bc6dd63300001:
/yarn-leader-election/yarn-ha-cluster/ActiveStandbyElectorLock
0x15bc6dd624d0002:
/hadoop-ha/de/ActiveStandbyElectorLock
5、envi:輸出關(guān)于服務(wù)器的環(huán)境詳細(xì)信息(不同于conf命令)拾碌,比如host.name吐葱、java.version、java.home校翔、user.dir=/data/zookeeper-3.4.6/bin之類信息
[hadoop2@demain1 ~]$ echo envi | nc localhost 2181
Environment:
zookeeper.version=3.4.5-cdh5.5.0--1, built on 11/09/2015 20:27 GMT
host.name=demain1
java.version=1.7.0_25
java.vendor=Oracle Corporation
java.home=/usr/local/jdk1.7.0_25/jre
java.class.path=/usr/local/zookeeper/bin/../build/classes:/usr/local/zookeeper/bin/../build/lib/*.jar:/usr/local/zookeeper/bin/../share/zookeeper/zookeeper-3.4.5-cdh5.5.0.jar:/usr/local/zookeeper/bin/../share/zookeeper/slf4j-log4j12-1.7.5.jar:/usr/local/zookeeper/bin/../share/zookeeper/slf4j-api-1.7.5.jar:/usr/local/zookeeper/bin/../share/zookeeper/netty-3.2.2.Final.jar:/usr/local/zookeeper/bin/../share/zookeeper/log4j-1.2.16.jar:/usr/local/zookeeper/bin/../share/zookeeper/jline-2.11.jar:/usr/local/zookeeper/bin/../src/java/lib/*.jar:/usr/local/zookeeper/bin/../conf:
java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.io.tmpdir=/tmp
java.compiler=<NA>
os.name=Linux
os.arch=amd64
os.version=2.6.32-431.el6.x86_64
user.name=hadoop2
user.home=/home/hadoop2
user.dir=/
6弟跑、ruok:測試服務(wù)是否處于正確運行狀態(tài)。如果正常返回"imok"展融,否則返回空
[hadoop2@demain1 ~]$ echo ruok | nc localhost 2181
imok
7窖认、srst:重置服務(wù)器的統(tǒng)計信息
[hadoop2@demain1 ~]$ echo srst | nc localhost 2181
Server stats reset.
8、srvr:輸出服務(wù)器的詳細(xì)信息告希。zk版本扑浸、接收/發(fā)送包數(shù)量、連接數(shù)燕偶、模式(leader/follower)喝噪、節(jié)點總數(shù)
[hadoop2@demain1 ~]$ echo srvr | nc localhost 2181
Zookeeper version: 3.4.5-cdh5.5.0--1, built on 11/09/2015 20:27 GMT
Latency min/avg/max: 0/0/0
Received: 10
Sent: 10
Connections: 3
Outstanding: 0
Zxid: 0x1e00000024
Mode: follower
Node count: 203
9、stat:輸出服務(wù)器的詳細(xì)信息:接收/發(fā)送包數(shù)量指么、連接數(shù)酝惧、模式(leader/follower)、節(jié)點總數(shù)伯诬、延遲晚唇。 所有客戶端的列表
[hadoop2@demain1 ~]$ echo stat | nc localhost 2181
Zookeeper version: 3.4.5-cdh5.5.0--1, built on 11/09/2015 20:27 GMT
Clients:
/127.0.0.1:57536[0](queued=0,recved=1,sent=0)
/10.1.2.207:50745[1](queued=0,recved=64,sent=64)
/10.1.2.217:45858[1](queued=0,recved=63,sent=63)
Latency min/avg/max: 0/0/0
Received: 22
Sent: 22
Connections: 3
Outstanding: 0
Zxid: 0x1e00000024
Mode: follower
Node count: 203
10、wchs:列出服務(wù)器watches的簡潔信息:連接總數(shù)盗似、watching節(jié)點總數(shù)和watches總數(shù)
[hadoop2@demain1 ~]$ echo wchs | nc localhost 2181
2 connections watching 1 paths
Total watches:2
11哩陕、wchc:通過session分組,列出watch的所有節(jié)點赫舒,它的輸出是一個與 watch 相關(guān)的會話的節(jié)點列表悍及。如果watches數(shù)量很大的話,將會產(chǎn)生很大的開銷接癌,會影響性能心赶,小心使用
[hadoop2@demain1 ~]$ echo wchc | nc localhost 2181
0x15bc6dd624d0002
/hadoop-ha/de/ActiveStandbyElectorLock
0x15bc6dd624d0003
/hadoop-ha/de/ActiveStandbyElectorLock
12、wchp:通過路徑分組缺猛,列出所有的 watch 的session id信息缨叫。它輸出一個與 session 相關(guān)的路徑椭符。如果watches數(shù)量很大的話,將會產(chǎn)生很大的開銷弯汰,會影響性能艰山,小心使用
[hadoop2@demain1 ~]$ echo wchp | nc localhost 2181
/hadoop-ha/de/ActiveStandbyElectorLock
0x15bc6dd624d0003
0x15bc6dd624d0002
13湖雹、mntr:列出集群的健康狀態(tài)咏闪。包括“接受/發(fā)送”的包數(shù)量、操作延遲摔吏、當(dāng)前服務(wù)模式(leader/follower)鸽嫂、節(jié)點總數(shù)、watch總數(shù)征讲、臨時節(jié)點總數(shù)
[hadoop2@demain1 ~]$ echo mntr | nc localhost 2181
zk_version 3.4.5-cdh5.5.0--1, built on 11/09/2015 20:27 GMT
zk_avg_latency 0
zk_max_latency 1
zk_min_latency 0
zk_packets_received 68
zk_packets_sent 68
zk_num_alive_connections 3
zk_outstanding_requests 0
zk_server_state follower
zk_znode_count 203
zk_watch_count 2
zk_ephemerals_count 2
zk_approximate_data_size 15571
zk_open_file_descriptor_count 29
zk_max_file_descriptor_count 1024000