启动客户端
help
查看当前znode中所包含的内容
ls /
查看当前节点详细数据
ls2 /
分别创建普通节点
第一个
create /sanguo "jinlian"
第二个
create /sanguo/shuguo "liubei"
获得节点的值
get /sanguo
get /sanguo/shuguo
创建短暂节点
create -e /sanguo/wuguo "zhouyu"
在当前客户端是能查看到的
退出当前客户端然后再重启客户端
quit
bin/zkCli.sh
创建带序号的节点
(1)先创建一个普通的根节点/sanguo/weiguo
create /sanguo/weiguo "caocao"
create -s /sanguo/weiguo/xiaoqiao "jinlian"
如果原来没有序号节点,序号从0开始依次递增。如果原节点下已有2个节点,则再排序时从2开始,以此类推。
修改节点数据值
set /sanguo/weiguo "simayi"
删除节点
delete /sanguo/jin
递归删除节点
rmr /sanguo/shuguo
查看节点状态
stat /sanguo
节点的值变化监听
(1)在hadoop104主机上注册监听/sanguo节点数据变化
get /sanguo watch
(2)在hadoop103主机上修改/sanguo节点的数据
set /sanguo "xisi"
(3)观察hadoop104主机收到数据变化的监听
WATCHER::
WatchedEvent state:SyncConnected type:NodeDataChanged path:/sanguo
节点的子节点变化监听(路径变化)
(1)在hadoop104主机上注册监听/sanguo节点的子节点变化
ls /sanguo watch
(2)在hadoop103主机/sanguo节点上创建子节点
create /sanguo/jin "simayi"
(3)观察hadoop104主机收到子节点变化的监听
WATCHER::
WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/sanguo