一、连接服务器端
1 [root@sxl132 zookeepeer]# ./bin/zkCli.sh -server 192.168.116.144:2181
2 Connecting to 192.168.116.144:2181
3 2018-01-11 06:55:04,157 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
4 2018-01-11 06:55:04,169 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost
5 2018-01-11 06:55:04,169 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_151
6 2018-01-11 06:55:04,174 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
7 。。。。。。。。。。。。。。。。。。。。。。。。。。
8 6.144/192.168.116.144:2181, sessionid = 0x4000004a4240000, negotiated timeout = 30000
9
10 WATCHER::
11
12 WatchedEvent state:SyncConnected type:None path:null
二、使用zkCli.sh的相关指令
1、查看相关命令
1 [zk: 192.168.116.144:2181CONNECTED) 0] h
2 ZooKeeper -server host:port cmd args
3 stat path [watch]
4 set path data [version]
5 ls path [watch]
6 delquota [-n|-b] path
7 ls2 path [watch]
8 setAcl path acl
9 setquota -n|-b val path
10 history
11 redo cmdno
12 printwatches on|off
13 delete path [version]
14 sync path
15 listquota path
16 rmr path
17 get path [watch]
18 create [-s] [-e] path data acl
19 addauth scheme auth
20 quit
21 getAcl path
22 close
23 connect host:port
2、查看目录结构
1 [zk: 192.168.116.144:2181CONNECTED) 1] ls /
2 [zookeeper]
3 [zk: 192.168.116.144:2181CONNECTED) 2] ls2 /
4 [zookeeper]
5 cZxid = 0x0
6 ctime = Wed Dec 31 16:00:00 PST 1969
7 mZxid = 0x0
8 mtime = Wed Dec 31 16:00:00 PST 1969
9 pZxid = 0x0
10 cversion = -1
11 dataVersion = 0
12 aclVersion = 0
13 ephemeralOwner = 0x0
14 dataLength = 0
15 numChildren = 1
3、创建节点和节点数据
1 [zk: 192.168.116.144:2181CONNECTED) 8] create /root root_data
2 Created /root
3 [zk: 192.168.116.144:2181CONNECTED) 9] ls /
4 [zookeeper, root]
4、查看节点及节点的数据信息
1 [zk: 192.168.116.144:2181CONNECTED) 11] get /root
2 root_data
3 cZxid = 0xa00000002
4 ctime = Thu Jan 11 15:09:50 PST 2018
5 mZxid = 0xa00000002
6 mtime = Thu Jan 11 15:09:50 PST 2018
7 pZxid = 0xa00000002
8 cversion = 0
9 dataVersion = 0
10 aclVersion = 0
11 ephemeralOwner = 0x0
12 dataLength = 9
13 numChildren = 0
5、修改节点数据
1 [zk: 192.168.116.144:2181CONNECTED) 12] set /root ROOT_DATA
2 cZxid = 0xa00000002
3 ctime = Thu Jan 11 15:09:50 PST 2018
4 mZxid = 0xa00000003
5 mtime = Thu Jan 11 15:13:14 PST 2018
6 pZxid = 0xa00000002
7 cversion = 0
8 dataVersion = 1
9 aclVersion = 0
10 ephemeralOwner = 0x0
11 dataLength = 9
12 numChildren = 0
13 [zk: 192.168.116.144:2181CONNECTED) 13] get /root
14 ROOT_DATA
15 cZxid = 0xa00000002
16 ctime = Thu Jan 11 15:09:50 PST 2018
17 mZxid = 0xa00000003
18 mtime = Thu Jan 11 15:13:14 PST 2018
19 pZxid = 0xa00000002
20 cversion = 0
21 dataVersion = 1
22 aclVersion = 0
23 ephemeralOwner = 0x0
24 dataLength = 9
25 numChildren = 0
6、删除节点
1 [zk: 192.168.116.144:2181CONNECTED) 15] delete /root
2 [zk: 192.168.116.144:2181CONNECTED) 16] ls /
3 [zookeeper]
其他的命令,童鞋们可以自己去尝试。
参考文档:
徐培成的大数据zookeepeer视频。