一.windows系统

zookeeper提取码:zook

procrun提取码:proc

1.解压zookeeper并新建两个文件夹:datalog

 2.在conf中打开zoo.cfg文件,并将刚新增的文件夹路径设置进去

 

 3.编写停止脚本zkServerStop.cmd放在bin目录下
@echo off
 
cd..
set CDIR=%CD%
set ZOOKEEPER_SERVICE=zookeeper
set ZOOKEEPER_HOME=%CDIR%
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
pause

 

 4.解压procrun,并将prunmgr.exe和prunsrv.exe文件复制进zookeeper根目录,然后修改名称

 

 5.编写两个脚本

服务安装脚本:install.bat

@echo off
 
cd.
set CDIR=%CD%
cd..
set BASEDIR=%CD%
set SRV=%CDIR%\zookeeper-srv.exe
set ZOOKEEPER_HOME=%CDIR%
set NAME=Zookeeper
"%SRV%" //IS//%NAME% --DisplayName=%NAME% --Description=%NAME% --Startup=manual --StartMode=exe --StartPath="%ZOOKEEPER_HOME%" --StartImage="%ZOOKEEPER_HOME%\bin\zkServer.cmd" --StopPath="%ZOOKEEPER_HOME%" --StopImage="%ZOOKEEPER_HOME%\bin\zkServerStop.cmd" --StopMode=exe --StopTimeout=10 --LogPath="%ZOOKEEPER_HOME%\log" --LogPrefix="zookeeper-log" --PidFile=zookeeper.pid --LogLevel=Info --StdOutput=auto --StdError=auto
echo install success
pause

服务卸载脚本:uninstall.bat
@echo off
 
cd.
set CDIR=%CD%
cd..
set BASEDIR=%CD%
set SERVICE_NAME=Zookeeper
set SRV=%CDIR%\zookeeper-srv.exe
%SRV% //DS//%SERVICE_NAME%
echo finish uninstall
pause

 6.双击install.bat脚本执行安装服务

 

 

 二.centos系统

 附件提取码:zook

1.将安装包移到指定位置

 2.cd到安装包所在目录:cd /opt/server,然后解压到指定位置:tar -xvzf zookeeper-3.4.14.tar.gc -C /opt/server,解压后重命名

 

 

 3.将conf目录里的zoo_sample.cfg复制一份名为zoo.cfg的文件:cp zoo_sample.cfg zoo.cfg

 

 

 4.新建下图中的文件夹并在zoo.cfg文件里进行配置

 

 5.在conf/java.env中进行配置

 

 6.配置环境变量,在/etc/profile文件的最后添加如下的配置,然后执行:source /etc/profile

 

 

 7.配置自启动,在/usr/lib/systemd/system/里新建zookeeper.service,内容如下(路径修改为自己的)

[Unit]
Description=zookeeper
After=network.target
ConditionPathExists=/opt/server/zookeeper3.4.14/conf/zoo.cfg

[Service]
Type=forking
Environment=ZOO_LOG_DIR=/opt/server/zookeeper3.4.14/log
ExecStart=/opt/server/zookeeper3.4.14/bin/zkServer.sh start
ExecStop=/opt/server/zookeeper3.4.14/bin/zkServer.sh stop
User=root
Group=root

[Install]
WantedBy=multi-user.target

然后执行systemctl enable zookeeper配置自启动,再输入启动命令:systemctl start zookeeper

 

 

 

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐