1)在hadoop102的/home/mars/bin目录下创建脚本
[mars@hadoop102 bin]$ vim zk.sh
在脚本中编写如下内容
#!/bin/bash
case $1 in
"start"){
for i in hadoop102 hadoop103 hadoop104
do
echo "------------- $i -------------"
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh start"
done
};;
"stop"){
for i in hadoop102 hadoop103 hadoop104
do
echo "------------- $i -------------"
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop"
done
};;
"status"){
for i in hadoop102 hadoop103 hadoop104
do
echo "------------- $i -------------"
ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh status"
done
};;
esac
2)增加脚本执行权限
[mars@hadoop102 bin]$ chmod 777 zk.sh
3)Zookeeper集群启动脚本
[mars@hadoop102 module]$ zk.sh start
4)Zookeeper集群停止脚本
[mars@hadoop102 module]$ zk.sh stop