本文主要講解zookeeper的下載、安裝、和常見啓動問題的解決
一:下載
官網下載地址:http://mirror.bit.edu.cn/apache/zookeeper/
1:選擇要下載的版本,這裏我選擇的是3.5.5版本
2:選擇帶有bin名稱的包進行下載(至於爲什麼選擇,下面解釋)
二:安裝
1:將下載的下來的包解壓,並手動創建“data”和“log”兩個文件夾
2:進入conf文件夾下,選擇“zoo_sample.cfg”文件,複製一份更名“zoo.cfg”
3:進入zoo.cfg進行編輯
# The number of milliseconds of each tick
#tickTime:這個時間是作爲 Zookeeper 服務器之間或客戶端與服務器之間維持心跳的時間間隔,也就是每個 tickTime 時間就會發送一個心跳。
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
#initLimit:這個配置項是用來配置 Zookeeper 接受客戶端(這裏所說的客戶端不是用戶連接 Zookeeper 服務器的客戶端,
#而是 Zookeeper 服務器集羣中連接到 Leader 的 Follower 服務器)初始化連接時最長能忍受多少個心跳時間間隔數。
#當已經超過 10 個心跳的時間(也就是 tickTime)長度後 Zookeeper 服務器還沒有收到客戶端的返回信息,
#那麼表明這個客戶端連接失敗。總的時間長度就是 10*2000=20 秒
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
#syncLimit:這個配置項標識 Leader 與 Follower 之間發送消息,請求和應答時間長度,
#最長不能超過多少個 tickTime 的時間長度,總的時間長度就是 5*2000=10 秒
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#dataDir:顧名思義就是 Zookeeper 保存數據的目錄,默認情況下,Zookeeper 將寫數據的日誌文件也保存在這個目錄裏。
dataDir=D:\apache-zookeeper-3.5.5-bin\apache-zookeeper-3.5.5-bin\data
dataLogDir=D:\apache-zookeeper-3.5.5-bin\apache-zookeeper-3.5.5-bin\log
# the port at which the clients will connect
#clientPort:這個端口就是客戶端連接 Zookeeper 服務器的端口,Zookeeper 會監聽這個端口,接受客戶端的訪問請求。
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
三:啓動
進入bin目錄,點擊zkServer.com進行啓動,如果你啓動成功就不用看下面了。
四:常見問題
1:啓動閃退
如果您啓動閃退:說明有報錯。先查看報錯信息,在解決報錯
點擊zkServer.cmd文件,在最下面添加pause,這樣就可以看到報錯信息
錯誤:文件名、目錄名或卷標語法不正確
如果報錯信息是這個,查看一下你的jdk環境變量的配置,看是否有JAVA_HOME,並且看它的 路徑是否真實存在。
因爲,zookeeper裏面配置的是系統中的jdk環境變量
2:找不到或無法加載主類 org.apache.zookeeper.server.quorum.QuorumPeerMain
這裏就要說上面爲什麼要選擇src的包了
從目前的最新版本3.5.5開始,帶有bin名稱的包纔是我們想要的下載可以直接使用的裏面有編譯後的二進制的包,而之前的普通的tar.gz的包裏面是隻是源碼的包無法直接使用
----------------------------------------------------------------------------------------------------------------------此係列所有內容均學習傳智播客視頻