多臺kafka同時啟動shell指令碼

鴨梨山大哎發表於2020-12-30

假設有三臺機器,分別為mypc01,mypc02,mypc03

#!/bin/bash

show(){
	echo -e "\033[0;37;44m"$1"\033[00m"
}

case $1 in 

start)
for i in mypc01 mypc02 mypc03
do
show "--------------- $i ---------------" 
ssh $i> /dev/null 2>&1 << eof
/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
exit
eof
echo "    $i kafka已啟動  "
done
;;

stop)
for i in mypc01 mypc02 mypc03
do
show "--------------- $i ---------------"
ssh $i '/usr/local/kafka/bin/kafka-server-stop.sh'
echo "   $i kafka已經關閉 "
done
;;
esac

相關文章