ZooKeeper的安装模式分为三种,分别为:单机模式、集群模式和集群伪分布模式。可根据自己需求选择合适的部署方式。本文主要是单机模式的介绍。
安装zookeeper首先要安装JDK,安装JDK可以参考文章:JDK的使用
电脑上已经安装了JDK,使用java -version 查看安装的JDK版本。
zookeeper官方主页: https://zookeeper.apache.org/
镜像下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/
根据自己的JDK版本,下载对应的镜像,否则会出现不兼容,启动报错问题。
官网发行说明:
2019年5月20日:可用3.5.5版
1、现在建议的最低JDK版本为1.8
2、发布工件已进行了相当大的更改:
apache-zookeeper-XYZtar.gz是标准的仅源发行版,
apache-zookeeper-XYZ-bin.tar.gz是包含二进制文件的便捷tarball
也就是目前的最新版本3.5.5开始,带有bin标识的包才是我们想要的下载可以直接使用的里面有编译后的二进制的包,而之前的普通的tar.gz的包里面是只是源码的包是无法直接使用的。所以这里要下载带bin标识的。
下载好之后解压:
1、zookeeper 的配置文件在 conf 目录下,将conf目录下的zoo_sample.cfg文件更名为zoo.cfg,因为 zookeeper 在启动时会找这个文件作为默认配置文件。
2、在D:\soft\zookeeper\apache-zookeeper-3.6.1-bin 文件夹下创建data目录和log目录。
配置zoo.cfg 文件
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=D:\\soft\\zookeeper\\apache-zookeeper-3.6.1-bin\\data
dataLogDir=D:\\soft\\zookeeper\\apache-zookeeper-3.6.1-bin\\log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
1、tickTime:这个时间是作为 zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
2、dataDir:顾名思义就是 zookeeper 保存数据的目录,默认情况下,zookeeper 将写数据的日志文件也保存在这个目录里。
3、dataLogDir:顾名思义就是 zookeeper 保存日志文件的目录
4、clientPort:这个端口就是客户端连接 zookeeper 服务器的端口,zookeeper 会监听这个端口,接受客户端的访问请求。
当这些配置项配置好后,你现在就可以启动 zookeeper 了
1、可以直接进bin目录,双击 zkServer.cmd 启动
2、进入到bin目录,启动zkServer.cmd,如图
启动成功界面:
启动后,命令 jps 可以看到QuorumPeerMain的进程。
启动客户端查看:zkCli.cmd -server 127.0.0.1:2181
成功界面。
到此,单机的zookeeper的部署就结束了。