目录
Zookeeper实战记录-目录:https://blog.csdn.net/weixin_39565597/article/details/104401912
1、help:显示所有操作命令
# 帮助信息
[zk: localhost:2181(CONNECTED) 1] help
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
2、ls path [watch]:使用 ls 命令来查看当前znode中所包含的内容
# 查询'/'目录下所有节点
[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]
3、ls2 path [watch]:查看当前节点数据并能看到更新次数等数据
# 查询'/'目录下所有节点,且显示其stat结构信息
[zk: localhost:2181(CONNECTED) 1] ls2 /
[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
4、get path [watch]:获得节点的值
# 获取zookeeper节点的信息(数据(第一行)+stat结构体)
[zk: localhost:2181(CONNECTED) 1] 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、create [-s][-e] path data:普通创建[-s含有序列]、[-e临时(重启或者超时消失)]
# 创建hello节点信息,数据为www.baidu.com
[zk: localhost:2181(CONNECTED) 1] create /hello 'www.baidu.com'
# 查看节点,发现已经创建按成功hello节点
[zk: localhost:2181(CONNECTED) 2] ls /
[hello, zookeeper]
# 获取hello节点信息
[zk: localhost:2181(CONNECTED) 2] get /hello
www.baidu.com
cZxid = 0x2
ctime = Mon Feb 17 22:08:48 CST 2020
mZxid = 0x2
mtime = Mon Feb 17 22:08:48 CST 2020
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 13
numChildren = 0
6、set:设置节点的具体值
# 设置节点数据
[zk: localhost:2181(CONNECTED) 1] set /hello 'com.baidu.www'
cZxid = 0x4
ctime = Tue Feb 18 20:55:36 CST 2020
mZxid = 0x9
mtime = Tue Feb 18 21:07:11 CST 2020
pZxid = 0x4
cversion = 0
dataVersion = 4
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
# 查看节点数据已经修改了
[zk: localhost:2181(CONNECTED) 1] get /hello
com.baidu.www
cZxid = 0x4
ctime = Tue Feb 18 20:55:36 CST 2020
mZxid = 0x9
mtime = Tue Feb 18 21:07:11 CST 2020
pZxid = 0x4
cversion = 0
dataVersion = 4
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
7、stat:查看节点状态
# 查看节点的结构体
[zk: localhost:2181(CONNECTED) 1] stat /hello
cZxid = 0x4
ctime = Tue Feb 18 20:55:36 CST 2020
mZxid = 0x9
mtime = Tue Feb 18 21:07:11 CST 2020
pZxid = 0x4
cversion = 0
dataVersion = 4
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0
8、delete:删除节点
# 删除节点信息,如果有子节点则不能删除,必须先删除其下子节点。
[zk: localhost:2181(CONNECTED) 1] delete /hello
# 删除成功
[zk: localhost:2181(CONNECTED) 2] ls /
[zookeeper]
9、rmr:递归删除节点
# 删除节点信息,如果该节点下还有其它节点,则会递归删除。
[zk: localhost:2181(CONNECTED) 1] rmr /hello
WATCHER::
WatchedEvent state:SyncConnected type:NodeDeleted path:/hello
# 删除成功
[zk: localhost:2181(CONNECTED) 2] ls /
[zookeeper]