说明:本脚本基于SSH服务器免密登录,如集群未配置SSH,参照:《SSH安装配置》 。
一、启动脚本:start-kafka-cluster.sh
#!/bin/bash
brokers="server1 server2 server3"
KAFKA_HOME="/usr/local/services/kafka/kafka_2.11-2.3.0"
KAFKA_NAME="kafka_2.11-2.3.0"
echo "INFO : Begin to start kafka cluster ..."
for broker in $brokers
do
echo "INFO : Starting ${KAFKA_NAME} 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 !"
为脚本添加执行权限:
chmod a+x start-kafka-cluster.sh
二、停止脚本:stop-kafka-cluster.sh
#!/bin/bash
brokers="server1 server2 server3"
KAFKA_HOME="/usr/local/services/kafka/kafka_2.11-2.3.0"
KAFKA_NAME="kafka_2.11-2.3.0"
echo "INFO : Begin to stop kafka cluster ..."
for broker in $brokers
do
echo "INFO : Shut down ${KAFKA_NAME} on ${broker} ..."
ssh ${broker} "source /etc/profile;bash ${KAFKA_HOME}/bin/kafka-server-stop.sh"
if [[ $? -ne 0 ]]; then
echo "INFO : Shut down ${KAFKA_NAME} on ${broker} is down"
fi
done
echo "INFO : kafka cluster shut down completed!"
为脚本添加执行权限:
chmod a+x stop-kafka-cluster.sh
参考资料
参考书籍:Kafka入门与实践
出处: https://www.cnblogs.com/DeepInThought
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。