大数据 > 正文

2018-07-12期 Zookeeper操作命令【本人亲自反复验证通过分享】

1、连接zk

[root@hadoop-server01 bin]# ./zkCli.sh -server hadoop-server01

[zk: hadoop-server01(CONNECTED) 0] help

ZooKeeper -server host:port cmd args

connect host:port

get path [watch]

ls path [watch]

set path data [version]

rmr path

delquota [-n|-b] path

quit

printwatches on|off

create [-s] [-e] path data acl

stat path [watch]

close

ls2 path [watch]

history

listquota path

setAcl path acl

getAcl path

sync path

redo cmdno

addauth scheme auth

delete path [version]

setquota -n|-b val path

2、ls命令

[zk: hadoop-server01(CONNECTED) 2] ls /

3、创建节点

[zk: hadoop-server01(CONNECTED) 4] create /itcast 500000

[zk: hadoop-server01(CONNECTED) 5] ls /

[itcast, zookeeper]

[zk: hadoop-server01(CONNECTED) 7] get /itcast

500000

cZxid = 0x100000004

ctime = Sun Jul 01 20:37:56 PDT 2018

mZxid = 0x100000004

mtime = Sun Jul 01 20:37:56 PDT 2018

pZxid = 0x100000004

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 0

4、修改数据

[zk: hadoop-server01(CONNECTED) 8] set /itcast 100000

cZxid = 0x100000004

ctime = Sun Jul 01 20:37:56 PDT 2018

mZxid = 0x100000005

mtime = Sun Jul 01 20:40:17 PDT 2018

pZxid = 0x100000004

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 0

[zk: hadoop-server01(CONNECTED) 9] get /itcast

100000

cZxid = 0x100000004

ctime = Sun Jul 01 20:37:56 PDT 2018

mZxid = 0x100000005

mtime = Sun Jul 01 20:40:17 PDT 2018

pZxid = 0x100000004

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

5、注册监听器

比如:

[zk: hadoop-server01(CONNECTED) 0] get /itcast watch --该注册只能收到一次通知,收到后失效

100000

cZxid = 0x100000004

ctime = Sun Jul 01 20:37:56 PDT 2018

mZxid = 0x100000005

mtime = Sun Jul 01 20:40:17 PDT 2018

pZxid = 0x100000004

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 0

在其它节点就该数据

[zk: hadoop-server02(CONNECTED) 0] set /itcast 4000000

cZxid = 0x100000004

ctime = Sun Jul 01 20:37:56 PDT 2018

mZxid = 0x10000000b

mtime = Sun Jul 01 22:13:14 PDT 2018

pZxid = 0x100000004

cversion = 0

dataVersion = 2

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 7

numChildren = 0

观察注册监听器节点变化

WatchedEvent state:SyncConnected type:NodeDataChanged path:/itcast




声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:4051308@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。