zookeeper学习(二) 集群模式安装

前置环境

  • 三台centos7服务器
192.168.2.201
192.168.2.202
192.168.2.150
  • 三台服务器都需要安装jdk1.8以上
  • zookeeper安装包

安装jdk

在单机模式已经描述过,这里略过,有需要可以去看单机模式中的这部分,注意的是三台服务器都需要安装

安装zookeeper

  • 当前在192.168.2.201上操作
  • 解压zookeeper安装包
  • 在安装目录下新建zkData目录
mkdir zkData
  • 修改修改conf/zoo.cfg文件
 cp zoo_sample.cfg ./zoo.cfg
  • 修改zoo.cfg中的DataDir值 改为zkData所在的目录
dataDir=/opt/software/zookeeper-3.4.6/zkData
  • 在zoo.cfg目录中添加集群信息,server.x 中的x是代表这台主机的序号,如server.1代表这台zookeeper的序号是1,server.2代表这台zookeeper的序号是2,server.3代表这台zookeeper的序号是3,
server.1=192.168.2.201:2888:3888
server.2=192.168.2.202:2888:3888   
server.3=192.168.2.150:2888:3888
# 自动触动清楚任务时间间隔,小时为单位,默认为0,表示不自动清除
autopurge.purgeInterval=2
# 保存的快照数量,之外的会被清除
autopurge.snapRetainCount=5
  • 最终的zoo.cfg文件
[root@aiops-release conf]# cat 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=/tmp/zookeeper
# 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

dataDir=/opt/software/zookeeper-3.4.6/zkData
clientPort=2181 
server.1=192.168.2.201:2888:3888
server.2=192.168.2.202:2888:3888   
server.3=192.168.2.150:2888:3888
autopurge.purgeInterval=2
autopurge.snapRetainCount=5
  • 在zkData目录下创建myid文件,并写入1,对应之前zoo.cfg中的server.1中的序号1
echo "1" >> myid
  • 配置环境变量
vim /etc/profile

在文件底部添加zookeeper的安装目录

export ZOOKEEPER_HOME=/opt/software/zookeeper-3.4.6
export PATH=$PATH:$ZOOKEEPER_HOME/bin
  • 刷新配置文件
source /etc/profile
  • 复制整个zookeeper安装目录到其余两台服务器,最好在相同目录
scp -r zookeeper-3.4.6/ root@192.168.2.202:/目录/z/zookeeper-3.4.6/
scp -r zookeeper-3.4.6/ root@192.168.2.150:/目录/z/zookeeper-3.4.6/
  • 修改192.168.2.202 和192.168.2.150中myid对应的值,分别为2和3
192.168.2.202
echo "2" >> myid
192.168.2.150
echo "3" >> myid
  • 配置192.168.2.202 和192.168.2.150的环境变量,并刷新,与上面配置192.168.2.201时的步骤一致
  • 最终三台服务器都应该装有jdk1.8,以及三台服务器中的zoo.cfg文件是一致的,zkData中的myid分别为1,2,3,与zoo.cfg中的配置的服务器编号对应

启动

  • 依次启动三台服务器的zookeeper
  • 查看三台服务器的状态
    192.168.2.150
[root@aiops-test bin]# ./zkServer.sh status
JMX enabled by default
Using config: /opt/software/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader

192.168.2.202

[root@aiops-release bin]# ./zkServer.sh status
JMX enabled by default
Using config: /opt/software/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower

192.168.2.201

[root@aiops bin]# ./zkServer.sh status
JMX enabled by default
Using config: /opt/software/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值