欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

windows把zookeeper注册成服务

程序员文章站 2022-05-04 17:53:42
...

1.下载zookeeper服务插件(zip包)

http://archive.apache.org/dist/commons/daemon/binaries/windows/

2.把prunsrv.exe、prunmgr.exe复制到zookeeper的bin路径下

windows把zookeeper注册成服务

 3.新建一个install.bat文件,用于注册服务

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

4.新建一个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

5.配置zookeeper的环境变量,新建ZOOKEEPER_HOME和ZOOKEEPER_SERVICE,前面是你安装zookeeper的bin路径,后面是你server的名称。

windows把zookeeper注册成服务

6.在cmd中以管理员启动install.bat文件。

7.查看zookeeper服务是否启动成功(启动之前最好关闭cmd启动的zookeeper)。

windows把zookeeper注册成服务