1. 程式人生 > >啟動kafka集群,關閉kafka集群腳本

啟動kafka集群,關閉kafka集群腳本

cto spa onf highlight sel pin conf span start

啟動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

啟動kafka集群,關閉kafka集群腳本