目录
查看服务架构图-服务分布、版本信息
一:安装前准备
1:zookeeper安装包选择--官网下载
2:zookeeper3.5.7安装包--百度网盘
二:安装与常用配置
2.1:下载解压zk安装包
2.2:配置环境变量
2.3:配置修改
2.4:分发zookeeper到node02, node03节点
2.5:修改node02, node03节点的myid
三:Zookeeper基础操作
3.1:服务管理
查看服务架构图-服务分布、版本信息
系统环境:centos7
Java环境:Java8
免密与基础配置参考:Apache Hadoop生态部署-3台设置的免密登录,xsync分发脚本,jpsall脚本
单机安装参考上篇:Apache Hadoop生态部署-zookeeper单机安装
一:安装前准备
1:zookeeper安装包选择--官网下载
Index of /dist/zookeeper
2:zookeeper3.5.7安装包--百度网盘
链接:https://pan.baidu.com/s/1aodm4GON2fMfwMutZUy3mA?pwd=yyds
提取码:yyds
二:安装与常用配置
2.1:下载解压zk安装包
[root@node01 ~]# cd /tmp
[root@node01 tmp]# wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.7/apache-zookeeper-3.5.7-bin.tar.gz
或者从百度网盘下载,上传到/tmp下
解压到/usr/local/
[root@node01 tmp]# sudo tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /usr/local/
[root@node01 tmp]# sudo mv /usr/local/apache-zookeeper-3.5.7-bin /usr/local/zookeeper-3.5.7
2.2:配置环境变量
sudo vim /etc/profile.d/zookeeper.sh
插入内容
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.5.7
export PATH=$PATH:$ZOOKEEPER_HOME/bin
执行source /etc/profile使环境变量生效
2.3:配置修改
(1)备份配置文件zoo_sample.cfg
[root@node01 tmp]# cd /usr/local/zookeeper-3.5.7/conf
[root@node01 conf]# sudo cp zoo_sample.cfg zoo.cfg
(2)修改zoo.cfg配置
创建数据存放目录
[root@node01 conf]# mkdir -p /usr/local/zookeeper-3.5.7/data
[root@node01 conf]# sudo vim /usr/local/zookeeper-3.5.7/conf/zoo.cfg
# 修改 dataDir 路径
dataDir=/usr/local/zookeeper-3.5.7/data
# 在最后添加上以下内容,其中2888是通讯端口,3888是选举端口
server.1=node01:2888:3888
server.2=node02:2888:3888
server.3=node03:2888:3888
(3)配置myid
[root@node01 conf]# vim $ZOOKEEPER_HOME/data/myid
1
# 注意LISTEN 2181端口,2888端口,3888端口,8080端口(注意冲突)
2.4:分发zookeeper到node02, node03节点
scp -r /usr/local/zookeeper-3.5.7 root@node02:/usr/local/
scp -r /usr/local/zookeeper-3.5.7 root@node03:/usr/local/
或者使用自编写的同步脚本
~/xsync /usr/local/zookeeper-3.5.7
2.5:修改node02, node03节点的myid
[root@node02 conf]# vim $ZOOKEEPER_HOME/data/myid
2
[root@node03 conf]# vim $ZOOKEEPER_HOME/data/myid
3
#写上配置文件服务器对应server的值,必须与配置文件编号一致
node01中myid填1
node02中myid填2
node03中myid填3
三:Zookeeper基础操作
3.1:服务管理
编写脚本操作Zookeeper
vim $ZOOKEEPER_HOME/bin/myzookeeper.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
for i in node01 node02 node03
do
echo ---------- zookeeper $i 启动 ------------
ssh $i "/usr/local/zookeeper-3.5.7/bin/zkServer.sh start"
done
;;
"stop")
for i in node01 node02 node03
do
echo ---------- zookeeper $i 关闭 ------------
ssh $i "/usr/local/zookeeper-3.5.7/bin/zkServer.sh stop"
done
;;
"status")
for i in node01 node02 node03
do
echo ---------- zookeeper $i 状态 ------------
ssh $i "/usr/local/zookeeper-3.5.7/bin/zkServer.sh status"
done
;;
*)
echo "Input Args Error..."
;;
esac
添加可执行权限
chmod +x $ZOOKEEPER_HOME/bin/myzookeeper.sh
# 启动 Zookeeper
$ myzookeeper.sh start
# 查看状态
$ myzookeeper.sh status
# 停止 Zookeeper
$ myzookeeper.sh stop