1. Zookeeper安裝
1.1測試JDK
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.2上傳壓縮包
zookeeper官網:https://zookeeper.apache.org/releases.htmlhtml
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.3解壓壓縮包
tar -xvf zookeeper-3.4.14.tar.gz
1.4 刪除壓縮包,將解壓文件更名爲zookeeper(自定義)
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.5 建立data和log文件
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.6 修改zoo.cfg配置文件
1.6.1 進入data文件,pwd
,複製其路徑
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.6.2更改zoo_sample.cfg文件名爲zoo.cfg
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.6.3 修改dataDir路徑,也就是剛纔的data路徑(dataLogDir相似)
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.7 檢測Zooleeper是否安裝成功
1.7.1 進入bin文件目錄下,經過sh zkServer.sh start
開啓
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
1.7.2 開啓後 ,經過 sh zkServer.sh status
檢測狀態 ,
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
狀態顯示爲standalone說明開啓成功,你的Zookeeper安裝成功!!!
2.Zookeeper集羣搭建
2.1 準備工做
2.1.1建立zkCluster文件再zookeeper的根目錄下,再其中建立zk1/zk2/zk3三個文件夾
2.1.2在三個文件夾中建立data和log文件 -- mkdir {zk1,zk2,zk3}/{data,log}
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
2.2建立myid
2.2.1根據不一樣的文件有不一樣myid
-----zk1的myid中內容爲1,zk2爲2,zk3爲3
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
2.3編輯配置文件
2.3.1 複製zk1的路徑
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
2.3.2 在conf文件目錄下將zoo_sample.cfg 複製爲zoo1.cfg以後修改配置文件.
2.3.3 vim zoo1.cfg -->> 更改配置
- dataDir和dataLogDir的路徑就用data和log所對應的路徑
- clientPort 所對應的2181的最後一位數,只需按照myid中的數字所配置,其他三位不用修改
- server.1/2/3 是屬於疊加一的方式,便於記憶
- zoo2.cfg/zoo3.cfg只需按照我上文所述更改便可
- 記住server.1/2/3不須要更改,只用配置一次
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
2.4 測試集羣搭建是否成功
sh zkServer.sh start zoo1.cfg 開啓
sh zkServer.sh stop zoo1.cfg 關閉
sh zkServer.sh status zoo1.cfg 檢測狀態
2.4.1 在圖中我只開啓了zoo1.cfg/zoo2.cfg---->> 從我框住的能夠看出,zoo2.cfg爲主機,zoo1.cfg爲從機,若是zoo3.cfg開啓,依舊是zoo2.cfg的從機
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
Zookeeper集羣搭建成功!!!