标题:
Zookeeper入门之二-命令行基本操作(1)
[打印本页]
作者:
look_w
时间:
2019-4-12 17:10
标题:
Zookeeper入门之二-命令行基本操作(1)
ZK的基本使用
3888端口,用于leader选举的端口
命令行使用
创建
create [-s | -e ] path data acl
其中 -s 表示顺序节点,
-e 表示 临时节点
不加的话,默认是持久化节点
acl是权限,默认不加权限限制
sh $ZK_HOME/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] create /zk-jsy-book 122jin
Created /zk-jsy-book
通过执行以上命令,可以在根目录下创建一个 zk-jsy-book的节点,其值是 122jin
读取
ls path
类似于linux下的ls命令,可以列举出path下所有的一级子节点
[zk: localhost:2181(CONNECTED) 2] ls /
[zk-jsy-book, zookeeper]
[zk: localhost:2181(CONNECTED) 3] ls /zk-jsy-book
[]
get path
可以获取某个节点的值及其对应属性
[zk: localhost:2181(CONNECTED) 5] create /zk-jsy-book/book1 111 --- 再创建一个子节点
Created /zk-jsy-book/book1
[zk: localhost:2181(CONNECTED) 6] ls /zk-jsy-book --- ls查看
[book1]
[zk: localhost:2181(CONNECTED) 7] get /zk-jsy-book --- get获取节点值及属性信息
122jin
cZxid = 0x2d
ctime = Tue Jul 24 12:47:37 GMT 2018
mZxid = 0x2d
mtime = Tue Jul 24 12:47:37 GMT 2018
pZxid = 0x2e
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 1
[zk: localhost:2181(CONNECTED) 8] get /zk-jsy-book/book1 --- 获取子节点值及属性信息
111
cZxid = 0x2e
ctime = Tue Jul 24 13:21:01 GMT 2018
mZxid = 0x2e
mtime = Tue Jul 24 13:21:01 GMT 2018
pZxid = 0x2e
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 3
numChildren = 0
更新
set path data [version]
[zk: localhost:2181(CONNECTED) 9] set /zk-jsy-book test
cZxid = 0x2d
ctime = Tue Jul 24 12:47:37 GMT 2018
mZxid = 0x2f
mtime = Tue Jul 24 13:39:13 GMT 2018
pZxid = 0x2e
cversion = 1
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 1
[zk: localhost:2181(CONNECTED) 10] get /zk-jsy-book
test
cZxid = 0x2d
ctime = Tue Jul 24 12:47:37 GMT 2018
mZxid = 0x2f
mtime = Tue Jul 24 13:39:13 GMT 2018
pZxid = 0x2e
cversion = 1
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 1
[zk: localhost:2181(CONNECTED) 11]
可以看到,dataVersion变成了1
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0