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

前置环境

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

安装jdk

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

安装zookeeper

  • 当前在192.168.2.201上操作
  • 解压zookeeper安装包
  • 在安装目录下新建zkData目录
powershell 复制代码
mkdir zkData
  • 修改修改conf/zoo.cfg文件
powershell 复制代码
 cp zoo_sample.cfg ./zoo.cfg
  • 修改zoo.cfg中的DataDir值 改为zkData所在的目录
powershell 复制代码
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,
powershell 复制代码
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文件
powershell 复制代码
[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
powershell 复制代码
echo "1" >> myid
  • 配置环境变量
powershell 复制代码
vim /etc/profile

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

powershell 复制代码
export ZOOKEEPER_HOME=/opt/software/zookeeper-3.4.6
export PATH=$PATH:$ZOOKEEPER_HOME/bin
  • 刷新配置文件
powershell 复制代码
source /etc/profile
  • 复制整个zookeeper安装目录到其余两台服务器,最好在相同目录
powershell 复制代码
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
powershell 复制代码
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
powershell 复制代码
[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

powershell 复制代码
[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

powershell 复制代码
[root@aiops bin]# ./zkServer.sh status
JMX enabled by default
Using config: /opt/software/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
相关推荐
望森FPGA21 分钟前
HDLBits中文版,标准参考答案 |2.5 More Verilog Features | 更多Verilog 要点
学习·fpga开发
l1x1n031 分钟前
DOS 命令学习笔记
笔记·学习·web安全
道爷我悟了1 小时前
Vue入门-指令学习-v-on
javascript·vue.js·学习
人工智能技术咨询.2 小时前
张雪峰谈人工智能技术应用专业的就业前景!
人工智能·学习·计算机视觉·语言模型
s_little_monster2 小时前
【QT】QT入门
数据库·c++·经验分享·笔记·qt·学习·mfc
alfiy2 小时前
Elasticsearch学习笔记(六)使用集群令牌将新加点加入集群
笔记·学习·elasticsearch
北极无雪2 小时前
Spring源码学习:SpringMVC(4)DispatcherServlet请求入口分析
java·开发语言·后端·学习·spring
望森FPGA3 小时前
HDLBits中文版,标准参考答案 |3.1.1 Basic Gates | 基本门电路
学习·fpga开发
JavaGPT3 小时前
prometheus学习笔记之PromQL
笔记·学习·prometheus
纪伊路上盛名在3 小时前
如何初步部署自己的服务器,达到生信分析的及格线
linux·运维·服务器·python·学习·r语言·github