kafka设置shell脚本文件一键启动和关闭

1.kafka的bin目录下kafka-server-stop.sh需要修改

PIDS=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}')
改为
PIDS=$(ps ax | grep -i 'kafka' | grep java | grep -v grep | awk '{print $1}')

2.准备工作

  • 配置了主机名、映射
  • 免密登录
  • 主机同步时间
  • 关闭防火墙
  • 配置环境变量
  • 安装了zookeeper集群

kafka集群设置shell脚本一键启动

  • 首先新建文件start-kafka.sh
touch start-kafka.sh
  • 进入文件:
vi start-kafka.sh
  • 编写脚本
for host in hdp-1 hdp-2 hdp-3
do
        ssh $host "source /etc/profile;/root/apps/kafka_2.12-2.3.0/bin/kafka-server-start.sh /root/apps/kafka_2.12-2.3.0/config/server.properties >/dev/null 2>&1 &"
        echo "$host kafka is running"
done
  • 写好后保存,加上可执行权限
chmod u+x start-kafka.sh
  • 运行
sh start-kafka.sh
[root@hdp-1 ~]# ./start-kafka.sh 
hdp-1 kafka is running
hdp-2 kafka is running
hdp-3 kafka is running
  • jps查看进程

kafka集群设置shell脚本一键关闭

  • 首先新建文件stop-kafka.sh
stop-kafka.sh
  • 进步文件
vi stop-kafka.sh
  • 编写脚本
for host in hdp-1 hdp-2 hdp-3
do
        ssh $host "source /etc/profile;/root/apps/kafka_2.12-2.3.0/bin/kafka-server-stop.sh"
        echo "$host kafka is stopping"
done
  • 写好后保存,加上可执行权限:
chmod u+x stop-kafka.sh
  • 运行:
sh stop-kafka.sh
  • 查询kafka状态
[root@hdp-1 ~]# jps
7073 QuorumPeerMain
8087 Jps
6297 NodeManager
7722 Kafka
5901 DataNode
6189 ResourceManager
5791 NameNode
[root@hdp-1 ~]# ./stop-kafka.sh 
hdp-1 kafka is stopping
hdp-2 kafka is stopping
hdp-3 kafka is stopping

你可能感兴趣的:(kafka设置shell脚本文件一键启动和关闭)