大数据高可用技术之zookeeper3.4.5安装配置

2022-05-10 19:09:15 浏览数 (1)

目录

一、安装准备

二、zookeeper安装

三、zookeeper配置

四、配置环境变量

五、启动zookeeper

一、安装准备

下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/

官方文档:https://zookeeper.apache.org/doc/r3.4.5/

这里一共安装三台机器,分别是 hadoop001、hadoop002、hadoop003

二、zookeeper安装

1、解压文件

代码语言:javascript复制
cd /usr/local/hadoop
代码语言:javascript复制
tar zxpf zookeeper-3.4.5.tar.gz -C /usr/local/hadoop

 2、创建软连接 

代码语言:javascript复制
ln -s zookeeper-3.4.5 zookeeper

三、zookeeper配置

1、配置zoo.cfg

代码语言:javascript复制
vim /usr/local/hadoop/zookeeper/conf/zoo.cfg

zoo.cfg配置内容如下

代码语言:javascript复制
# 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=/usr/local/hadoop/zookeeper/data
dataLogDir=/usr/local/hadoop/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
#
# 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=hadoop001:2888:3888
server.2=hadoop002:2888:3888
server.3=hadoop003:2888:3888

配置文件说明

tickTime:心跳时间,默认2000毫秒即2秒 initLimit:初始化时follower和leader之间的最多心跳数 syncLimit:follower和leader之间请求响应的最多心跳数 dataDir:存放myid、版本信息和数据持久化的目录 dataLogDir:zookeeper存放日志的目录 clientPort:zookeeper监听的端口,默认2181 server.N=ip:2888:3888:server节点配置,N表示第N台zk的节点

2、配置myid

zookeeper根据配置文件自动创建dataDir、dataLogDir目录,需要自己手动创建

代码语言:javascript复制
mkdir /usr/local/hadoop/zookeeper/data
mkdir /usr/local/hadoop/zookeeper/logs

给每台zk节点配置myid,每个节点myid的值和zoo.cfg中的server.N一致

代码语言:javascript复制
echo "1" > /usr/local/hadoop/zookeeper/data/myid
代码语言:javascript复制
echo "2" > /usr/local/hadoop/zookeeper/data/myid
代码语言:javascript复制
echo "3" > /usr/local/hadoop/zookeeper/data/myid
代码语言:javascript复制
cat /usr/local/hadoop/zookeeper/data/myid

zookeeper的选举机制和myid密切关联,myid值大的相对更容易成为leader,具体这里就不详细讨论了。

如不配置myid,会在 zookeeper.out 文件中抛出错误

[myid:] - ERROR [main:QuorumPeerMain@85] - Invalid config, exiting abnormally org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /usr/local/hadoop/zookeeper/bin/../conf/zoo.cfg

四、配置环境变量

代码语言:javascript复制
vim /etc/profile
代码语言:javascript复制
export ZOO_HOME=/usr/local/hadoop/zookeeper
export PATH=$PATH:$ZOO_HOME/bin

五、启动zookeeper

代码语言:javascript复制
zkServer.sh start
代码语言:javascript复制
zkServer.sh status

 这里第二个节点选举成了leader 

0 人点赞