Zookeeper集群一键启停脚本

1.创建脚本

vi /usr/bin/zk
#!/bin/bash
if [ $# -lt 1 ]
then
  echo "No Args Input..."
  exit ;
fi

case $1 in
"start"){
        for i in 192.168.58.130 192.168.58.131 192.168.58.132
        do
                echo ---------- zookeeper $i 启动 ------------
				ssh $i "source /etc/profile;/usr/zookeeper/apache-zookeeper-3.9.1-bin/bin/zkServer.sh start"
        done
};;
"stop"){
        for i in 192.168.58.130 192.168.58.131 192.168.58.132
        do
                echo ---------- zookeeper $i 停止 ------------
                ssh $i "source /etc/profile;/usr/zookeeper/apache-zookeeper-3.9.1-bin/bin/zkServer.sh stop"
        done
};;
"status"){
        for i in 192.168.58.130 192.168.58.131 192.168.58.132
        do
                echo ---------- zookeeper $i 状态 ------------
                ssh $i "source /etc/profile;/usr/zookeeper/apache-zookeeper-3.9.1-bin/bin/zkServer.sh status"
        done
};;
*)
  echo "Input Args Error..."
;;
esac

2.添加执行权限

chmod +x /usr/bin/zk

3.对Zookeeper服务脚本添加读取环境变量操作[已在脚本中刷新变量,此步骤可有可无]

#!/usr/bin/env bash之后添加如下内容

source /etc/profile

4.管理

zk start/stop/status
posted @ 2024-01-02 10:34  SpringCore  阅读(162)  评论(0编辑  收藏  举报