很少說,直接上乾貨!html
爲何要在Win下來安裝Zookeeper呢?apache
其實玩過大數據的人很清楚,在Linux下我更不說了。在win下,如Disconf 、Dubbo等應用。windows
因此,它的應用是很是廣的。app
ZooKeeper是一個分佈式的,開放源碼的分佈式應用程序協調服務,是Google的Chubby一個開源的實現,是Hadoop和Hbase的重要組件。它是一個爲分佈式應用提供一致性服務的軟件,提供的功能包括:配置維護、域名服務、分佈式同步、組服務等。分佈式
ZooKeeper的目標就是封裝好複雜易出錯的關鍵服務,將簡單易用的接口和性能高效、功能穩定的系統提供給用戶。ide
ZooKeeper包含一個簡單的原語集,提供Java和C的接口。oop
ZooKeeper代碼版本中,提供了分佈式獨享鎖、選舉、隊列的接口,代碼在zookeeper-3.4.8\src\recipes。其中分佈鎖和隊列有Java和C兩個版本,選舉只有Java版本。post
zookeeper下載地址:性能
http://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/
(可自行在官網下載本身須要的版本)大數據
我這裏以zookeeper-3.4.8爲例。
個人是解壓到指定目錄下 D:\SoftWare\zookeeper-3.4.8
本博文,只關心其bin目錄和conf目錄。
如下是默認的內容
# 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
# 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
主要修改配置中的 dataDir ,根據本身實際修改便可,以下
好比我這裏是
dataDir=D:\SoftWare\zookeeper-3.4.8\data
因此,個人爲
# 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:\SoftWare\zookeeper-3.4.8\data
# 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
進入cmd下進bin目錄,執行 zkserver.cmd 便可啓動
至此,完成!
下載的Zookeeper是.cmd的批處理命令運行的,默認沒有提供以windows服務的方式運行的方案!!!
爲此,本文下載prunsrv 來做爲zookeeper的服務管理。
將zookeeper作成 windows 服務,避免每次關閉後,再啓動還須要使用cmd。
下載prunsrv
下載地址:http://archive.apache.org/dist/commons/daemon/binaries/windows/ ,找到commons-daemon-1.0.15-bin-windows
解壓後複製如下文件
注意:64位系統的機器用amd64/prunsrv.exe
(1)複製 commons-daemon-1.0.15-bin-windows/amd64/prunsrv.exe 至 zookeeper-3.4.8\bin目錄下
這是作服務的執行程序
(2)複製 commons-daemon-1.0.15-bin-windows/prunmgr.exe 至 zookeeper-3.4.8\bin目錄下
監控服務配置及運行的程序
爲Zookeeper配置環境變量
添加ZOOKEEPER_SERVICE, ZOOKEEPER_HOME兩個環境變量
ZOOKEEPER_SERVICE:服務名稱(不要有中文),我這裏取的是,命名爲zookeeper_service
ZOOKEEPER_HOME:設置到zookeeper-3.4.8目錄下
新建 zkServerStop.cmd 文件
在zookeeper-3.4.8\bin目錄下添加一個 zkServerStop.cmd 文件.
(注:cmd文件或者下面的bat文件,咱們均可以先建立一個文本文件,而後把下面的內容copy進去,而後修改文本文件的後綴名便可)
內容以下:
@echo off
setlocal
TASKLIST /svc | findstr /c:"%ZOOKEEPER_SERVICE%" > %ZOOKEEPER_HOME%\zookeeper_svc.pid
FOR /F "tokens=2 delims= " %%G IN
(%ZOOKEEPER_HOME%\zookeeper_svc.pid) DO (
@set zkPID=%%G
)
taskkill /PID %zkPID% /T /F
del %ZOOKEEPER_HOME%/zookeeper_svc.pid
endlocal
新建一個批處理安裝文件install.bat
(注: install.bat 文件也須要放在zookeeper-3.4.8\bin 目錄下才能夠)
prunsrv.exe "//IS//%ZOOKEEPER_SERVICE%" ^ --DisplayName="Zookeeper (%ZOOKEEPER_SERVICE%)" ^
--Description="Zookeeper (%ZOOKEEPER_SERVICE%)" ^
--Startup=auto --StartMode=exe ^
--StartPath=%ZOOKEEPER_HOME% ^
--StartImage=%ZOOKEEPER_HOME%\bin\zkServer.cmd ^
--StopPath=%ZOOKEEPER_HOME%\ ^
--StopImage=%ZOOKEEPER_HOME%\bin\zkServerStop.cmd ^
--StopMode=exe --StopTimeout=5 ^
--LogPath=%ZOOKEEPER_HOME% --LogPrefix=zookeeper-wrapper ^
--PidFile=zookeeper.pid --LogLevel=Info --StdOutput=auto --StdError=auto
最後在cmd中以管理員身份運行install.bat
(注:其實我想說在install.bat文件就能夠了,而後進入服務管理,就能夠看到相應的服務了,不過這時候還沒啓動,右擊啓動便可。)
zookeeper-3.4.8\bin目錄下,雙擊
查看: 開始→運行(Windows+R快捷鍵也能調出運行) 輸入:services.msc肯定
若是你想完全刪除這個服務,則
開始」——「運行」——「regedit」)而後依次打開HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services