當前位置:首頁 > IT技術(shù) > 系統(tǒng)服務(wù) > 正文

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作
2021-09-02 20:53:45

??此篇的操作都是在上篇的基礎(chǔ)上進行的。


下 表 為 客 戶 端 常 用 的 s h e l l 操 作 color{#FF0000}{下表為客戶端常用的shell操作} shell

命令基本語法 功能描述
help 顯示所有操作命令
ls path [watch] 使用 ls 命令來查看當前znode中所包含的內(nèi)容
ls2 path [watch] 查看當前節(jié)點數(shù)據(jù)并能看到更新次數(shù)等數(shù)據(jù)
create 普通創(chuàng)建
create -s 含有序列
create -e 臨時(重啟或者超時消失)
get path [watch] 獲得節(jié)點的值
set 設(shè)置節(jié)點的具體值
stat 查看節(jié)點狀態(tài)
delete 刪除節(jié)點
rmr 遞歸刪除節(jié)點
1. 啟動客戶端
[bigdata@hadoop002 zookeeper-3.4.10]$ bin/zkCli.sh

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_客戶端

2. 顯示所有操作
[zk: localhost:2181(CONNECTED) 1] help

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_zookeeper_02

3. 查看當前znode中所包含的內(nèi)容
[zk: localhost:2181(CONNECTED) 2] ls /

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_客戶端_03

4. 查看當前節(jié)點詳細數(shù)據(jù)
[zk: localhost:2181(CONNECTED) 3] ls2 /

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_數(shù)據(jù)_04

5. 分別創(chuàng)建2個普通節(jié)點
[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

6. 獲取節(jié)點的值
[zk: localhost:2181(CONNECTED) 8] get /sanguo

[zk: localhost:2181(CONNECTED) 9] get /sanguo/shuguo

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_客戶端_05

7. 創(chuàng)建短暫節(jié)點
[zk: localhost:2181(CONNECTED) 10] create -e /sanguo/wuguo "zhouyu"
Created /sanguo/wuguo

  • 1. 在當前客戶端時能查看到的
[zk: localhost:2181(CONNECTED) 11] ls /sanguo 
[wuguo, shuguo]

  • 2. 退出當前客戶端然后再重啟客戶端
[zk: localhost:2181(CONNECTED) 12] quit
[bigdata@hadoop002 zookeeper-3.4.10]$ bin/zkCli.sh
  • 3. 再次查看根目錄下短暫節(jié)點已經(jīng)刪除
[zk: localhost:2181(CONNECTED) 0] ls /sanguo
[shuguo]
8. 創(chuàng)建帶序號的節(jié)點
  • 1.先創(chuàng)建一個普通的根節(jié)點/sanguo/weiguo
[zk: localhost:2181(CONNECTED) 1] create /sanguo/weiguo "caocao"
Created /sanguo/weiguo
  • 2. 創(chuàng)建帶序號的節(jié)點
    ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_數(shù)據(jù)_06
    ??如果原來沒有序號節(jié)點,序號從0開始依次遞增。如果原節(jié)點下已有2個節(jié)點,則再排序時從2開始,以此類推。

9. 修改節(jié)點數(shù)據(jù)值
[zk: localhost:2181(CONNECTED) 5] set /sanguo/weiguo "simayi"

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_數(shù)據(jù)_07

10. 節(jié)點的值變化監(jiān)聽
  • 1. 在hadoop004主機上注冊監(jiān)聽/sanguo節(jié)點數(shù)據(jù)變化
[zk: localhost:2181(CONNECTED) 26] [zk: localhost:2181(CONNECTED) 8] get /sanguo watch
  • 2. 在hadoop003主機上修改/sanguo節(jié)點的數(shù)據(jù)
[zk: localhost:2181(CONNECTED) 1] set /sanguo "xisi"
  • 3. 觀察hadoop004主機收到數(shù)據(jù)變化的監(jiān)聽
WATCHER::
WatchedEvent state:SyncConnected type:NodeDataChanged path:/sanguo
  • 4. 圖解
    ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_客戶端_08
11. 節(jié)點的子節(jié)點變化監(jiān)聽(路徑變化)
  • 1. 在hadoop004主機上注冊監(jiān)聽/sanguo節(jié)點的子節(jié)點變化
[zk: localhost:2181(CONNECTED) 1] ls /sanguo watch
[shuguo, weiguo]
  • 2. 在hadoop003主機/sanguo節(jié)點上創(chuàng)建子節(jié)點
[zk: localhost:2181(CONNECTED) 2] create /sanguo/jin "simayi"
Created /sanguo/jin
  • 3. 觀察hadoop004主機收到子節(jié)點變化的監(jiān)聽
WATCHER::
WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/sanguo
  • 4. 圖解

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_數(shù)據(jù)_09

12. 刪除節(jié)點
[zk: localhost:2181(CONNECTED) 4] delete /sanguo/jin
13. 遞歸刪除節(jié)點
[zk: localhost:2181(CONNECTED) 15] rmr /sanguo/shuguo
14. 查看節(jié)點狀態(tài)
[zk: localhost:2181(CONNECTED) 17] stat /sanguo

ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_大數(shù)據(jù)_10

本篇博客就到這里了,下一篇博客博主將為大家?guī)鞿ookeeper的API操作,敬請期待!!!


ZooKeeper快速入門系列(5) | Zookeeper常用的shell操作_數(shù)據(jù)_11

?? 看 完 就 贊 , 養(yǎng) 成 習 慣 ! ! ! color{#FF0000}{看完就贊,養(yǎng)成習慣?。。 ,養(yǎng)!!!^ _ ^ ?? ?? ??
??碼字不易,大家的支持就是我堅持下去的動力。點贊后不要忘了關(guān)注我哦!

本文摘自 :https://blog.51cto.com/u

開通會員,享受整站包年服務(wù)立即開通 >