Window部署zookeeper

Posted StoryBoy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Window部署zookeeper相关的知识,希望对你有一定的参考价值。

准备:

下载zookeeper
下载jdk

安装配置

  1. 设置JAVA_HOME环境变量(配置好后,==注销电脑生效==):
    以管理员身份运行:

 
   
   
 
  1. wmic environment create name="JAVA_HOME",username="<system>",VariableValue="C:\Program Files\Java\jdk1.8.0_131"

  1. 配置
    2.1 conf目录下 copy zoo_sample.cfg zoo.cfg 并修改配置
    其他可默认,主要修改一下配置即可 

    dataDir=G:\\Software\Architect\zookeeper-3.5.3-beta\data
    2.2 集群配置 

    initLimit=5
    syncLimit=2
    server.1=192.168.211.1:2888:3888
    server.2=192.168.211.2:2888:3888

  2. 测试

    双击启动bin目录(G:\Software\Architect\zookeeper-3.5.3-beta\bin)的zkServer.cmd 查看端口是否正常:

 
   
   
 
  1. netstat -aon | findstr 2181

监控zookeeper软件

zk ui部署
编译zkui:(懒人可直接下载编译好的资源zkui-2.0)

 
   
   
 
  1. cd /d G:\Software\Architect\zkui-master

  2. mvn clean install

将config.cfg拷贝到jar同目录下,并修改配置

 
   
   
 
  1. cd /d G:\Software\Architect\zkui-master\target

  2. copy ..\config.cfg .\

 
   
   
 
  1. #Server Port

  2. serverPort=9090

  3. #Comma seperated list of all the zookeeper servers

  4. zkServer=10.0.0.7:2181

  5. #可调节连接zookeeper的超时时间

  6. #zkSessionTimeout=20

启动zkui

 
   
   
 
  1. java -jar zkui-2.0-SNAPSHOT-jar-with-dependencies.jar

制作成批处理zkuiStart.cmd

 
   
   
 
  1. cd /d %~dp0

  2. java -jar zkui-2.0-SNAPSHOT-jar-with-dependencies.jar

username: admin, pwd: manager
zookeeper未启动时,会报错误如下:

 
   
   
 
  1. KeeperErrorCode = ConnectionLoss for /


将zookeeper做成windows服务

  1. 下载prunsrv

    以管理员身份运行批处理(设置ZOOKEEPERSERVICE,ZOOKEEPERHOME环境变量):

 
   
   
 
  1. wmic environment create name="ZOOKEEPER_SERVICE",username="<system>",VariableValue="zookeeperService"

  2. wmic environment create name='ZOOKEEPER_HOME',username="<system>",VariableValue="G:\Software\Architect\zookeeper-3.5.3-beta"

  1. 拷贝文件

 
   
   
 
  1.  64位机器用amd64/prunsrv.exe

  2.   a. 复制 commons-daemon-1.0.15-bin-windows/amd64/prunsrv.exe zookeeper\bin目录下

  3.   这是做服务的执行程序

  4.   b. 复制 commons-daemon-1.0.15-bin-windows/prunmgr.exe zookeeper\bin目录下

  1. install.bat安装脚本(放于zookeeper bin目录下):

 
   
   
 
  1. prunsrv.exe "//IS//%ZOOKEEPER_SERVICE%" ^

  2.        --DisplayName="Zookeeper (%ZOOKEEPER_SERVICE%)" ^

  3.        --Description="Zookeeper (%ZOOKEEPER_SERVICE%)" ^

  4.        --Startup=auto --StartMode=exe ^

  5.        --StartPath=%ZOOKEEPER_HOME% ^

  6.        --StartImage=%ZOOKEEPER_HOME%\bin\zkServer.cmd ^

  7.        --StopPath=%ZOOKEEPER_HOME%\ ^

  8.        --StopImage=%ZOOKEEPER_HOME%\bin\zkServerStop.cmd ^

  9.        --StopMode=exe --StopTimeout=5 ^

  10.        --LogPath=%ZOOKEEPER_HOME% --LogPrefix=zookeeper-wrapper ^

  11.        --PidFile=zookeeper.pid --LogLevel=Info --StdOutput=auto --StdError=auto

  1. zkServerStop.cmd停止服务:

 
   
   
 
  1. @echo off

  2. setlocal

  3. TASKLIST /svc | findstr /c:"%ZOOKEEPER_SERVICE%" > %ZOOKEEPER_HOME%\zookeeper_svc.pid

  4. FOR /F "tokens=2 delims= " %%G IN (%ZOOKEEPER_HOME%\zookeeper_svc.pid) DO (

  5.    @set zkPID=%%G

  6. )

  7. taskkill /PID %zkPID% /T /F

  8. del %ZOOKEEPER_HOME%/zookeeper_svc.pid

  9. endlocal

==特别的JAVAHOME一定要设置为系统变量,否则会报JAVAHOME未设置==

参考资料:

zk ui部署
安装成windows服务


以上是关于Window部署zookeeper的主要内容,如果未能解决你的问题,请参考以下文章

很实用的JQuery代码片段(转)

add application window with unknown token XXX Unable to add window;is your activity is running?(代码片段

add application window with unknown token XXX Unable to add window;is your activity is running?(代码片段

window7环境下ZooKeeper的安装运行及监控查看

asp.net页面实用代码片段

导致资产预编译在heroku部署上失败的代码片段