月眸


zookeeper学习四:zookeeper客户端命令介绍

毛毛小妖 2019-08-08 425浏览 0条评论
首页/ 正文
分享到: / / / /

集群搭建完之后,就可以用客户端对服务器进行操作了,下面来看一下有哪些客户端命令吧。

命令基本语法 功能描述
help 显示所有操作命令
ls path [watch] 使用ls命令查看当前znode中包含的内容
ls2 path [watch] 查看当前结点数据并能够看到更新次数等信息
create

普通创建

-s    含有序号

-e    临时创建(重启或者超时消失)

get path [watch] 获得节点的值
set 设置节点的具体值
stat 查看节点状态
delete 删除节点
rmr 递归删除节点

1、启动客户端

[root@master bin]# pwd
/opt/software/zookeeper-3.4.14/bin
[root@master bin]# ./zkCli.sh 

2、显示所有操作命令

[zk: localhost:2181(CONNECTED) 3] help
ZooKeeper -server host:port cmd args
        stat path [watch]
        set path data [version]
        ls path [watch]
        delquota [-n|-b] path
        ls2 path [watch]
        setAcl path acl
        setquota -n|-b val path
        history 
        redo cmdno
        printwatches on|off
        delete path [version]
        sync path
        listquota path
        rmr path
        get path [watch]
        create [-s] [-e] path data acl
        addauth scheme auth
        quit 
        getAcl path
        close 
        connect host:port
[zk: localhost:2181(CONNECTED) 4]

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

[zk: localhost:2181(CONNECTED) 0] ls /
[sanguo0000000001, wb, zookeeper, test]
[zk: localhost:2181(CONNECTED) 1]

4、查看当前节点全部数据

[zk: localhost:2181(CONNECTED) 5] ls2 /
[sanguo0000000001, wb, zookeeper, test]
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x200000006
cversion = 2
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 4
[zk: localhost:2181(CONNECTED) 6]

5、创建普通节点

创建的节点必须要有内容,否则不会创建

[zk: localhost:2181(CONNECTED) 21] create /eyesmoons "测试内容"
Created /eyesmoons
[zk: localhost:2181(CONNECTED) 22]ls /
[zookeeper, eyesmoons]

6、创建带编号的节点

[zk: localhost:2181(CONNECTED) 37] create -s /eyesmoonsNo "带编号的 普的 通普通普通普通 普通的的 的节点"
Created /eyesmoonsNo0000000004
[zk: localhost:2181(CONNECTED) 38] ls /
[zookeeper, eyesmoons, eyesmoonsNo0000000004]
[zk: localhost:2181(CONNECTED) 39]

7、获得节点的值

[zk: localhost:2181(CONNECTED) 43] get /eyesmoons
测试内容
cZxid = 0x20000000f
ctime = Thu Aug 08 23:42:18 CST 2019
mZxid = 0x20000000f
mtime = Thu Aug 08 23:42:18 CST 2019
pZxid = 0x20000000f
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 12
numChildren = 0
[zk: localhost:2181(CONNECTED) 44]

8、修改节点数据

[zk: localhost:2181(CONNECTED) 57] set /eyesmoons "修改后得知的巍峨"
cZxid = 0x20000000f
ctime = Thu Aug 08 23:42:18 CST 2019
mZxid = 0x200000015
mtime = Thu Aug 08 23:48:41 CST 2019
pZxid = 0x20000000f
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 24
numChildren = 0
[zk: localhost:2181(CONNECTED) 58] get /eyesmoons

eyesmoons               eyesmoonsNo0000000004
[zk: localhost:2181(CONNECTED) 58] get /eyesmoons
修改后得知的巍峨
cZxid = 0x20000000f
ctime = Thu Aug 08 23:42:18 CST 2019
mZxid = 0x200000015
mtime = Thu Aug 08 23:48:41 CST 2019
pZxid = 0x20000000f
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 24
numChildren = 0
[zk: localhost:2181(CONNECTED) 59]

9、节点的值变化监听

在一个节点设置监听

[zk: localhost:2181(CONNECTED) 86] get /eyesmoons watch
修改后得知的巍峨
cZxid = 0x20000000f
ctime = Thu Aug 08 23:42:18 CST 2019
mZxid = 0x200000015
mtime = Thu Aug 08 23:48:41 CST 2019
pZxid = 0x20000000f
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 24
numChildren = 0
[zk: localhost:2181(CONNECTED) 87] 

在另一个节点修改值

[zk: localhost:2181(CONNECTED) 0] set /eyesmoons "测试监听"
cZxid = 0x20000000f
ctime = Thu Aug 08 23:42:18 CST 2019
mZxid = 0x200000017
mtime = Thu Aug 08 23:50:53 CST 2019
pZxid = 0x20000000f
cversion = 0
dataVersion = 2
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 12
numChildren = 0
[zk: localhost:2181(CONNECTED) 1]

立马能感知到修改:

[zk: localhost:2181(CONNECTED) 86] get /eyesmoons watch
修改后得知的巍峨
cZxid = 0x20000000f
ctime = Thu Aug 08 23:42:18 CST 2019
mZxid = 0x200000015
mtime = Thu Aug 08 23:48:41 CST 2019
pZxid = 0x20000000f
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 24
numChildren = 0
[zk: localhost:2181(CONNECTED) 87] 
WATCHER::

WatchedEvent state:SyncConnected type:NodeDataChanged path:/eyesmoons

10、删除节点

[zk: localhost:2181(CONNECTED) 14] delete /eyesmoons
[zk: localhost:2181(CONNECTED) 15] ls /
[zookeeper, eyesmoonsNo0000000004]
[zk: localhost:2181(CONNECTED) 16]

11、查看节点状态

[zk: localhost:2181(CONNECTED) 19] stat /eyesmoonsNo0000000004       
cZxid = 0x200000014
ctime = Thu Aug 08 23:46:15 CST 2019
mZxid = 0x200000014
mtime = Thu Aug 08 23:46:15 CST 2019
pZxid = 0x200000014
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 54
numChildren = 0
[zk: localhost:2181(CONNECTED) 20]

 

最后修改:2019-08-08 16:23:58 © 著作权归作者所有
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

上一篇

发表评论

评论列表

还没有人评论哦~赶快抢占沙发吧~