zookeeper创建节点
1.创建持久节点[zk: localhost:2181(CONNECTED) 0] create /user tomCreated /user# 获取节点值[zk: localhost:2181(CONNECTED) 2] get /usertom# 获取节点下的子节点[zk: localhost:2181(CONNECTED) 3] ls /user[]#创建子节点[zk: localhost:
·
1.创建持久节点
[zk: localhost:2181(CONNECTED) 0] create /user tom
Created /user
# 获取节点值
[zk: localhost:2181(CONNECTED) 2] get /user
tom
# 获取节点下的子节点
[zk: localhost:2181(CONNECTED) 3] ls /user
[]
#创建子节点
[zk: localhost:2181(CONNECTED) 4] create /user/aaa 我是aaa
Created /user/aaa
[zk: localhost:2181(CONNECTED) 5] create /user/bbb 我是bbb
Created /user/bbb
[zk: localhost:2181(CONNECTED) 6] get /user/aaa
我是aaa
[zk: localhost:2181(CONNECTED) 7] ls /user/aaa
[]
该节点重新启动一个zkCli.sh就会发现这些节点还在.这是持久节点.
2.创建临时节点
[zk: localhost:2181(CONNECTED) 8] create -e /user/meinv 我是美女
然后重新启动一个zkCli.sh就会发现节点已经消失.
3.创建持久性顺序节点
[zk: localhost:2181(CONNECTED) 5] create /user/nv
Created /user/nv
[zk: localhost:2181(CONNECTED) 6] get /user/nv
null
[zk: localhost:2181(CONNECTED) 7] create -s /user/nv/luoli
Created /user/nv/luoli0000000000
[zk: localhost:2181(CONNECTED) 8] create -s /user/nv/shaofu
Created /user/nv/shaofu0000000001
[zk: localhost:2181(CONNECTED) 9] ls /user/nv
[luoli0000000000, shaofu0000000001]
可以看到创建的节点,直接后缀携带了自增的0000000000>>>>
该节点是持久性的
4.创建临时顺序节点
zk: localhost:2181(CONNECTED) 10] create -s -e /user/nv/luoli1
Created /user/nv/luoli10000000002
[zk: localhost:2181(CONNECTED) 11] create -s -e /user/nv/shaofu1
Created /user/nv/shaofu20000000003
[zk: localhost:2181(CONNECTED) 12] ls /user/nv
[luoli0000000000, luoli10000000002, shaofu0000000001, shaofu10000000003]
[zk: localhost:2181(CONNECTED) 13]
该节点会在会话关闭后消失
更多推荐
已为社区贡献6条内容
所有评论(0)