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