进入Apache ZooKeeper官方网站进行下载,https://zookeeper.apache.org/releases.html
这里我们选择zookeeper-3.4.12版本进行下载
百度网盘下载
链接:https://pan.baidu.com/s/1HOEcfGpg7CqAm28cOhGzuA 密码:ap4n
安装
将下载好的zookeeper-3.4.12.tar.gz解压到常用安装目录下面即可
将conf目录下的zoo_sample.cfg文件,复制一份,重命名为zoo.cfg
修改zoo.cfg配置文件,将dataDir=/tmp/zookeeper修改成zookeeper安装目录所在的data文件夹(需要在安装目录下面新建一个空的data文件夹和log文件夹),再添加一条添加数据日志的配置,如下图
启动zookeeper,判定是否安装成功,双击运行bin目录下的zkServer.cmd文件即可
Intelij IDEA中添加zookeeper插件
1. 点击工具栏的“设置”图标,在弹出的窗口中,选择Plugins插件选项,搜索zookeeper进行相应安装
2. 重启IDEA开发工具后,查看是否安装成功
单机模式
单机安装非常简单,只要获取到 Zookeeper 的压缩包并解压到某个目录如:C:\zookeeper-3.4.5\下,Zookeeper 的启动脚本在 bin 目录下,Windows 下的启动脚本是 zkServer.cmd。
在你执行启动脚本之前,还有几个基本的配置项需要配置一下,Zookeeper 的配置文件在 conf 目录下,这个目录下有 zoo_sample.cfg 和 log4j.properties,你需要做的就是将 zoo_sample.cfg 改名为 zoo.cfg,因为 Zookeeper 在启动时会找这个文件作为默认配置文件。下面详细介绍一下,这个配置文件中各个配置项的意义。
# 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=C:\\zookeeper-3.4.5\\data
dataLogDir=C:\\zookeeper-3.4.5\\log
# the port at which the clients will connect
clientPort=2181
#
# 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
当这些配置项配置好后,你现在就可以启动 Zookeeper 了,启动后要检查 Zookeeper 是否已经在服务,可以通过 netstat –ano 命令查看是否有你配置的 clientPort 端口号在监听服务。
集群模式
Zookeeper 不仅可以单机提供服务,同时也支持多机组成集群来提供服务。实际上 Zookeeper 还支持另外一种伪集群的方式,也就是可以在一台物理机上运行多个 Zookeeper 实例,下面将介绍集群模式的安装和配置。
Zookeeper 的集群模式的安装和配置也不是很复杂,所要做的就是增加几个配置项。集群模式除了上面的三个配置项还要增加下面几个配置项:
initLimit=5
syncLimit=2
server.1=192.168.211.1:2888:3888
server.2=192.168.211.2:2888:3888
Zookeeper 会维护一个具有层次关系的数据结构,它非常类似于一个标准的文件系统,如图 1 所示:
Zookeeper 这种数据结构有如下这些特点:
Zookeeper 作为一个分布式的服务框架,主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储,但是 Zookeeper 并不是用来专门存储数据的,它的作用主要是用来维护和监控你存储的数据的状态变化。通过监控这些数据状态的变化,从而可以达到基于数据的集群管理.
原文:https://www.cnblogs.com/Jeremy2001/p/11788722.html