1、连接到节点:./zkCli.sh -r -timeout 2000 -server master:21810,注意默认端口是2181,我自己改了
[root@slave2 bin]# ./zkCli.sh -r -timeout 2000 -server master:21810
Connecting to master:21810
2018-06-18 17:22:24,373 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.12-e5259e437540f349646870ea94dc2658c4e44b3b, built on 03/27/2018 03:55 GMT
2018-06-18 17:22:24,376 [myid:] - INFO [main:Environment@100] - Client environment:host.name=slave2.lan
2018-06-18 17:22:24,376 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_171
2018-06-18 17:22:24,379 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-06-18 17:22:24,379 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.8.0_171-amd64/jre
2018-06-18 17:22:24,379 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/hadoop/zookeeper-3.4.12/bin/../build/classes:/usr/hadoop/zookeeper-3.4.12/bin/../build/lib/*.jar:/usr/hadoop/zookeeper-3.4.12/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/hadoop/zookeeper-3.4.12/bin/../lib/slf4j-api-1.7.25.jar:/usr/hadoop/zookeeper-3.4.12/bin/../lib/netty-3.10.6.Final.jar:/usr/hadoop/zookeeper-3.4.12/bin/../lib/log4j-1.2.17.jar:/usr/hadoop/zookeeper-3.4.12/bin/../lib/jline-0.9.94.jar:/usr/hadoop/zookeeper-3.4.12/bin/../lib/audience-annotations-0.5.0.jar:/usr/hadoop/zookeeper-3.4.12/bin/../zookeeper-3.4.12.jar:/usr/hadoop/zookeeper-3.4.12/bin/../src/java/lib/*.jar:/usr/hadoop/zookeeper-3.4.12/bin/../conf:.:/usr/java/jdk1.8.0_171-amd64/lib:/usr/java/jdk1.8.0_171-amd64/jre/lib:/lib
2018-06-18 17:22:24,380 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-06-18 17:22:24,380 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-06-18 17:22:24,380 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2018-06-18 17:22:24,380 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2018-06-18 17:22:24,380 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2018-06-18 17:22:24,381 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-229.el7.x86_64
2018-06-18 17:22:24,381 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2018-06-18 17:22:24,381 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2018-06-18 17:22:24,381 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/usr/hadoop/zookeeper-3.4.12/bin
2018-06-18 17:22:24,382 [myid:] - INFO [main:ZooKeeper@441] - Initiating client connection, connectString=master:21810 sessionTimeout=2000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@67424e82
Welcome to ZooKeeper!
2018-06-18 17:22:24,417 [myid:] - INFO [main-SendThread(master.lan:21810):ClientCnxn$SendThread@1028] - Opening socket connection to server master.lan/172.2.1.224:21810. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2018-06-18 17:22:24,490 [myid:] - INFO [main-SendThread(master.lan:21810):ClientCnxn$SendThread@878] - Socket connection established to master.lan/172.2.1.224:21810, initiating session
[zk: master:21810(CONNECTING) 0] 2018-06-18 17:22:24,551 [myid:] - INFO [main-SendThread(master.lan:21810):ClientCnxn$SendThread@1302] - Session establishment complete on server master.lan/172.2.1.224:21810, sessionid = 0x100004616de0000, negotiated timeout = 4000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
2、查询帮助命令:ls h
[zk: master:21810(CONNECTED) 0] ls h
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
3、ls path:列出path下的文件
[zk: master:21810(CONNECTED) 1] ls /
[zookeeper]
4、获取节点信息:
[zk: master:21810(CONNECTED) 2] get /zookeeper
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
5、退出
[zk: master:21810(CONNECTED) 3] quit
Quitting...
2018-06-18 17:26:48,886 [myid:] - INFO [main:ZooKeeper@687] - Session: 0x100004616de0000 closed
2018-06-18 17:26:48,888 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@521] - EventThread shut down for session: 0x100004616de0000