kafka 服务启停管理脚本 留存备用

B站影视 2025-01-09 04:05 3

摘要:#!/bin/bashWORK_HOME=$(cd "$(dirname "$0")"; pwd)cd $WORK_HOMEumask 077source ~/.bash_profilesource ./common.shINSTALL_DIR=$WORK_H

#!/bin/bash

WORK_HOME=$(cd "$(dirname "$0")"; pwd)

cd $WORK_HOME

umask 077

source ~/.bash_profile

source ./common.sh

INSTALL_DIR=$WORK_HOME/..

KAFKA_INSTALL_DIR=$INSTALL_DIR/kafka

start {

$KAFKA_INSTALL_DIR/bin/kafka-server-start.sh -daemon $KAFKA_INSTALL_DIR/config/server.properties

}

stop {

$KAFKA_INSTALL_DIR/bin/kafka-server-stop.sh $KAFKA_INSTALL_DIR/config/server.properties

}

status {

if [[ -n "$(ps -ef | grep 'kafka/bin' | grep 'kafkaServer' | grep -v grep)" ]]; then

zk_addr=`sed '/^zookeeper.connect=/!d;s/.*=//' $KAFKA_INSTALL_DIR/config/server.properties`

check_service --service-name kafka --shell="$KAFKA_INSTALL_DIR/bin/kafka-topics.sh --list --zookeeper $zk_addr"

echo "kafka service available!"

else

echo "kafka not running!"

exit 3

fi

}

case "$1" in

'start')

start

;;

'stop')

stop

;;

'restart')

stop

sleep 3

start

;;

'status')

status

;;

*)

echo "Usage: $0 {start|stop|restart|status}"

exit 1

esac

来源:小羊看科技

相关推荐