Xftp上传zookeeper压缩包到hadoop102

解压安装

在hadoop102解压Zookeeper安装包到/opt/module/目录下

tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/

把安装目录文件名改短些

mv apache-zookeeper-3.5.7-bin/ zookeeper-3.5.7

配置服务器编号

mkdir zkData
cd zkData
vim myid

添加:

2

配置zoo.cfg文件

把/opt/module/zookeeper-3.5.7/conf目录下的zoo_sample.cfg改为zoo.cfg

mv zoo_sample.cfg zoo.cfg

编写zoo.cfg

#修改数据存储路径
dataDir=/opt/module/zookeeper-3.5.7/zkData
#增加内容
#######################cluster##########################
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888

直接从hadoop102上把配置好的zookeeper安装目录分发到集群

cd /opt/module
xsync zookeeper-3.5.7

在hadoop103、hadoop104分别修改myid内容为3、4

编写集群启停脚本zk

在hadoop102下的/home/atguigu/bin下编写该脚本

vim zk

#!/bin/bash

case $1 in
"start"){
	for i in hadoop102 hadoop103 hadoop104
	do
        echo ---------- zookeeper $i 启动 ------------
		ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh start"
	done
};;
"stop"){
	for i in hadoop102 hadoop103 hadoop104
	do
        echo ---------- zookeeper $i 停止 ------------    
		ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop"
	done
};;
"status"){
	for i in hadoop102 hadoop103 hadoop104
	do
        echo ---------- zookeeper $i 状态 ------------    
		ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh status"
	done
};;
esac

增加脚本执行权限

chmod 744 zk

脚本群起zookeeper

zk start

脚本群关zookeeper

zk stop