首页 > 系统服务 > 详细

kafka shell file

时间:2019-05-30 22:06:39      阅读:123      评论:0      收藏:0      [点我收藏+]

1. start kafka and schema_registry

 

#!/bin/sh
export KAFKA_HOME=/home/lenmom/workspace/software/confluent-community-5.1.0-2.11
export KAFKA_PROCESS_ID=$(jps |grep SupportedKafka     |awk {print $1})
export SCHEMA_REGISTRY_PROCESS_ID=$(jps |grep SchemaRegistryMain |awk {print $1})

export reset_data=0


if [ $# = 1 ] && [ "$1"=="reset" ]; then
    reset_data=1
else
    reset_data=0
fi


start_kafka(){
    if [ "$KAFKA_PROCESS_ID" != "" ]; then
        if [ $reset_data -eq 1 ]; then
            echo "kafka process already running, kill it: "+ $KAFKA_PROCESS_ID
            kill -9 $KAFKA_PROCESS_ID

            echo "delete kafka data"
            # clean up kafka data.
            rm -rf $KAFKA_HOME/kafka-logs
            mkdir -p $KAFKA_HOME/kafka-logs

            rm -rf $KAFKA_HOME/logs
            mkdir -p $KAFKA_HOME/logs

            sleep 3
            echo "restart kafka"
            $KAFKA_HOME/bin/kafka-server-start -daemon  $KAFKA_HOME/etc/kafka/server.properties
        fi
    else
        echo "start kafka"
        $KAFKA_HOME/bin/kafka-server-start -daemon  $KAFKA_HOME/etc/kafka/server.properties
    fi
}


start_schema_registry(){
    if [ "$SCHEMA_REGISTRY_PROCESS_ID" != "" ]; then
        if [ $reset_data -eq 1 ]; then
            echo "SchemaRegistry process already running, kill it: "+ $SCHEMA_REGISTRY_PROCESS_ID
            kill -9 $SCHEMA_REGISTRY_PROCESS_ID
            echo "restart confluent schema registry"
            $KAFKA_HOME/bin/schema-registry-start -daemon $KAFKA_HOME/etc/schema-registry/schema-registry.properties
        fi
    else
        echo "start confluent schema registry"
        $KAFKA_HOME/bin/schema-registry-start -daemon $KAFKA_HOME/etc/schema-registry/schema-registry.properties
    fi
}


start_connect_distributed(){
    echo "start confluent kafka connect"
    connect_process_id=$(jps |grep ConnectDistributed |awk {print $1})
    if [ "$connect_process_id" != "" ]; then
        # process already started, if not reset then nothing to do.
        if [ $reset_data -eq 1 ]; then
            # process already started,and use reset, so kill the process.
            echo "kafka-connect process already running, kill it: "+ $connect_process_id
            kill -9  $connect_process_id

            echo "restart kafka-connect"
            $KAFKA_HOME/bin/connect-distributed  $KAFKA_HOME/etc/schema-registry/connect-avro-distributed.properties
        fi
    else
        echo "start kafka-connect"
        $KAFKA_HOME/bin/connect-distributed  $KAFKA_HOME/etc/schema-registry/connect-avro-distributed.properties
    fi
}




start_kafka
sleep 5
start_schema_registry
start_connect_distributed

 

kafka shell file

原文:https://www.cnblogs.com/lenmom/p/10951284.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!