Kafka集群启动脚本(start-kafka)

  1. cd /usr/local/bin
  2. sudo vi start-kafka

脚本内容如下:

  1. #!/bin/bash
  2. KAFKA_HOME=/home/vagrant/modules/kafka_2.11-0.11.0.3
  3. echo "start kafka-------------------------------------------------"
  4. for i in bigdata-node1 bigdata-node2 bigdata-node3
  5. do
  6. ssh $i "source /etc/profile;${KAFKA_HOME}/bin/kafka-server-start.sh ${KAFKA_HOME}/config/server.properties >/dev/null 2>&1 &"
  7. done
  8. sleep 10s
  9. jpsx
  10. exit 0

设置脚本执行权限:

  1. sudo chmod +x start-kafka
  2. sudo chown vagrant:vagrant start-kafka

Kafka集群停止脚本(stop-kafka)

  1. cd /usr/local/bin
  2. sudo vi stop-kafka

脚本内容如下:

  1. #!/bin/bash
  2. KAFKA_HOME=/home/vagrant/modules/kafka_2.11-0.11.0.3
  3. echo "stop kafka"
  4. for i in bigdata-node1 bigdata-node2 bigdata-node3
  5. do
  6. ssh $i "source /etc/profile;${KAFKA_HOME}/bin/kafka-server-stop.sh ${KAFKA_HOME}/config/server.properties &"
  7. done
  8. sleep 10s
  9. jpsx
  10. exit 0

设置脚本执行权限:

  1. sudo chmod +x stop-kafka
  2. sudo chown vagrant:vagrant stop-kafka

分发(选做):

  1. # 使用root账户分发至其他节点
  2. sudo scp -r /usr/local/bin/*-kafka root@bigdata-node2:/usr/local/bin/
  3. sudo scp -r /usr/local/bin/*-kafka root@bigdata-node3:/usr/local/bin/