启动kafka集群,关闭kafka集群脚本

在$KAFKA_HOME/bin下新建如下脚本文件

start-kafka.sh

#!/bin/bash
BROKERS="mini41 mini42 mini43"
APPHOME="/home/hadoop/apps/kafka"
APP_NAME="kafka_2.10-0.10.1.0" for i in $BROKERS
do
echo "Starting ${APP_NAME} on ${i} "
ssh ${i} "source /etc/profile; nohup sh ${APPHOME}/bin/kafka-server-start.sh ${APPHOME}/config/server.properties > /dev/null 2>&1 &"
if [[ $? -ne 0 ]]; then
echo "Starting ${APP_NAME} on ${i} is ok"
fi
done
echo All $APP_NAME are started
exit 0

  

stop-kafka.sh

#!/bin/bash
BROKERS="mini41 mini42 mini43"
APPHOME="/home/hadoop/apps/kafka"
APP_NAME="kafka_2.10-0.10.1.0" for i in $BROKERS
do
echo "Stopping ${APP_NAME} on ${i} "
ssh ${i} "source /etc/profile;bash ${APPHOME}/bin/kafka-server-stop.sh"
if [[ $? -ne 0 ]]; then
echo "Stopping ${APP_NAME} on ${i} is down"
fi
done echo All $APP_NAME are stopped
exit 0
chmod a+x start-kafka.sh

chmod a+x stop-kafka.sh
05-11 17:47