资料来源:ZooKeeper系列之二:Zookeeper常用命令
[root@datanode1 ~]# zkCli.sh -server 127.0.0.1:2181
[zk: 127.0.0.1:2181(CONNECTED) 2] ls / [storm, hbase, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 3] ls2 / [storm, hbase, zookeeper] cZxid = 0x0 ctime = Thu Jan 01 07:00:00 CST 1970 mZxid = 0x0 mtime = Thu Jan 01 07:00:00 CST 1970 pZxid = 0x1100000002 cversion = 1 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 0 numChildren = 3 [zk: 127.0.0.1:2181(CONNECTED) 4]
[zk: 127.0.0.1:2181(CONNECTED) 4] create /zk "test4~" Created /zk [zk: 127.0.0.1:2181(CONNECTED) 5] ls / [zk, storm, hbase, zookeeper] [zk: 127.0.0.1:2181(CONNECTED) 6] create /zk "test01" Node already exists: /zk [zk: 127.0.0.1:2181(CONNECTED) 7] ls / [zk, storm, hbase, zookeeper] [zk: 127.0.0.1:2181(CONNECTED) 8]
[zk: 127.0.0.1:2181(CONNECTED) 9] get /zk "test4~" cZxid = 0x1800001c42 ctime = Mon Aug 03 14:59:30 CST 2015 mZxid = 0x1800001c42 mtime = Mon Aug 03 14:59:30 CST 2015 pZxid = 0x1800001c42 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 8 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 10]
[zk: 127.0.0.1:2181(CONNECTED) 10] set /zk "zkbak" cZxid = 0x1800001c42 ctime = Mon Aug 03 14:59:30 CST 2015 mZxid = 0x1800001d07 mtime = Mon Aug 03 15:04:52 CST 2015 pZxid = 0x1800001c42 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 11]
[zk: 127.0.0.1:2181(CONNECTED) 11] get /zk "zkbak" cZxid = 0x1800001c42 ctime = Mon Aug 03 14:59:30 CST 2015 mZxid = 0x1800001d07 mtime = Mon Aug 03 15:04:52 CST 2015 pZxid = 0x1800001c42 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 12]
[zk: 127.0.0.1:2181(CONNECTED) 12] delete /zk [zk: 127.0.0.1:2181(CONNECTED) 13] ls / [storm, hbase, zookeeper] [zk: 127.0.0.1:2181(CONNECTED) 14]
[zk: 127.0.0.1:2181(CONNECTED) 15] quit
[zk: 127.0.0.1:2181(CONNECTED) 14] help
[root@datanode1 ~]# echo stat | nc 127.0.0.1 2181 Zookeeper version: 3.4.6-1569965, built on 02/20/2014 09:09 GMT Clients: /127.0.0.1:51410[0](queued=0,recved=1,sent=0) /192.168.57.137:53366[1](queued=0,recved=3740,sent=3740) Latency min/avg/max: 0/2/1135 Received: 9184 Sent: 9183 Connections: 2 Outstanding: 0 Zxid: 0x1800001e68 Mode: follower Node count: 29 [root@datanode1 ~]#
[root@datanode1 ~]# echo ruok|nc 127.0.0.1 2181 imok[root@datanode1 ~]#
imok[root@datanode1 ~]# echo dump|nc 127.0.0.1 2181 SessionTracker dump: org.apache.zookeeper.server.quorum.LearnerSessionTracker@7c6faeb8 ephemeral nodes dump: Sessions with Ephemerals (3): 0x34ef173456d0006: /storm/supervisors/1f53140e-f9fe-43e3-841d-4ef92fd862f4 0x14ef17333560003: /storm/supervisors/2ee21b72-3291-41f8-857c-ed8a3a8a70c7 0x34ef173456d0005: /storm/supervisors/56fa3c25-82c2-46ff-919c-7fbc16d6345d [root@datanode1 ~]#
[root@datanode1 ~]# echo kill | nc 127.0.0.1 1281 [root@datanode1 ~]#
[root@datanode1 ~]# echo conf | nc 127.0.0.1 2181 clientPort=2181 dataDir=/home/hadoop/modules/zookeeper-data/data/version-2 dataLogDir=/home/hadoop/modules/zookeeper-data/logs/version-2 tickTime=2000 maxClientCnxns=60 minSessionTimeout=4000 maxSessionTimeout=40000 serverId=1 initLimit=10 syncLimit=5 electionAlg=3 electionPort=3888 quorumPort=2888 peerType=0 [root@datanode1 ~]#
[root@datanode1 ~]# echo cons | nc 127.0.0.1 2181 /127.0.0.1:51415[0](queued=0,recved=1,sent=0) /192.168.57.137:53366[1](queued=0,recved=4300,sent=4300,sid=0x14ef17333560003,lop=SETD,est=1438580726687,to=20000,lcxid=0x10c9,lzxid=0x1800002047,lresp=1438586879981,llat=2,minlat=0,avglat=4,maxlat=1101) [root@datanode1 ~]#
[root@datanode1 ~]# echo envi | nc 127.0.0.1 2181 Environment: zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT host.name=datanode1 java.version=1.7.0_67 java.vendor=Oracle Corporation java.home=/usr/java/jdk1.7.0_67/jre java.class.path=/home/hadoop/modules/zookeeper/bin/../build/classes:/home/hadoop/modules/zookeeper/bin/../build/lib/*.jar:/home/hadoop/modules/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/hadoop/modules/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/home/hadoop/modules/zookeeper/bin/../lib/netty-3.7.0.Final.jar:/home/hadoop/modules/zookeeper/bin/../lib/log4j-1.2.16.jar:/home/hadoop/modules/zookeeper/bin/../lib/jline-0.9.94.jar:/home/hadoop/modules/zookeeper/bin/../zookeeper-3.4.6.jar:/home/hadoop/modules/zookeeper/bin/../src/java/lib/*.jar:/home/hadoop/modules/zookeeper/bin/../conf:.:/usr/java/jdk1.7.0_67//lib/tools.jar 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=root user.home=/root user.dir=/root [root@datanode1 ~]#
[root@datanode1 ~]# echo reqs | nc 127.0.0.1 2181 [root@datanode1 ~]#
[root@datanode1 ~]# echo wchs | nc 127.0.0.1 2181 0 connections watching 0 paths Total watches:0 [root@datanode1 ~]#
[root@datanode1 ~]# echo wchc | nc 127.0.0.1 2181 [root@datanode1 ~]#
它输出一个与session相关的路径。
[root@datanode1 ~]# echo wchp | nc 127.0.0.1 2181 [root@datanode1 ~]#