ZooKeeper做独立服务器运行(下)

ZooKeeper做独立服务器运行(下)
四、ZooKeeper Java客户端连接后的命令概述
键入help,可以看到有如下命令:

点击(此处)折叠或打开

  1. connecthost:port
  2.          getpath [watch]
  3.          lspath [watch]
  4.          setpath data [version]
  5.          rmrpath
  6.          delquota[-n|-b] path
  7.          quit
  8.          printwatcheson|off
  9.          create[-s] [-e] path data acl
  10.          statpath [watch]
  11.          close
  12.          ls2path [watch]
  13.          history
  14.          listquotapath
  15.          setAclpath acl
  16.          getAclpath
  17.          syncpath
  18.          redocmdno
  19.          addauthscheme auth
  20.          deletepath [version]
  21.          setquota-n|-b val path
下面,我们来试用这些命令。
首先,看看列表命令,如下:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 6] ls /
  2. [zookeeper]
接下来,我们创建一个新的znode节点,这个znode节点相关的字符串为“my_data”,如下:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 6] create/zk_test my_data
  2. Created /zk_test
再次执行列表命令,如下:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 6] ls /
  2. [zookeeper, zk_test]
可以看到,zk_test目录已经被创建。
下面,我们使用get命令来验证此znode节点相关的数据,如下:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 7] get/zk_test
  2. my_data
  3. cZxid = 0x4
  4. ctime = Fri May 02 08:28:40 UTC 2014
  5. mZxid = 0x4
  6. mtime = Fri May 02 08:28:40 UTC 2014
  7. pZxid = 0x4
  8. cversion = 0
  9. dataVersion = 0
  10. aclVersion = 0
  11. ephemeralOwner = 0x0
  12. dataLength = 7
  13. numChildren = 0
我们还可以使用set命令修改此znode相关的数据,如下:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 8] set/zk_test junk
  2. cZxid = 0x4
  3. ctime = Fri May 02 08:28:40 UTC 2014
  4. mZxid = 0x5
  5. mtime = Fri May 02 08:34:32 UTC 2014
  6. pZxid = 0x4
  7. cversion = 0
  8. dataVersion = 1
  9. aclVersion = 0
  10. ephemeralOwner = 0x0
  11. dataLength = 4
  12. numChildren = 0
最后,我们可以删除此znode节点,如下:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 10] delete/zk_test
  2. [zk: 127.0.0.1:2181(CONNECTED) 11] ls /
  3. [zookeeper]
退出ZooKeeper客户端连接,执行命令:

点击(此处)折叠或打开

  1. [zk: 127.0.0.1:2181(CONNECTED) 12] quit
  2. Quitting...
  3. 2014-05-02 08:49:47,415 [myid:] - INFO [main:ZooKeeper@684] - Session:0x145bbdc9b460001 closed
  4. 2014-05-02 08:49:47,415 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@512]- EventThread shut down


上一篇:*大学林轩田机器学习基石课程学习笔记10 -- Logistic Regression


下一篇:阿里云智能--基础产品技术月刊 2019年6月