一、三台服务器分别如下:
172.28.5.120:zookeeper120.blockchain.hl95.com
172.28.5.124:zookeeper124.blockchain.hl95.com
172.28.5.125:zookeeper125.blockchain.hl95.com
将域名设置配置到三台服务器的/etc/hosts文件下
172.28.5.120 zookeeper120.blockchain.hl95.com 172.28.5.124 zookeeper124.blockchain.hl95.com 172.28.5.125 zookeeper125.blockchain.hl95.com
二、首先需要安装JAVA环境
参考:https://www.cnblogs.com/sky-cheng/p/10564569.html
三、下载zookeeper
三台服务器均下载
[root@redis-01 src]# cd /usr/local/src/ [root@redis-01 src]# wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
四、解压
[root@redis-01 src]# tar -zxvf zookeeper-3.4.14.tar.gz
五、移动到目标目录
[root@redis-01 src]# mv zookeeper-3.4.14/ ../
六、复制conf下的zoo_sample.cfg为zoo.cfg
[root@redis-01 zookeeper-3.4.14]# cp /usr/local/zookeeper-3.4.14/conf/zoo_sample.cfg /usr/local/zookeeper-3.4.14/conf/zoo.cfg
七、新建数据目录
root@redis-01 zookeeper-3.4.14]# mkdir /usr/local/zookeeper-3.4.14/data
八、新建日志目录
[root@redis-01 zookeeper-3.4.14]# mkdir /usr/local/zookeeper-3.4.14/logs
九、编辑zoo.cfg配置文件
设置dataDir为刚才建立的数据目录,设置dataLogDir为新建的日志目录
[root@redis-01 zookeeper-3.4.14]# vim /usr/local/zookeeper-3.4.14/conf/zoo.cfg
dataDir=/usr/local/zookeeper-3.4.14/data/
dataLogDir=/usr/local/zookeeper-3.4.14/logs
设置3个节点配置
server.1=zookeeper120.blockchain.hl95.com:2888:3888
server.2=zookeeper124.blockchain.hl95.com:2888:3888
server.3=zookeeper125.blockchain.hl95.com:2888:3888
最后配置如下:
# 服务器之间或客户端与服务器之间维持心跳的时间间隔 # tickTime以毫秒为单位。 tickTime=2000 # 集群中的follower服务器(F)与leader服务器(L)之间的初始连接心跳数 initLimit=10 # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数 syncLimit=5 # 快照保存目录 # 不要设置为/tmp,该目录重新启动后会被自动清除 dataDir=/usr/local/zookeeper-3.4.14/data/ # 日志保存目录 dataLogDir=/usr/local/zookeeper-3.4.14/logs # 客户端连接端口 clientPort=2181 # 客户端最大连接数。 # 根据自己实际情况设置,默认为60个 # maxClientCnxns=60 # 三个节点配置,格式为: # server.服务编号=服务地址、LF通信端口、选举端口
server.1=zookeeper120.blockchain.hl95.com:2888:3888
server.2=zookeeper124.blockchain.hl95.com:2888:3888
server.3=zookeeper125.blockchain.hl95.com:2888:3888
九、将该配置文件复制到其他节点
[root@redis-01 zookeeper-3.4.14]# scp -P25601 /usr/local/zookeeper-3.4.14/conf/zoo.cfg root@172.28.5.124:/usr/local/zookeeper-3.4.14/conf/ root@172.28.5.124's password: zoo.cfg 100% 1091 54.1KB/s 00:00 [root@redis-01 zookeeper-3.4.14]# scp -P25601 /usr/local/zookeeper-3.4.14/conf/zoo.cfg root@172.28.5.125:/usr/local/zookeeper-3.4.14/conf/ root@172.28.5.125's password: zoo.cfg 100% 1091 52.8KB/s 00:00
十、在/usr/local/zookeeper-3.4.14/data/目录下创建myid文件,文件内容为在zoo.cfg里节点配置的序号
[root@redis-01 zookeeper-3.4.14]# echo 1 > /usr/local/zookeeper-3.4.14/data/myid
[root@redis-03 data]# echo 2 >> /usr/local/zookeeper-3.4.14/data/myid
[root@redis-03 data]# echo 3 >> /usr/local/zookeeper-3.4.14/data/myid
十一、配置环境变量
[root@redis-01 data]# echo "export ZK_HOME=/usr/local/zookeeper-3.4.14" >> /etc/profile [root@redis-01 data]# source /etc/profile [root@redis-01 data]# echo "export PATH=$ZK_HOME/bin:$PATH" >> /etc/profile [root@redis-01 data]# source /etc/profile
十二、分别启动zookeeper
[root@redis-01 zookeeper-3.4.14]# zkServer.sh start ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
三台都启动完毕后,再分别查询状态
[root@redis-01 zookeeper-3.4.14]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg Mode: follower [root@redis-01 zookeeper-3.4.14]#
[root@redis-02 zookeeper-3.4.14]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg Mode: follower
[root@redis-03 zookeeper-3.4.14]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper-3.4.14/bin/../conf/zoo.cfg Mode: leader
2个follower和1个leader