kafka集羣每次啓動都須要登陸多臺服務器操做,比較麻煩,安裝了一個批量管理工具pssh,配置了ssh免祕鑰登陸,寫了一個簡單的shell腳本方便平常的批量啓動、關閉操做。shell
[root@kafka1 ~]# cat /usr/local/kafka/bin/kafka-daemons.sh #!/bin/bash #kafka start stop #date 2020.03.07 ########################### #[root@kafka1 ~]# cat /root/khost.txt #192.168.180.21 #192.168.180.22 #192.168.180.23 #三臺主機配置ssh免祕鑰 function zookeeper_start(){ pssh -h khost.txt -i zkServer.sh start sleep 5 pssh -h khost.txt -i jps } function zookeeper_stop(){ pssh -h khost.txt -i zkServer.sh stop sleep 5 pssh -h khost.txt -i jps } function zookeeper_status(){ pssh -h khost.txt -i zkServer.sh status } function kafka_start(){ pssh -h khost.txt -i kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties sleep 5 pssh -h khost.txt -i jps } function kafka_stop(){ pssh -h khost.txt -i kafka-server-stop.sh sleep 5 pssh -h khost.txt -i jps } function kafka_status(){ pssh -h khost.txt -i jps } echo -e "[1] start zookeeper [2] stop zookeeper [3] status zookeeper [4] start kafka [5] stop kafka [6] status kafka " read -p "please input install servers[1]|[2]|[3]|[4]|[5]|[6]|:" server_s case $server_s in 1) read -p "Please confirm your input [yes]:" confirm case $confirm in yes|YES|YEs|yEs|yeE) zookeeper_start ;; *) exit esac ;; 2) read -p "Please confirm your input [yes]:" confirm case $confirm in yes|YES|YEs|yEs|yeE) zookeeper_stop ;; *) exit esac ;; 3) read -p "Please confirm your input [yes]:" confirm case $confirm in yes|YES|YEs|yEs|yeE) zookeeper_status ;; *) exit esac ;; 4) read -p "Please confirm your input [yes]:" confirm case $confirm in yes|YES|YEs|yEs|yeE) kafka_start ;; *) exit esac ;; 5) read -p "Please confirm your input [yes]:" confirm case $confirm in yes|YES|YEs|yEs|yeE) kafka_stop ;; *) exit esac ;; 6) read -p "Please confirm your input [yes]:" confirm case $confirm in yes|YES|YEs|yEs|yeE) kafka_status ;; *) exit esac ;; *) echo -e "\033[32;1m please input start or stop servers[1]|[2]|[3]|[4]|[5]|[6]!!!\033[0m" exit esac
添加腳本的執行權限bash
[root@kafka1 ~]# chmod 755 /usr/local/kafka/bin/kafka-daemons.sh
啓動zookeeper服務器
啓動kafkassh