1.  连接到zookeeper服务

[java2000_wl@localhost zookeeper-3]$ bin/zkCli.sh -server 127.0.0.1:2181



2.  使用ls命令查看当前zookeeper中包含的内容

[zk: 127.0.0.1:2181(CONNECTED) 1] ls /

[zookeeper]


3.  创建新的znode,使用create命令

[zk:127.0.0.1:2181(CONNECTED) 2] create /zk testData

Created /zk


4.  获取节点中的值  get命令

[zk:127.0.0.1:2181(CONNECTED) 4] get /zk

testData

cZxid = 0x700000008

ctime = Sat Mar 0923:01:24 CST 2013

mZxid = 0x700000008

mtime = Sat Mar 0923:01:24 CST 2013

pZxid = 0x700000008

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 8

numChildren = 0


5.  使用set命令来对znode关联的字符串进行设置

[zk: 127.0.0.1:2181(CONNECTED) 5] set /zk mydata

cZxid = 0x700000008

ctime = Sat Mar 09 23:01:24 CST 2013

mZxid = 0x700000009

mtime = Sat Mar 09 23:06:03 CST 2013

pZxid = 0x700000008

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 0


6.  删除znode节点

[zk: 127.0.0.1:2181(CONNECTED) 7]delete /zk



Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐