下载
从官网选择一个binary版本进行下载
https://zookeeper.apache.org/releases.html
安装
将下载的tar包解压至节点的指定目录即可
tar zxvf zookeeper-3.4.14.tar.gz -C /opt
配置
ZooKeeper home目录的conf下有一个配置样例文件 zoo_sample.cfg。ZooKeeper 会以zoo.cfg文件的配置信息启动进程,我们可以使用这个样例文件创建配置文件 zoo.cfg
cd /opt/zookeeper-3.4.14/
cp conf/zoo_sample.cfg conf/zoo.cfg
vim zoo.cfg
这里主要调整了两个地方,一是 dataDir 目录设置到了一个非tmp的目录下,生产环境可以将其放至数据盘所挂载的目录下。这里同时也指定了日志的目录。二是添加了server的信息,server.*=hostname:2888:3888,也可以使用ip地址。
# 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=/opt/dfs/zk/data
dataLogDir=/opt/dfs/zk/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
server.0=node1:2888:3888
server.1=node2:2888:3888
server.2=node3:2888:3888
将配置好的ZooKeeper分发至每一台节点,如果已完成解压到所有节点则分发 zoo.cfg文件至每一个节点。
保证每一个节点有ZooKeeper存放数据的目录
mkdir -p /opt/zk/data
mkdir -p /opt/zk/log
在data目录创建myid文件,写入节点对应的id。这个id就是配置文件中 server.{id}={hostname}:2888:3888 {id}所对应的数字。
touch myid
echo "0" > myid
启动
每个节点home目录下启动ZooKeeper
bin/zkServer.sh start
Reference
https://zookeeper.apache.org/doc/r3.4.14/zookeeperStarted.html