# -server:client端连接的IP和端口号
$ ./bin/zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2016-09-30 01:51:22,268 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
2016-09-30 01:51:22,271 [myid:] - INFO [main:Environment@100] - Client environment:host.name=hadoop1
2016-09-30 01:51:22,271 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_79
2016-09-30 01:51:22,272 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2016-09-30 01:51:22,272 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/data/jdk1.7.0_79/jre
2016-09-30 01:51:22,272 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/data/zookeeper-3.4.8/bin/../build/classes:/data/zookeeper-3.4.8/bin/../build/lib/*.jar:/data/zookeeper-3.4.8/bin/../lib/slf4j-log4j12-1.6.1.jar:/data/zookeeper-3.4.8/bin/../lib/slf4j-api-1.6.1.jar:/data/zookeeper-3.4.8/bin/../lib/netty-3.7.0.Final.jar:/data/zookeeper-3.4.8/bin/../lib/log4j-1.2.16.jar:/data/zookeeper-3.4.8/bin/../lib/jline-0.9.94.jar:/data/zookeeper-3.4.8/bin/../zookeeper-3.4.8.jar:/data/zookeeper-3.4.8/bin/../src/java/lib/*.jar:/data/zookeeper-3.4.8/bin/../conf:
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.16.0-77-generic
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:user.name=yunyu
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/yunyu
2016-09-30 01:51:22,273 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/data/zookeeper-3.4.8
2016-09-30 01:51:22,275 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@71adff7c
Welcome to ZooKeeper!
2016-09-30 01:51:22,299 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2016-09-30 01:51:22,303 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
JLine support is enabled
2016-09-30 01:51:22,337 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x1577a41e9b90000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]
# zkShell中输入help会提示出所有的命令参数
[zk: 127.0.0.1:2181(CONNECTED) 0] help
ZooKeeper host:port cmd args
get path [watch]
ls path [watch]
set path data [version]
delquota [-n|-b] path
quit
printwatches on|off
create path data acl
stat path [watch]
listquota path
history
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
deleteall path
setquota -n|-b val path
# 查看znode节点
[zk: 127.0.0.1:2181(CONNECTED) 0] ls
[zookeeper]
# 创建新的znode节点,关联到"my_data"
[zk: 127.0.0.1:2181(CONNECTED) 3] create /zk_test my_data
Created /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 4] ls /
[zookeeper, zk_test]
# 验证/zk_test节点已经关联到"my_data"
[zk: 127.0.0.1:2181(CONNECTED) 5] get /zk_test
my_data
cZxid = 0x6
ctime = Mon Aug 29 20:42:40 PDT 2016
mZxid = 0x6
mtime = Mon Aug 29 20:42:40 PDT 2016
pZxid = 0x6
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
# 修改/zk_test节点的数据关联
[zk: 127.0.0.1:2181(CONNECTED) 6] set /zk_test junk
cZxid = 0x6
ctime = Mon Aug 29 20:42:40 PDT 2016
mZxid = 0x7
mtime = Mon Aug 29 20:47:08 PDT 2016
pZxid = 0x6
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 7] get /zk_test
junk
cZxid = 0x6
ctime = Mon Aug 29 20:42:40 PDT 2016
mZxid = 0x7
mtime = Mon Aug 29 20:47:08 PDT 2016
pZxid = 0x6
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
# 删除/zk_test节点
[zk: 127.0.0.1:2181(CONNECTED) 8] delete /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 9] ls /
[zookeeper]