标签:
再启动Zookeeper服务之后,输入以下命令,连接到Zookeeper服务:
zkCli.sh -server localhost:2181
连接成功之后,系统会输出Zookeeper的相关环境及配置信息,并在屏幕输出“welcome to Zookeeper!”等信息。输入help之后,屏幕会输出可用的Zookeeper命令,如下图所示
(1) 使用ls命令查看当前Zookeeper中所包含的内容:ls /
[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 2]
(2) 创建一个新的Znode节点"zk",以及和它相关字符,执行命令:create /zk myData
[zk: localhost:2181(CONNECTED) 2] create /zk myData Created /zk
(3) 再次使用ls命令来查看现在Zookeeper的中所包含的内容:ls /
[zk: localhost:2181(CONNECTED) 3] ls /
[zk, zookeeper]
此时看到,zk节点已经被创建。
(4) 使用get命令来确认第二步中所创建的Znode是否包含我们创建的字符串,执行命令:get /zk
[zk: localhost:2181(CONNECTED) 4] get /zk myData cZxid = 0x500000006 ctime = Fri Oct 17 03:54:20 PDT 2014 mZxid = 0x500000006 mtime = Fri Oct 17 03:54:20 PDT 2014 pZxid = 0x500000006 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 6 numChildren = 0
(5) 接下来通过set命令来对zk所关联的字符串进行设置,执行命令:set /zk jiang1234
[zk: localhost:2181(CONNECTED) 5] set /zk jiang2014 cZxid = 0x500000006 ctime = Fri Oct 17 03:54:20 PDT 2014 mZxid = 0x500000007 mtime = Fri Oct 17 03:55:50 PDT 2014 pZxid = 0x500000006 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 9 numChildren = 0
(6) 再次使用get命令来查看,上次修改的内容,执行命令:get /zk
[zk: localhost:2181(CONNECTED) 6] get /zk jiang2014 cZxid = 0x500000006 ctime = Fri Oct 17 03:54:20 PDT 2014 mZxid = 0x500000007 mtime = Fri Oct 17 03:55:50 PDT 2014 pZxid = 0x500000006 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 9 numChildren = 0
(7) 下面我们将刚才创建的Znode删除,执行命令:delete /zk
[zk: localhost:2181(CONNECTED) 7] delete /zk
(8) 最后再次使用ls命令查看Zookeeper中的内容,执行命令:ls /
[zk: localhost:2181(CONNECTED) 8] ls /
[zookeeper]
经过验证,zk节点已经删除。
标签:
原文地址:http://www.cnblogs.com/chenyansong/p/5529640.html