使用脚本来管理Kafka的服务
Posted Mr.zhou_Zxy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用脚本来管理Kafka的服务相关的知识,希望对你有一定的参考价值。
开发脚本来管理Kafka的服务
start-kafka.sh 用于开启zookeeper,kafka服务,由于开启前后顺序不能变,所以这里应手动先开启zookeeper,再开启Kafka
start-producer.sh 用于开启Kafka的生产端
start-consumer.sh 用于开启Kafka的消费端
- start-kafka.sh
#!/bin/bash
# filename:start-kafka.sh
# autho:zxy
# date:2021-07-19
# KAFKA的安装路径
KAFKA_HOME=/data/apps/kafka_2.11-2.4.1
# 接受参数
CMD=$1
## 帮助函数
usage() {
echo "usage:"
echo "start-kafka.sh zookeeper/kafka/stopz/stopk"
echo "description:"
echo " zookeeper:start zookeeperService"
echo " kafka:start kafkaService"
echo " stopz:stop zookeeperService"
echo " stopk:stop kafkaService"
exit 0
}
if [ ${CMD} == "zookeeper" ];then
# 启动kafka的zookeeper服务
sh $KAFKA_HOME/bin/zookeeper-server-start.sh -daemon $KAFKA_HOME/config/zookeeper.properties
elif [ ${CMD} == "kafka" ];then
# 启动kafka的Kafka服务
sh $KAFKA_HOME/bin/kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties
elif [ ${CMD} == "stopz" ];then
sh $KAFKA_HOME/bin/zookeeper-server-stop.sh -daemon $KAFKA_HOME/config/zookeeper.properties
elif [ ${CMD} == "stopk" ];then
sh $KAFKA_HOME/bin/kafka-server-stop.sh -daemon $KAFKA_HOME/config/server.properties
ps -aux|grep kafka|gawk '{print $2}'|xargs -n1 kill -9
else
usage
fi
- start-producer.sh
#!/bin/bash
# filename:start-producer.sh
# autho:zxy
# date:2021-07-19
# KAFKA的安装路径
KAFKA_HOME=/data/apps/kafka_2.11-2.4.1
#接收参数
CMD=$1
##帮助函数
usage(){
echo "usage:"
echo "sh start-producer.sh topicName"
}
sh $KAFKA_HOME/bin/kafka-console-producer.sh --topic ${CMD} --broker-list hadoop:9092
- start-consumer.sh
#!/bin/bash
# filename:start-consumer.sh
# autho:zxy
# date:2021-07-19
# KAFKA的安装路径
KAFKA_HOME=/data/apps/kafka_2.11-2.4.1
#接收参数
CMD=$1
##帮助函数
usage(){
echo "usage:"
echo "sh start-consumer.sh topicName"
}
sh $KAFKA_HOME/bin/kafka-console-consumer.sh --topic ${CMD} --bootstrap-server hadoop:9092
以上是关于使用脚本来管理Kafka的服务的主要内容,如果未能解决你的问题,请参考以下文章