本地模式安装

准备

  1. 安装JDK
  2. 解压tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
  3. 修改名称,方便使用mv apache-zookeeper-3.5.7-bin/ zookeeper-3.5.7

修改配置

  1. cd /opt/module/zookeeper-3.5.7/conf
  2. mv zoo_sample.cfg zoo.cfg
  3. vim zoo.cfg # 修改zoo.cfg的dataDir路径(修改内容如下)
  4. dataDir=/opt/module/zookeeper-3.5.7/zkData
  5. cd /opt/module/zookeeper-3.5.7
  6. mkdir zkData # 创建dataDir文件夹

操作ZK

# 启动ZK
/opt/module/zookeeper-3.5.7/bin/zkServer.sh start

# 查看进程是否启动
jps

# 查看状态
/opt/module/zookeeper-3.5.7/bin/zkServer.sh status

# 退出客户端
[zk: localhost:2181(CONNECTED) 0] quit

# 停止ZK
/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop

配置参数

# 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/module/zookeeper-3.5.7/zkData
# 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
参数 含义
tickTime=2000 通信心跳时间,ZK服务器与客户端心跳时间,单位为毫秒
initLimit=10 LF初始通信时限
Leader和Follower初始连接时能容忍的最多心跳数(tickTime数量)
syncLimit=5 LF同步通信时限
Leader和Follower之间通信时间如果超过syncLimit*tickTime,Leader认为Follower死亡
dataDir=/opt/module/zookeeper-3.5.7/zkData 保存Zookeeper中的数据
默认的tmp目录,容易被linux系统定期删除,一般不用默认的tmp目录
clientPort=2181 客户端连接端口,通常不做修改