Kafka集群启动脚本(start-kafka)
cd /usr/local/bin
sudo vi start-kafka
脚本内容如下:
#!/bin/bash
KAFKA_HOME=/home/vagrant/modules/kafka_2.11-0.11.0.3
echo "start kafka-------------------------------------------------"
for i in bigdata-node1 bigdata-node2 bigdata-node3
do
ssh $i "source /etc/profile;${KAFKA_HOME}/bin/kafka-server-start.sh ${KAFKA_HOME}/config/server.properties >/dev/null 2>&1 &"
done
sleep 10s
jpsx
exit 0
设置脚本执行权限:
sudo chmod +x start-kafka
sudo chown vagrant:vagrant start-kafka
Kafka集群停止脚本(stop-kafka)
cd /usr/local/bin
sudo vi stop-kafka
脚本内容如下:
#!/bin/bash
KAFKA_HOME=/home/vagrant/modules/kafka_2.11-0.11.0.3
echo "stop kafka"
for i in bigdata-node1 bigdata-node2 bigdata-node3
do
ssh $i "source /etc/profile;${KAFKA_HOME}/bin/kafka-server-stop.sh ${KAFKA_HOME}/config/server.properties &"
done
sleep 10s
jpsx
exit 0
设置脚本执行权限:
sudo chmod +x stop-kafka
sudo chown vagrant:vagrant stop-kafka
分发(选做):
# 使用root账户分发至其他节点
sudo scp -r /usr/local/bin/*-kafka root@bigdata-node2:/usr/local/bin/
sudo scp -r /usr/local/bin/*-kafka root@bigdata-node3:/usr/local/bin/