须知:
zookeeper的节点数量不适宜太多,也不适宜太少。必须是奇数个
本文准备的zookeeper集群的节点个数有3个分别是hadoop02, hadoop03, hadoop04
zookeeper集群不用依赖于任何东西,除了JDK。
版本的选择:zookeeper-3.4.5到10.tar.gz 都可以。
安装步骤:(本文以zookeeper-3.4.10.tar.gz为例)
1、获取安装包包。并且上传到服务器
使用SecureCRTPortable软件(按住ALT+P)拖拽上传到服务器
2、解压到对应的安装目录
tar -zxvf zookeeper-3.4.10.tar.gz -C apps/
3、修改配置文件
进入配置文件所在目录
cd /home/hadoop/apps/zookeeper-3.4.10/conf
更改zoo_sample.cfg文件名字为zoo.cfg,使用下面命令
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.
dataDir=/home/hadoop/data/zkdata
# 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_maintenan
ce
#
# 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.2=hadoop02:2888:3888
server.3=hadoop03:2888:3888server.4=hadoop04:2888:3888
server.5=hadoop05:2888:3888:observer //如果有四台机器,想配置观察者就写
4、分发文件给其他节点
cd /home/hadoop/apps
scp -r zookeeper-3.4.10/ hadoop03:$PWD
scp -r zookeeper-3.4.10/ hadoop04:$PWD
scp -r zookeeper-3.4.10/ hadoop05:$PWD //如果有四台机器,想配置观察者就写
5、每个节点分别创建自己的myid
使用cd /home/hadoop/data/zkdata 命令在此目录下创建myid文件
myid文件中的内容就是这个节点的serverid, 除此之外,什么都不要放
[hadoop@hadoop03 zkdata]$ cat myid
3
6、配置环境变量
cd ~
vim .bashrc
追加下面两行
export ZOOKEEPER_HOME=/home/hadoop/apps/zookeeper-3.4.10
export PATH=$PATH:$ZOOKEEPER_HOME/bin
执行刷新命令 source .bashrc
分发环境变量
scp -r .bashrc hadoop03:$PWD
scp -r .bashrc hadoop04:$PWD
scp -r .bashrc hadoop05:$PWD //如果有四台机器,想配置观察者就写
7、启动zookeeper
命令:
启动:zkServer.sh start
停止:zkServer.sh stop
查看状态:zkServer.sh status
8、查看是否启动zookeeper成功
在02,03,04,05集群上启动zookeeper,使用下面的命令
zkServer.sh start
先输入jps查看是否有zookeeper进程
[hadoop@hadoop04 ~]$ jps
2213 Jps
2203 QuorumPeerMain
再输入 zkServer.sh status 显示如下
[hadoop@hadoop03 zkdata]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apps/zookeeper-3.4.10/bin/../conf/zoo.cfgMode: follower
[hadoop@hadoop02 conf]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apps/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader出现以上两点即是安装成功!