记录一下,网上有些资料是错的,prunsrv的参数要以
--
开头!
一
下载最新版的apache commons daemon
http://archive.apache.org/dist/commons/daemon/binaries/windows/commons-daemon-1.3.4-bin-windows.zip
解压,复制两个exe文件到zk的bin目录下
二
编写服务停止脚本(启动脚本不用自己写,zk提供了的),保存为$ZOOKEEPER_HOME/bin/zkServerStop.cmd
@echo off
rem 设置监听的端口号,zookeeper默认端口号2181,kafka默认端口号9092
set port=2181
echo port : %port%
for /f "usebackq tokens=1-5" %%a in (`netstat -ano ^| findstr %port%`) do (
if [%%d] EQU [LISTENING] (
set pid=%%e
)
)
for /f "usebackq tokens=1-5" %%a in (`tasklist ^| findstr %pid%`) do (
set image_name=%%a
)
echo now will kill process : pid %pid%, image_name %image_name%
rem 根据进程ID,kill进程
taskkill /f /pid %pid%
三
编写服务安装脚本,里面可以直接把zk的路径和服务名这些参数设置一下,也可以配置环境变量,保存为$ZOOKEEPER_HOME/bin/install.bat
注意:prunsrv的参数都是
--
开始的,网上很多地方都写错了
@echo off
set BASEDIR=%CD%
rem 设置程序名称
set SERVICE_EN_NAME=Zookeeper
rem set ZOOKEEPER_HOME=F:\zookeeper-3.6.1-binset SERVICE_CH_NAME=zookeeper_service
set SRV=%ZOOKEEPER_HOME%\bin\prunsrv.exe
rem 输出信息
echo SERVICE_NAME: %SERVICE_EN_NAME%
echo ZOOKEEPER_HOME: %ZOOKEEPER_HOME%
rem 安装
prunsrv.exe //IS//"%SERVICE_EN_NAME%" --DisplayName="Zookeeper (%SERVICE_EN_NAME%)" --Description="Zookeeper (%SERVICE_EN_NAME%)" --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
pause off
四
执行install.bat安装服务,再执行services.msc,进服务管理器里面找刚刚安装的zk服务,点击启动
五
去zk主目录找*.log文件,看下启动有没有问题,然后执行bin/zkCli.cmd,检查一下能不能连上zk
[zk: localhost:2181(CONNECTED) 2] ls /zookeeper
[config, quota]
标签:bin,ZOOKEEPER,windows,zookeeper,--,set,HOME%,apache
From: https://www.cnblogs.com/sunhaixian/p/17826243.html