Centos7 搭建Zookeeper3.4.14--轻易上手,
下载页面
开发手册(英文版)
命令下载
命令:# wget https://apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
下载
解压
命令:# tar -zxvf zookeeper-3.4.14.tar.gz

把zookeeper移到/usr/local下
命令: # mv zookeeper-3.4.14 /usr/local

进入zookeeper,创建data(数据)和logs(日志)存储文件夹
命令:# mkdir data logs

创建zoo.cfg
命令:# cd conf/
命令:# cp zoo_sample.cfg zoo.cfg

修改zoo.cfg
命令:vim zoo.cfg
-
配置中的参数说明
-
tickTime:the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.
■ 中文:ZooKeeper使用的基本时间单位(毫秒)。 它用于做心跳,并且最小会话(session)超时将是tickTime的两倍
-
tickTime:the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.
-
initLimit: initLimitis timeouts ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader.
■ 中文:用于限制ZooKeeper服务器必须连接到Leader服务器的时间长度,有必要可以设置在一点点的时间长度。
-
initLimit: initLimitis timeouts ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader.
-
syncLimit:The entry syncLimit limits how far out of date a server can be from a leader.
■ 中文:服务器与领导者之间过时的距离。可以通过心跳检测机制,来检测机器的存活状态。如果Leader发出心跳包在syncLimit之后,还没有从Folloer那里收到响应,那么就认为这个F已经不在线了.所以这个参数不移设置过大。
-
syncLimit:The entry syncLimit limits how far out of date a server can be from a leader.
-
dataDir:the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.
■ 中文:配置存储内存数据库快照的位置以及数据库更新的事务日志。
-
dataDir:the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.
-
clientPort:the port to listen for client connections
■ 中文:侦听客户端连接的端口
-
clientPort:the port to listen for client connections
- 修改如下:
dataDir=/usr/local/zookeeper-3.4.14/data
dataLogDir=/usr/local/zookeeper-3.4.14/logs
server.1=192.168.10.108:2888:3888
** 补充说明
server.X=hostip/hostName:port1:port2 的条目列出了组成ZooKeeper服务的服务器。服务器启动时,它通过在数据目录中查找文件myid来知道它是哪台服务器 ,port1端口用于Follower和Leader之间的数据同步和其它通信,port2端口用于Leader选举过程中投票通信。

创建myid,注明上面zoo.cfg中的server.x中的x
命令: # cd ../data
命令:# vim myid

配置zookeeper的环境变量
- 添加环境变量
命令: # cd ~
命令: # vim .base_profile
#zookeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.14
export PATH=$ZOOKEEPER_HOME/bin:$PATH
- 生效环境变量
命令: # source .base_profile
开放2181、2888、3888端口
命令: # firewall-cmd --zone=public --add-port=2181/tcp --permanent
命令: # firewall-cmd --zone=public --add-port=2888/tcp --permanent
命令: # firewall-cmd --zone=public --add-port=3888/tcp --permanent
命令: # firewall-cmd --reload

启动zookeeper
命令:# cd /usr/local/zookeeper-3.4.14/bin
命令:# cd ./zkServer.sh start
补充停止命令:# ./zkServer.sh stop

设置开机启动
- 新建一个名为zookeeper文件
命令: # cd /etc/rc.d/init.d
命令: touch zookeeper

- 编辑zookeeper文件,添加如下内容
命令: # vim zookeeper
#!/bin/bash
#chkconfig:2345 10 90
#description: service zookeeper
export JAVA_HOME=/home/jdk/jdk1.8.0_231
export ZOO_LOG_DIR=/usr/local/zookeeper-3.4.14/logs
ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.14
su root ${ZOOKEEPER_HOME}/bin/zkServer.sh "$1"

- 给/etc/rc.d/init.d/zookeeper文件授权,且把zookeeper这个脚本添加到开机启动项
命令:# chmod +x /etc/rc.d/init.d/zookeeper
命令:# chkconfig --add zookeeper
命令:# chkconfig --list

- 使用reboot(重启服务器命令)验证