1: 在 /usr/local/bin 目錄下touch xkafka.sh
2 : chmod 777 xkafka.sh
3 :編輯文件
#!/bin/bash #判斷用戶是否傳參 if [ $# -ne 1 ];then echo "無效參數,用法為: $0 {start|stop}" exit fi #獲取用戶輸入的命令 cmd=$1 for (( i=101 ; i<=103 ; i++ )) ;do tput setaf 2 echo ========== hadoop${i} $cmd ================ tput setaf 9 case $cmd in start) ssh hadoop${i} "source /etc/profile ; nohup /opt/module/kafka/bin/kafka-server-start.sh /opt/module/kafka/config/server.properties >> /opt/module/kafka/console-logs/kafka-`date +%F`.log &" #ssh hadoop${i} "source /etc/profile ; /opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/bin/config/server.properties" echo hadoop${i} "服務已啟動" ;; stop) ssh hadoop${i} "source /etc/profile ; /opt/module/kafka/bin/kafka-server-stop.sh" echo hadoop${i} "服務已停止" ;; *) echo "無效參數,用法為: $0 {start|stop}" exit ;; esac done
注意點:
1:/opt/module/kafka/console-logs 需要在kafka 目錄下創建console-logs
2:用notepad++編輯時候。注意notepad++右下角編碼格式為Unix(LF)

