window安装zookeeper服务、开机自动运行
原创 exception 发表于:2018-09-09 10:27:27
  阅读 :962   收藏   编辑
  • zk下载地址:http://archive.apache.org/dist/zookeeper/

  • commons-daemon下载地址:http://archive.apache.org/dist/commons/daemon/binaries/windows/ 

本例zk版本:3.4.5 ,daemon版本:1.0.15  

http://archive.apache.org/dist/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz 

http://archive.apache.org/dist/commons/daemon/binaries/windows/commons-daemon-1.0.15-bin-windows.zip 

复制一份zk目录下conf下的zoo_sample.cfg,更名为zoo.cfg

21

修改dataDir为自己的地址

# 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=G:\server\zookeeper-3.4.6\zookeeper-3.4.6\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

解压下载好的commons-daemon-1.0.15-bin-windows

  • 64位系统复制amd64/prunsrv.exe 到zk目录下的bin目录下

22

  • 复制prunmgr.exe 到zk目录下的bin目录下

23

为Zookeeper配置环境变量

  • 新增ZOOKEEPER_SERVICE 服务名称(不要有中文),我的是zk_service

  • ZOOKEEPER_HOME zk的解压目录

新建 zkServerStop.cmd 文件

在zk目录下的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

新增安装文件install.bat文件

也是在zk目录下的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

启动zk

开始→运行(Windows+R)   输入:services.msc

24

卸载

开始→运行(Windows+R)输入regedit 然后依次打开HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services

删除即可