目录
下载地址:https://www.apache.org/dyn/closer.cgi/zookeeper/
官方文档:https://zookeeper.apache.org/doc/r3.4.5/
这里一共安装三台机器,分别是 hadoop001、hadoop002、hadoop003
1、解压文件
cd /usr/local/hadoop
tar zxpf zookeeper-3.4.5.tar.gz -C /usr/local/hadoop
2、创建软连接
ln -s zookeeper-3.4.5 zookeeper
1、配置zoo.cfg
vim /usr/local/hadoop/zookeeper/conf/zoo.cfg
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=/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目录,需要自己手动创建
mkdir /usr/local/hadoop/zookeeper/data
mkdir /usr/local/hadoop/zookeeper/logs
给每台zk节点配置myid,每个节点myid的值和zoo.cfg中的server.N一致
echo "1" > /usr/local/hadoop/zookeeper/data/myid
echo "2" > /usr/local/hadoop/zookeeper/data/myid
echo "3" > /usr/local/hadoop/zookeeper/data/myid
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
vim /etc/profile
export ZOO_HOME=/usr/local/hadoop/zookeeper
export PATH=$PATH:$ZOO_HOME/bin
zkServer.sh start
zkServer.sh status
这里第二个节点选举成了leader
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有