官方下载地址:https://zookeeper.apache.org/
版本:apache-zookeeper-3.7.1-bin.tar.gz
见:Hadoop集群搭建
使用远程工具拷贝安装包到Linux指定路径
/opt/software
将安装包解压到/opt/module中
[li@hadoop102 software]$ tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C /opt/module/
[li@hadoop102 module]$ mv apache-zookeeper-3.7.1-bin/ zookeeper-3.7.1
(1)将/opt/module/zookeeper-3.7.1/conf 这个路径下的 zoo_sample.cfg 修改为 zoo.cfg;
[li@hadoop102 conf]$ mv zoo_sample.cfg zoo.cfg
(2)打开 zoo.cfg 文件,修改 dataDir 路径:
[li@hadoop102 zookeeper-3.7.1]$ vim zoo.cfg
修改如下内容:
dataDir=/opt/module/zookeeper-3.7.1/zkData
配置参数解读:
1)tickTime = 2000:通信心跳时间,Zookeeper服务器与客户端心跳时间,单位毫秒
2)initLimit = 10:LF初始通信时限。Leader和Follower初始连接时能容忍的最多心跳数(tickTime的数量)
3)syncLimit = 5:LF同步通信时限
4)dataDir:保存Zookeeper中的数据 注意:默认的tmp目录,容易被Linux系统定期删除,所以一般不用默认的tmp目录。
5)clientPort = 2181:客户端连接端口,通常不做修改。
(3)在/opt/module/zookeeper-3.7.1/这个目录上创建 zkData 文件夹
[li@hadoop102 zookeeper-3.7.1]$ mkdir zkData
(1)启动 Zookeeper
[li@hadoop102 zookeeper-3.7.1]$ bin/zkServer.sh start
(2)查看进程是否启动
[li@hadoop102 zookeeper-3.7.1]$ jps
4020 Jps
4001 QuorumPeerMain
(3)查看状态
[li@hadoop102 zookeeper-3.7.1]$ bin/zkServer.sh stutas
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.1/bin/../conf/zoo.cfg
Usage: /opt/module/zookeeper-3.7.1/bin/zkServer.sh [--config <conf-dir>] {start|start-foreground|stop|version|restart|status|print-cmd}
(4)启动客户端
[li@hadoop102 zookeeper-3.7.1]$ bin/zkCli.sh
(5)退出客户端:
[zk: localhost:2181(CONNECTING) 3] quit
(6)停止 Zookeeper
[li@hadoop102 zookeeper-3.7.1]$ bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.7.1/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
(1)集群规划
在 hadoop102、hadoop103 和 hadoop104 三个节点上都部署 Zookeeper。
(2)解压安装
[li@hadoop102 software]$ tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz -C /opt/module/
[li@hadoop102 software]$ mv apache-zookeeper-3.7.1-bin/ zookeeper-3.7.1
(3)配置服务器编号
[li@hadoop102 software]$ mkdir zkDate
[li@hadoop102 software]$ vim myid
在文件中添加与 server 对应的编号(注意:上下不要有空行,左右不要有空格)
2
[li@hadoop102 software]$ xsync zookeeper-3.7.1
并分别在 hadoop103、hadoop104 上修改 myid 文件中内容为 3、4
(4)配置zoo.cfg文件
[li@hadoop102 software]$ mv zoo_sample.cfg zoo.cfg
[li@hadoop102 software]$ vim zoo.cfg
# 增加如下配置
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888
配置参数解读:
server.A=B:C:D
[li@hadoop102 conf]$ xsync zoo.cfg
(1)分别启动Zookeeper
[li@hadoop102 zookeeper-3.7.1]$ bin/zkServer.sh start
[li@hadoop103 zookeeper-3.7.1]$ bin/zkServer.sh start
[li@hadoop104 zookeeper-3.7.1]$ bin/zkServer.sh start
(2) 查看状态
[li@hadoop102 zookeeper-3.7.1]$ bin/zkServer.sh status
[li@hadoop103 zookeeper-3.7.1]$ bin/zkServer.sh status
[li@hadoop104 zookeeper-3.7.1]$ bin/zkServer.sh status
(1)在 hadoop102 的/home/li/bin 目录下创建脚本
[li@hadoop102 bin]$ vim zk.sh
脚本中编写如下内容:
#!/bin/bash
case $1 in
"start")
for i in hadoop102 hadoop103 hadoop104
do
echo ---------- zookeeper $i 启动 ------------
ssh $i "/opt/module/zookeeper-3.7.1/bin/zkServer.sh start"
done
;;
"stop")
for i in hadoop102 hadoop103 hadoop104
do
echo ---------- zookeeper $i 停止 ------------
ssh $i "/opt/module/zookeeper-3.7.1/bin/zkServer.sh stop"
done
;;
"status")
for i in hadoop102 hadoop103 hadoop104
do
echo ---------- zookeeper $i 状态 ------------
ssh $i "/opt/module/zookeeper-3.7.1/bin/zkServer.sh status"
done
;;
esac
(2)增加脚本执行权限
[li@hadoop102 bin]$ chmod u+x zk.sh
(3)Zookeeper 集群启动脚本
[li@hadoop102 bin]$ zk.sh start
(4)Zookeeper 集群停止脚本
[li@hadoop102 bin]$ zk.sh stop
在my_env.sh中配置Zookeeper环境变量,添加如下内容:
export ZK_HOME=/opt/module/zookeeper-3.7.1
export PATH=$PATH:$ZK_HOME/bin
将更改过的文件同步到hadoop103,hadoop104中
[li@hadoop102 profile.d]$ xsync my_env.sh