前言: zookeeper服务于大数据平台,是集群的协调服务,分布式一致性,保证的多个节点的数据一致性
一、安装准备
安装版本: 3.4.10
安装节点:
奇数台节点
只有1台的话数据安全性不高,所以不建议 只装一台,那么这么说的话就是至少3台
底层是java实现的,依赖 jdk ,要确保jdk正常安装
节点id分配: hdp01 1 ;hdp02 2 ;hdp03 3
二、安装步骤
1)上传压缩包
2)解压
tar -xvzf zookeeper-3.4.10.tar.gz
3)配置环境变量
//编辑配置文件
vim /etc/profile
//添加如下内容
export ZK_HOME=/home/hadoop/apps/zookeeper-3.4.10
export PATH=$PATH:$ZK_HOME/bin
//使配置文件生效
source /etc/profile
4)修改zk的配置文件
//cd到zookeeper的配置文件目录下
cd $ZK_HOME/conf
//给文件重命名
mv zoo_sample.cfg zoo.cfg
//编辑配置文件
vim 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. 快照存储位置 id文件 0-255
每一个节点 唯一id 我们手动指定的 一个集群中的id 不可重复的 投票使用的 这个id 必须写在一个文件中 文件名必须myid 快照位置-- myid文件的位置
dataDir=/home/hadoop/data/zookeeperdata
#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
server.1=hadoop01:2888:3888
server.2=hadoop02:2888:3888
server.3=hadoop03:2888:3888
解释:
指定zk集群的节点信息,将节点 id绑定
server.id=主机:2888:3888 一行一个配置代表一个节点
id 每一个节点 分配的唯一id 0-255
2888 选举端口 3888 心跳 端口
5)创建每一个节点的myid文件,将每一个节点的id写入
//吃的到这个目录下,之前zoo.cfg有配置过
dataDir=/home/hadoop/data/zookeeperdata
//创建myid的文件
vim myid
文件内容,只能有id,不能有多余的空格或换行
id 和 zoo.cfg中的配置文件中保持一致
6)远程发送zookeeper安装包
//发送整个安装包到其他节点
scp -r zookeeper-3.4.10 hadoop02:/home/hadoop/apps/
scp -r zookeeper-3.4.10 hadoop03:/home/hadoop/apps/
//发送/etc/profile(配置文件)
sudo scp /etc/profile hadoop02:/etc/
sudo scp /etc/profile hadoop03:/etc/
//使配置文件生效
source /etc/profile
7)启动
启动前需要保证时间同步,保证防火墙关闭
然后使用命令zkServer.sh start在每个节点上执行
启动完成:
8)验证
- jps 查看进程
出现如下就初步验证成功!
4789 QuorumPeerMain
- 使用zkServer.sh status
会在控制台显示节点是follower还是leader
9)如果发生错误
比如错误: is not running
这时候需要检查myid文件的内容和位置 !