在/usr/local/bin 目录下
[alex@hadoop102 ~]$ cd /usr/local/bin/
[alex@hadoop102 bin]$ sudo touch kafka.sh
[alex@hadoop102 bin]$ sudo chown alex:alex kafka.sh
[alex@hadoop102 bin]$ chmod 755 kafka.sh
[alex@hadoop102 bin]$ vim kafka.sh
#!/bin/bash
user=`whoami`
kafka_home=/opt/module/kafka
case $1 in
start)
for((host=102; host<=104; host++)); do
echo -e "---启动 $user@hadoop$host kafka---"
ssh $user@hadoop$host "source /etc/profile; $kafka_home/bin/kafka-server-start.sh -daemon $kafka_home/config/server.properties"
done
;;
stop)
for((host=102; host<=104; host++)); do
# 睡5秒钟
sleep 5
echo -e "---关闭 $user@hadoop$host kafka---"
ssh $user@hadoop$host "source /etc/profile; nohup $kafka_home/bin/kafka-server-stop.sh $kafka_home/config/server.properties"
done
;;
*)
echo "你启动的姿势不对"
echo " start 启动kafka集群"
echo " stop 停止kafka集群"
;;
esac
网友评论