欢迎访问IT教程网

Zookeeper相关命令

Linux admin 500℃ 0评论

1启动客户端

$ bin/zkCli.sh

2.显示所有操作命令

[zk: localhost:2181(CONNECTED) 1] help

3查看当前znode中所包含的内容

[zk: localhost:2181(CONNECTED) 0] ls /

[zookeeper]

4查看当前节点详细数据

[zk: localhost:2181(CONNECTED) 1] ls2 /

[zookeeper]

cZxid = 0x0

ctime = Thu Jan 01 08:00:00 CST 1970

mZxid = 0x0

mtime = Thu Jan 01 08:00:00 CST 1970

pZxid = 0x0

cversion = -1

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 0

numChildren = 1

5分别创建2普通节点

[zk: localhost:2181(CONNECTED) 3] create /xxxx "ooooo"

Created /xxxx

[zk: localhost:2181(CONNECTED) 4] create /xxxx/yyyy "zzzz"

Created /xxxx/yyyy

6.获得节点的值

[zk: localhost:2181(CONNECTED) 5] get /xxxx

ooooo

cZxid = 0x100000003

ctime = Wed Aug 29 00:03:23 CST 2018

mZxid = 0x100000003

mtime = Wed Aug 29 00:03:23 CST 2018

pZxid = 0x100000004

cversion = 1

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 7

numChildren = 1

[zk: localhost:2181(CONNECTED) 6]

[zk: localhost:2181(CONNECTED) 6] get /xxxx/yyyy

zzzz

cZxid = 0x100000004

ctime = Wed Aug 29 00:04:35 CST 2018

mZxid = 0x100000004

mtime = Wed Aug 29 00:04:35 CST 2018

pZxid = 0x100000004

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 0

7创建短暂节点

[zk: localhost:2181(CONNECTED) 7] create -e /xxxx/bbb "ccc"

Created /xxxx/bbb

1)在当前客户端是能查看到的

[zk: localhost:2181(CONNECTED) 3] ls /xxxx

[yyyy, bbb]

2)退出当前客户端然后再重启客户端

[zk: localhost:2181(CONNECTED) 12] quit

$ bin/zkCli.sh

3)再次查看根目录下短暂节点已经删除

[zk: localhost:2181(CONNECTED) 0] ls /xxxx

[yyyy]

8创建带序号的节点

1)先创建一个普通的根节点/sanguo/weiguo

[zk: localhost:2181(CONNECTED) 1] create /sanguo/weiguo "caocao"

Created /sanguo/weiguo

2创建带序号的节点

[zk: localhost:2181(CONNECTED) 2] create -s /sanguo/weiguo/xiaoqiao "jinlian"

Created /sanguo/weiguo/xiaoqiao0000000000

[zk: localhost:2181(CONNECTED) 3] create -s /sanguo/weiguo/daqiao "jinlian"

Created /sanguo/weiguo/daqiao0000000001

[zk: localhost:2181(CONNECTED) 4] create -s /sanguo/weiguo/diaocan "jinlian"

Created /sanguo/weiguo/diaocan0000000002

如果原来没有序号节点,序号0开始依次递增。如果原节点下2个节点,则再排序时从2开始,以此类推。

9修改节点数据值

[zk: localhost:2181(CONNECTED) 6] set /sanguo/weiguo "simayi"

10.节点的值变化监听

1主机3上注册监听/sanguo节点数据变化

[zk: localhost:2181(CONNECTED) 26] [zk: localhost:2181(CONNECTED) 8] get /sanguo watch

2)在主机2上修改/sanguo节点的数据

[zk: localhost:2181(CONNECTED) 1] set /sanguo "xisi"

3)观察主机3收到数据变化的监听

WATCHER::

WatchedEvent state:SyncConnected type:NodeDataChanged path:/sanguo

11节点的子节点变化监听(路径变化)

1)在主机3上注册监听/sanguo节点的子节点变化

[zk: localhost:2181(CONNECTED) 1] ls /sanguo watch

[aa0000000001, server101]

2主机2  /sanguo节点上创建子节点

[zk: localhost:2181(CONNECTED) 2] create /sanguo/jin "simayi"

Created /sanguo/jin

3观察主机3收到子节点变化的监听

WATCHER::

WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/sanguo

12删除节点

[zk: localhost:2181(CONNECTED) 4] delete /sanguo/jin

13.递归删除节点

[zk: localhost:2181(CONNECTED) 15] rmr /sanguo/shuguo

14.查看节点状态

[zk: localhost:2181(CONNECTED) 17] stat /sanguo

cZxid = 0x100000003

ctime = Wed Aug 29 00:03:23 CST 2018

mZxid = 0x100000011

mtime = Wed Aug 29 00:21:23 CST 2018

pZxid = 0x100000014

cversion = 9

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 4

numChildren = 1

 

1czxid-创建节点的事务zxid

每次修改ZooKeeper状态都会收到一个zxid形式的时间戳,也就是ZooKeeper事务ID

事务IDZooKeeper中所有修改总的次序。每个修改都有唯一的zxid,如果zxid1小于zxid2,那么zxid1zxid2之前发生。

2ctime - znode被创建的毫秒数(1970年开始)

3mzxid - znode最后更新的事务zxid

4mtime - znode最后修改的毫秒数(1970年开始)

5pZxid-znode最后更新的子节点zxid

6cversion - znode子节点变化号,znode子节点修改次数

7dataversion - znode数据变化号

8aclVersion - znode访问控制列表的变化号

9ephemeralOwner- 如果是临时节点,这个是znode拥有者的session id。如果不是临时节点则是0

10dataLength- znode的数据长度

11numChildren - znode子节点数量

本文固定链接:IT教程网 » Zookeeper相关命令
本站内容除特别标注外均为原创,欢迎转载,但请保留出处!

喜欢 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址