zookeeper集群管理脚本shell
cat /usr/local/sbin/manager_zk.sh
内容如下:
#!/bin/bash
#判断用户是否传参
if [ $# -ne 1 ];then
echo "无效参数,用法为: $0 {start|stop|restart|status}"
exit
fi
#获取用户输入的命令
cmd=$1
#定义函数功能
function zookeeperManger(){
case $cmd in
start)
echo "启动服务"
remoteExecution start
;;
stop)
echo "停止服务"
remoteExecution stop
;;
restart)
echo "重启服务"
remoteExecution restart
;;
status)
echo "查看状态"
remoteExecution status
;;
*)
echo "无效参数,用法为: $0 {start|stop|restart|status}"
;;
esac
}
#定义执行的命令
function remoteExecution(){
for (( i=111 ; i<=113 ; i++ )) ; do
tput setaf 2
echo ========== elk${i} zkServer.sh $1 ================
tput setaf 9
ssh elk${i} "source /etc/profile.d/zk.sh; zkServer.sh $1 2>/dev/null"
done
}
#调用函数
zookeeperManger
赋权:
chmod +x /usr/local/sbin/manager_zk.sh
使用:
启动zookeeper集群
[root@elk111 ~]# manager_zk.sh start
![](http://static.51tbox.com/static/2024-08-29/col/36ad99663013f2db77cd80efb9f7ce3a/56580e675b3643bab7bc80147b5d1060.png.jpg)
查看集群状态
[root@elk111 ~]# manager_zk.sh status