Kafka并没有提供同时启动集群中所有节点的执行脚本,在生产中一个Kafka集群往往会有多个节点,若逐个节点启动稍微有些麻烦,在这里自定义一个脚本用来启动或者停止集群中所有节点。
启动:
#!/bin/bash
brokers="hadoop3 hadoop4 hadoop5"
KAFKA_HOME="/opt/kafka/kafka_2.11-1.0.0"
echo "INFO:Begin to start kafka cluster..."
for broker in $brokers
do
echo "INFO:Start kafka on ${broker} ..."
ssh $broker -C "source /etc/profile; sh ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties"
if [ $? -eq 0 ]; then
echo "INFO:[${broker}] Start successfully "
fi
done
echo "INFO:Kafka cluster starts successfully!"
停止:
#!/bin/bash
brokers="hadoop3 hadoop4 hadoop5"
KAFKA_HOME="/opt/kafka/kafka_2.11-1.0.0"
echo "INFO:Begin to stop kafka cluster..."
for broker in $brokers
do
echo "INFO:Stop kafka on ${broker} ..."
ssh $broker -C "source /etc/profile; sh ${KAFKA_HOME}/bin/kafka-server-stop.sh"
if [ $? -eq 0 ]; then
echo "INFO:[${broker}] Stop successfully "
fi
done
echo "INFO:Kafka cluster stop successfully!"