1.下載的Zookeeper是.cmd的批處理命令運行的,默認沒有提供以windows服務的方式運行的方案apache
下載地址:http://zookeeper.apache.org/windows
2.下載prunsrv app
下載地址:http://archive.apache.org/dist/commons/daemon/binaries/windows/ code
3.解壓後複製文件 token
64位機器用amd64/prunsrv.exe
a. 複製 commons-daemon-1.0.15-bin-windows/amd64/prunsrv.exe 至 zookeeper-3.4.8\bin目錄下
這是作服務的執行程序
b. 複製 commons-daemon-1.0.15-bin-windows/prunmgr.exe 至 zookeeper-3.4.8\bin目錄下
監控服務配置及運行的程序 ip
4.配置環境變量get
添加ZOOKEEPER_SERVICE, ZOOKEEPER_HOME兩個環境變量cmd
ZOOKEEPER_SERVICE:服務名稱(不要有中文)io
ZOOKEEPER_HOME:設置到zookeeper-3.4.8目錄下監控
5.生成zoo.cfg
在zookeeper-3.4.8\conf目錄下複製一份zoo_sample.cfg文件,並重命名爲zoo.cfg
6.在zookeeper-3.4.8\bin目錄下添加一個 zkServerStop.cmd 文件
內容以下:
@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
7.新建一個批處理安裝文件:install.bat
內容以下:
最後在cmd中以管理員身份運行install.bat就OK了。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