在$KAFKA_HOME/bin下新建如下脚本文件
start-kafka.sh
#!/bin/bash
BROKERS="cluster1 cluster2 cluster3"
APPHOME="/usr/local/kafka_2.10-0.8.2.1"
APP_NAME="kafka_2.10-0.8.2.1"
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="cluster1 cluster2 cluster3"
APPHOME="/usr/local/kafka_2.10-0.8.2.1"
APP_NAME="kafka_2.10-0.8.2.1"
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
若kafka无法关闭
cd $KAFKA_HOME/bin
vi kafka-server-stop.sh
把PIDS=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}')这行代码修改为
PIDS=$(jps -lm | grep -i 'kafka.Kafka' | awk '{print $1}')
sh kafka-server-stop.sh ,该命令关闭KAFKA
|