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
相关推荐
三品吉他手会点灯3 小时前
C语言学习笔记 - 20.C编程预备计算机专业知识 - 变量为什么必须的初始化【重点】
c语言·笔记·学习
sakiko_4 小时前
UIKit学习笔记1-创建项目(使用UIKit)、使用组件
笔记·学习
生信碱移4 小时前
PACells:这个方法可以鉴定疾病/预后相关的重要细胞亚群,作者提供的代码流程可以学习起来了,甚至兼容转录组与 ATAC 两种数据类型!
人工智能·学习·算法·机器学习·数据挖掘·数据分析·r语言
千百元5 小时前
zookeeper启不来了
linux·zookeeper·debian
星幻元宇VR6 小时前
VR航空航天科普设备【VR时空直升机】
科技·学习·安全·生活·vr
_李小白6 小时前
【android opencv学习笔记】Day 2: Mat类(图片数据结构体)
android·opencv·学习
harder3217 小时前
RMP模式的创新突破
开发语言·学习·ios·swift·策略模式
程序猿乐锅8 小时前
【Tilas|第三篇】多表SQL语句
数据库·经验分享·笔记·学习·mysql
徐某人..8 小时前
基于i.MX6ULL平台的智能网关系统开发
arm开发·c++·单片机·qt·物联网·学习·arm
AOwhisky9 小时前
Kubernetes 学习笔记:集群管理、命名空间与 Pod 基础
linux·运维·笔记·学习·云原生·kubernetes