打开及关闭kafka
在$KAFKA_HOME/bin下新建如下脚本文件
start-kafka.sh
#!/bin/bash
BROKERS="cluster1 cluster2 cluster3"
APPHOME="/usr/local/kafka_2.10-0.8.2.1"
APP_NAME="kafka_2.10-0.8.2.1"
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="cluster1 cluster2 cluster3"
APPHOME="/usr/local/kafka_2.10-0.8.2.1"
APP_NAME="kafka_2.10-0.8.2.1"
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
zkServer.sh start
jps可以看到一个叫 QuorumPeerMain 的进程,说明 zookeeper 启动成功。
zkServer.sh status,可以看到三台中有一个是 leader,两个是 follower
(zkServer.sh stop退出)
cd /usr/local/kafka_2.10-0.8.2.1
screen -S kafka (Ctrl+A+D退出),建立虚拟窗口,
在leader中命令胡输入:./start-kafka.sh,即可打开三个虚拟机中的kafka。
在leader中命令胡输入:./stop-kafka.sh,即可关闭三个虚拟机中的kafka。