下载

官网:https://zookeeper.apache.org/releases.html
我下载的是3.6.1版本。主要要下载文件名带有bin的包。不然就会遇到后续提到的错误。

安装

将压缩包解压后放到一个目录下,将zoo_sample.cfg文件复制一份,修改名称为zoo.cfg
图片.png

配置一下数据和日志文件的存放路径,也就是dataDir和dataLogDir这两个属性,配置文件内容如下。

  1. # The number of milliseconds of each tick
  2. tickTime=2000
  3. # The number of ticks that the initial
  4. # synchronization phase can take
  5. initLimit=10
  6. # The number of ticks that can pass between
  7. # sending a request and getting an acknowledgement
  8. syncLimit=5
  9. # the directory where the snapshot is stored.
  10. # do not use /tmp for storage, /tmp here is just
  11. # example sakes.
  12. dataDir=D:\\ProgramData\\apache-zookeeper-3.6.1\\data
  13. dataLogDir=D:\\ProgramData\\apache-zookeeper-3.6.1\\log
  14. # the port at which the clients will connect
  15. clientPort=2181
  16. # the maximum number of client connections.
  17. # increase this if you need to handle more clients
  18. #maxClientCnxns=60
  19. #
  20. # Be sure to read the maintenance section of the
  21. # administrator guide before turning on autopurge.
  22. #
  23. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  24. #
  25. # The number of snapshots to retain in dataDir
  26. #autopurge.snapRetainCount=3
  27. # Purge task interval in hours
  28. # Set to "0" to disable auto purge feature
  29. #autopurge.purgeInterval=1
  30. ## Metrics Providers
  31. #
  32. # https://prometheus.io Metrics Exporter
  33. #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
  34. #metricsProvider.httpPort=7000
  35. #metricsProvider.exportJvmInfo=true

运行

进入bin目录,运行zkServer.cmd启动服务,再运行zkCli.cmd验证是否安装成功。
图片.png
安装成功

遇到问题

运行zkServer.cmd遇到如下报错信息:

错误: 找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain

从3.5.5版本开始,带有bin名称的包是可以直接使用的里面有编译后的二进制的包。重新下载后再操作即可。

参考链接

windows环境下安装zookeeper教程详解(单机版)
zookeeper-3.5.5安装报错:找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain