kafka集群启停脚本

注意:

  1. 需先在/etc/hosts 文件中配置 IP 映射。
  2. 启动kafka集群前,要先启动zoopkeeper集群。

一、kafka集群启动脚本

#!/bin/bash 
BROKERS="hadoop01 hadoop02 hadoop03"  
KAFKA_HOME="/usr/local/kafka"  
KAFKA_NAME=kafka_2.11-2.0.0
for i in ${BROKERS}
do
    echo "Starting ${KAFKA_NAME} on ${i} "
    ssh ${i} "source /etc/profile; nohup sh ${KAFKA_HOME}/bin/kafka-server-start.sh ${KAFKA_HOME}/config/server.properties > /dev/null 2>&1 &"
    if [[ $? -ne 0 ]]; then
        echo "Starting ${KAFKA_NAME} on ${i} is  ok"
    fi
done
echo All ${KAFKA_NAME} are started
exit 0

二、kafka集群停止脚本

#!/bin/bash 
BROKERS="hadoop01 hadoop02 hadoop03"  
KAFKA_HOME="/usr/local/kafka"  
KAFKA_NAME=kafka_2.11-2.0.0

for i in $BROKERS
do
    echo "Stopping ${KAFKA_NAME} on ${i} "
    ssh ${i} "source /etc/profile;bash ${KAFKA_HOME}/bin/kafka-server-stop.sh"
    if [[ $? -ne 0 ]]; then
        echo "Stopping ${KAFKA_HOME} on ${i} is down"
    fi
done

echo All ${KAFKA_NAME} are stopped
exit 0

三、启停合并脚本

#! /bin/bash

case $2 in
"start"){
        for i in $(cat $1)
        do
                echo " --------启动 $i Kafka-------"
                # 用于KafkaManager监控
                ssh $i "export JMX_PORT=9988 && /usr/local/kafka/bin/kafka-server-start.sh -daemon /opt/local/kafka/config/server.properties "
        done
};;
"stop"){
        for i in $(cat $1)
        do
                echo " --------停止 $i Kafka-------"
                ssh $i "/usr/local/kafka/bin/kafka-server-stop.sh stop"
        done
};;
esac

你可能感兴趣的:(Kafka)