一:安裝html
1:下載 zookeeper 安裝包,解壓;node
2:修改配置文件。apache
a:將文件目錄下的z oo_sample.cfg 文件複製一份到該目錄,而且更名爲 zoo.cfg;ide
b:修改zoo.cfg的文件內容。打開文件,修改 dataDir 屬性的值,修改成本機存在的目錄;ui
# 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=/tmp/zookeeper dataDir=D:/zookeperSpace # 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
3,啓動 zookeeper的服務。對應的啓動文件---zkServer.cmd;this
4,啓動zookeeper的客戶端。對應的啓動文件--zkCli.cmd;spa
二。zookeeper簡單使用code
1,建立節點htm
命令格式: create /node_1blog
說明:
a:建立臨時節點: create -e /node_2 "555";
b:建立有序節點:create -s /node_2 "555"
能夠用於生成主鍵
2,查詢節點
get /node_1
3.更新節點
命令格式:set /node_1 123
說明:
命令格式:set /node_1 "value "version (可選)
set 命令後,節點的version字段會增長;
set 時,若是version和當前節點的version不一致,則不能set成功。能夠經過version,查看該節點被修改的次數,也能夠經過該屬性,查看別人是否修改了節點;
4,刪除節點
命令格式:delete /node_1 version
說明:
a:該節點沒有子節點,則刪除成功;
b:version 字段設置同 set;
c:若是要所有刪除節點,則使用 rmr /節點名稱
d:節點 /zookeeper不能刪除;
5,列出目錄下的節點
命令格式:ls /節點路徑
說明:節點路徑必須以"/"開始;