2019年5月20日发行的3.5.5是3.5分支的第一个稳定版本。此版本被认为是3.4稳定分支的后续版本,可以用于生产。基于3.4它包含以下新功能
使用root账号登录系统并创建用户后完成如下配置
cd /usr/local/bin
mkdir zookeeper
cd zookeeper
curl -O https://archive.apache.org/dist/zookeeper/zookeeper-3.5.5-bin/apache-zookeeper-3.5.5-bin.tar.gz
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz
ln -s apache-zookeeper-3.5.5-bin zookeeper
修改bin/zkServer.sh,添加变量ZOO_LOG_DIR,改变量体现在zoo.cfg配置文件中
ZOO_LOG_DIR="$($GREP "^[[:space:]]*zooLogDir" "$ZOOCFG" | sed -e 's/.*=//')"

在 /etc/profile 中配置
export ZK_HOME=/usr/local/bin/zookeeper/zookeeper
export PATH=$PATH:$ZK_HOME/bin
切换回创建的账号并做如下配置
cd /home/zookeeper
mkdir stand_alone
cd stand_alone
mkdir data
mkdir datalog
mkdir conf
mkdir logger
mkdir zoolog
从 zookeeper 的安装路径下的 conf 中复制一份配置文件到新建的 conf 目录中
cp /usr/local/bin/zookeeper/zookeeper/conf/zoo_sample.cfg stand-alone/conf/zoo.cfg
cp /usr/local/bin/zookeeper/zookeeper/conf/log4j.properties stand-alone/conf/.
修改 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=/home/zookeeper/stand-alone/data
dataLogDir=/home/zookeeper/stand-alone/datalog
# 修改zkServer.sh文件中配置的路径
zooLogDir=/home/zookeeper/stand-alone/zoo
# 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
修改 log4j.properties 中的相关配置为
zookeeper.log.dir=/home/zookeeper/stand-alone/logger
zookeeper.root.logger=INFO, ROLLINGFILE
log4j.appender.ROLLINGFILE=org.apache.log4j.DailyRollingFileAppender
配置参数的含义:
关于日志配置
尝试如下指令启动
zkServer.sh
输出日志信息如下
Using config: /usr/local/bin/zookeeper/zookeeper/bin/../conf/zoo.cfg
grep: /usr/local/bin/zookeeper/zookeeper/bin/../conf/zoo.cfg: No such file or directory
grep: /usr/local/bin/zookeeper/zookeeper/bin/../conf/zoo.cfg: No such file or directory
mkdir: cannot create directory ‘’: No such file or directory
mkdir: cannot create directory ‘/usr/local/bin/zookeeper/zookeeper/bin/../logs’: Permission denied
Usage: /usr/local/bin/zookeeper/zookeeper/bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|restart|status|print-cmd}
按照日志提示做如下启动
zkServer.sh --config /home/zookeeper/stand-alone/conf start
启动
zkServer.sh start
停止
zkServer.sh stop
重启
zkServer.sh restart
查看状态
zkServer.sh status
或者
zkServer.sh --config /home/zookeeper/stand-alone/conf status
查看 zookeeper 输出信息
tail -f /home/zookeeper/stand-alone/zoo/zookeeper.out
客户端连接
zkCli.sh -server 127.0.0.1:2181

