命令基本语法 | 功能描述 |
---|---|
help | 显示所有操作命令 |
ls path [watch] | 使用 ls 命令来查看当前znode中所包含的内容 |
ls2 path [watch] | 查看当前节点数据并能看到更新次数等数据 |
create | 普通创建 |
create | -s 含有序列 |
create | -e 临时(重启或者超时消失) |
get path [watch] | 获得节点的值 |
set | 设置节点的具体值 |
stat | 查看节点状态 |
delete | 删除节点 |
rmr | 递归删除节点 |
[bigdata@hadoop002 zookeeper-3.4.10]$ bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 1] help
[zk: localhost:2181(CONNECTED) 2] ls /
[zk: localhost:2181(CONNECTED) 3] ls2 /
[zk: localhost:2181(CONNECTED) 6] create /sanguo "jinlian" Created /sanguo
Node already exists: /sanguo
[zk: localhost:2181(CONNECTED) 7] create /sanguo/shuguo "liubei"
Created /sanguo/shuguo
[zk: localhost:2181(CONNECTED) 8] get /sanguo
[zk: localhost:2181(CONNECTED) 9] get /sanguo/shuguo
[zk: localhost:2181(CONNECTED) 10] create -e /sanguo/wuguo "zhouyu"
Created /sanguo/wuguo
[zk: localhost:2181(CONNECTED) 11] ls /sanguo
[wuguo, shuguo]
[zk: localhost:2181(CONNECTED) 12] quit
[bigdata@hadoop002 zookeeper-3.4.10]$ bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /sanguo
[shuguo]
[zk: localhost:2181(CONNECTED) 1] create /sanguo/weiguo "caocao"
Created /sanguo/weiguo
如果原来没有序号节点,序号从0开始依次递增。如果原节点下已有2个节点,则再排序时从2开始,以此类推。
[zk: localhost:2181(CONNECTED) 5] set /sanguo/weiguo "simayi"
[zk: localhost:2181(CONNECTED) 26] [zk: localhost:2181(CONNECTED) 8] get /sanguo watch
[zk: localhost:2181(CONNECTED) 1] set /sanguo "xisi"
WATCHER::
WatchedEvent state:SyncConnected type:NodeDataChanged path:/sanguo
[zk: localhost:2181(CONNECTED) 1] ls /sanguo watch
[shuguo, weiguo]
[zk: localhost:2181(CONNECTED) 2] create /sanguo/jin "simayi"
Created /sanguo/jin
WATCHER::
WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/sanguo
[zk: localhost:2181(CONNECTED) 4] delete /sanguo/jin
[zk: localhost:2181(CONNECTED) 15] rmr /sanguo/shuguo
[zk: localhost:2181(CONNECTED) 17] stat /sanguo
本篇博客就到这里了,下一篇博客博主将为大家带来Zookeeper的API操作,敬请期待!!!