【README】 由于集群有多台机器,启动kafka ,查看其状态,都需要每台机器去执行命令, 可以写个脚本基于ssh免密登录批量执行;
【1】启动kafak (kk.sh)
#!/bin/bash
case $1 in
"start"){
for i in centos201 centos202 centos203
do
echo "**********$i kafka start **********"
ssh $i "/opt/module/kafka-0.11/bin/kafka-server-start.sh -daemon /opt/module/kafka-0.11/config/server.properties"
done
};;
"stop"){
for i in centos201 centos202 centos203
do
echo "**********$i kafka stop**********"
ssh $i "/opt/module/kafka-0.11/bin/kafka-server-stop.sh /opt/module/kafka-0.11/config/server.properties"
done
};;
esac
【2】执行jps(xcall.sh )
#!/bin/bash
params=$@
for i in centos201 centos202 centos203
do
echo "********** $i $params start **********"
ssh $i "$params"
done
【3】 以上脚本,只需要将其放置在 kafka_home/bin/ 目录下,然后 chmod +x xcall.sh 即可执行 ;
【4】执行效果
[root@centos201 bin]# kk.sh stop
**********centos201 kafka stop**********
No kafka server to stop
**********centos202 kafka stop**********
No kafka server to stop
**********centos203 kafka stop**********
No kafka server to stop
[root@centos201 bin]#
[root@centos201 bin]# kk.sh start
**********centos201 kafka start **********
**********centos202 kafka start **********
**********centos203 kafka start **********
[root@centos201 bin]#
[root@centos201 bin]#
[root@centos201 ~]# xcall.sh jps
********** centos201 jps start **********
5763 Jps
1692 QuorumPeerMain
5116 Kafka
********** centos202 jps start **********
4784 Kafka
5076 Jps
3370 QuorumPeerMain
********** centos203 jps start **********
4185 Jps
1676 QuorumPeerMain
4110 Kafka