1. 序
ZooKeeper的工作模式有三种:单机模式、集群模式、伪集群模式
2. 下载
2.1 zookeeper
可去ZooKeeper官网下载ZooKeeper的稳定版:zookeeper官网
2.2 jdk
由于Zookeeper使用Java编写,因此运行ZooKeeper之前需安装Java环境——配置JDK,且JDK版本应大于等于1.6
3 ZooKeeper配置
解压后,可得到如下目录:
3.1 cfg文件配置
进入conf文件夹,打开zoo_sample.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=/tmp/zookeeper
# 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
在该文件夹下新建“zoo.cfg”文件(ZooKeeper启动时会找名为“zoo.cfg”文件并将其作为默认配置文件),并将zoo_sample.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:/zookeeper-3.4.9/data
# 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
至此,ZooKeeper在Windows中的安装配置完毕。
4 启动ZooKeeper
进入bin文件夹,可得如下目录:
4.1 启动ZooKeeper服务器端
在Windows中双击“zkServer.cmd”;
4.2 启动ZooKeeper客户端
在Windows中双击“zkCli.cmd”;
注意:
上面两个步骤不能颠倒,否则ZooKeeper客户端不能成功启动。
5 添加系统变量
ZOOKEEPER_HOME:D:/zookeeper-3.4.9
Path: 在现有的值后面添加 ";%ZOOKEEPER_HOME%\bin;"