1. 创建 zk 脚本文件
touch zk
2. 编写脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input...[start,stop,restart,status]"
exit ;
fi
case $1 in
"start"){
echo ------------- zookeeper 集群启动 -------------
for i in test01 test02 test03
do
echo ------------- ZK $i 启动 -------------
ssh $i "/opt/zk/zookeeper-3.7.1-bin/bin/zkServer.sh start"
done
}
;;
"stop"){
echo ------------- zookeeper 集群停止 -------------
for i in test01 test02 test03
do
echo ------------- ZK $i 停止 -------------
ssh $i "/opt/zk/zookeeper-3.7.1-bin/bin/zkServer.sh stop"
done
}
;;
"restart"){
echo ------------- zookeeper 集群重启 -------------
for i in test01 test02 test03
do
echo ------------- ZK $i 重启 -------------
ssh $i "/opt/zk/zookeeper-3.7.1-bin/bin/zkServer.sh restart"
done
}
;;
"status"){
echo ------------- zookeeper 集群状态 -------------
for i in test01 test02 test03
do
echo ------------- ZK $i 状态 -------------
ssh $i "/opt/zk/zookeeper-3.7.1-bin/bin/zkServer.sh status"
done
}
;;
*)
echo "Input Args Error...[start,stop,restart,status]"
;;
esac
3. 给脚本赋予权限
chmod 777 zk