首先簡要講下安裝
- 安裝jdk
- 安裝Zookeeper. 在官網http://zookeeper.apache.org/下載zookeeper.我下載的是zookeeper-3.4.6版本。
- 解壓zookeeper-3.4.6至D:\machine\zookeeper-3.4.6.
- 在D:\machine 新建data及log目錄。
-
ZooKeeper的安裝模式分為三種,分別為:單機模式(stand-alone)、集群模式和集群偽分布模式。ZooKeeper 單機模式的安裝相對比較簡單,如果第一次接觸ZooKeeper的話,建議安裝ZooKeeper單機模式或者集群偽分布模式。
-
安裝單機模式。 至D:\machine\zookeeper-3.4.6\conf 復制 zoo_sample.cfg 並粘貼到當前目錄下,命名zoo.cfg 也就是指定一個data和log的路徑 端口哪些等等,不然啟動會閃退
-
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=D:\\zookeeper-3.4.8\\data dataLogDir=D:\\zookeeper-3.4.8\\logs # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1
1、打開cmd控制台cd到bin文件夾下, 可以通過
zkServer.cmd
啟動server
2、再打開一個cmd控制台,cd到bin文件夾下,執行
zkCli -server 127.0.0.1:2181
連接成功,回車后即可輸入命令
建立節點
create /zk hello
獲得節點
get /zk
設置節點
set /zk hello2
建立子節點
set /zk/subzk hello3
輸出節點目錄
ls /zk
刪除節點
delete /zk
3、zookeeper的四字命令
| ZooKeeper 四字命令 |
功能描述 |
| conf |
輸出相關服務配置的詳細信息。 |
| cons |
列出所有連接到服務器的客戶端的完全的連接 / 會話的詳細信息。包括“接受 / 發送”的包數量、會話 id 、操作延遲、最后的操作執行等等信息。 |
| dump |
列出未經處理的會話和臨時節點。 |
| envi |
輸出關於服務環境的詳細信息(區別於 conf 命令)。 |
| reqs |
列出未經處理的請求 |
| ruok |
測試服務是否處於正確狀態。如果確實如此,那么服務返回“imok ”,否則不做任何相應。 |
| stat |
輸出關於性能和連接的客戶端的列表。 |
| wchs |
列出服務器 watch 的詳細信息。 |
| wchc |
通過 session 列出服務器 watch 的詳細信息,它的輸出是一個與watch 相關的會話的列表。 |
| wchp |
通過路徑列出服務器 watch 的詳細信息。它輸出一個與 session相關的路徑。 |
