ZooKeeper做独立服务器运行(下)
四、ZooKeeper Java客户端连接后的命令概述
键入help,可以看到有如下命令:
-
connecthost:port
-
getpath [watch]
-
lspath [watch]
-
setpath data [version]
-
rmrpath
-
delquota[-n|-b] path
-
quit
-
printwatcheson|off
-
create[-s] [-e] path data acl
-
statpath [watch]
-
close
-
ls2path [watch]
-
history
-
listquotapath
-
setAclpath acl
-
getAclpath
-
syncpath
-
redocmdno
-
addauthscheme auth
-
deletepath [version]
-
setquota-n|-b val path
下面,我们来试用这些命令。
首先,看看列表命令,如下:
-
[zk: 127.0.0.1:2181(CONNECTED) 6] ls /
-
[zookeeper]
接下来,我们创建一个新的znode节点,这个znode节点相关的字符串为“my_data”,如下:
-
[zk: 127.0.0.1:2181(CONNECTED) 6] create/zk_test my_data
-
Created /zk_test
再次执行列表命令,如下:
-
[zk: 127.0.0.1:2181(CONNECTED) 6] ls /
-
[zookeeper, zk_test]
可以看到,zk_test目录已经被创建。
下面,我们使用get命令来验证此znode节点相关的数据,如下:
-
[zk: 127.0.0.1:2181(CONNECTED) 7] get/zk_test
-
my_data
-
cZxid = 0x4
-
ctime = Fri May 02 08:28:40 UTC 2014
-
mZxid = 0x4
-
mtime = Fri May 02 08:28:40 UTC 2014
-
pZxid = 0x4
-
cversion = 0
-
dataVersion = 0
-
aclVersion = 0
-
ephemeralOwner = 0x0
-
dataLength = 7
-
numChildren = 0
我们还可以使用set命令修改此znode相关的数据,如下:
-
[zk: 127.0.0.1:2181(CONNECTED) 8] set/zk_test junk
-
cZxid = 0x4
-
ctime = Fri May 02 08:28:40 UTC 2014
-
mZxid = 0x5
-
mtime = Fri May 02 08:34:32 UTC 2014
-
pZxid = 0x4
-
cversion = 0
-
dataVersion = 1
-
aclVersion = 0
-
ephemeralOwner = 0x0
-
dataLength = 4
-
numChildren = 0
最后,我们可以删除此znode节点,如下:
-
[zk: 127.0.0.1:2181(CONNECTED) 10] delete/zk_test
-
[zk: 127.0.0.1:2181(CONNECTED) 11] ls /
-
[zookeeper]
退出ZooKeeper客户端连接,执行命令:
-
[zk: 127.0.0.1:2181(CONNECTED) 12] quit
-
Quitting...
-
2014-05-02 08:49:47,415 [myid:] - INFO [main:ZooKeeper@684] - Session:0x145bbdc9b460001 closed
-
2014-05-02 08:49:47,415 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@512]- EventThread shut down
阅读(5603) | 评论(0) | 转发(3) |