From 0305cdfd7f621fa633b0b903c1f53ec3e7f1a8af Mon Sep 17 00:00:00 2001 From: Vyacheslav Boyko Date: Fri, 5 Jul 2019 12:02:20 +0300 Subject: [PATCH] scripts --- describe-group.sh | 15 +++++++++++++++ get-kafka-ip.sh | 3 +++ get-topic-content.sh | 18 ++++++++++++++++++ list-groups.sh | 11 +++++++++++ start-kafka.sh | 6 ++++++ start-zookeeper.sh | 5 +++++ stop-kafka.sh | 27 +++++++++++++++++++++++++++ stop-zookeeper.sh | 27 +++++++++++++++++++++++++++ which-kafka.sh | 1 + 9 files changed, 113 insertions(+) create mode 100644 describe-group.sh create mode 100644 get-kafka-ip.sh create mode 100644 get-topic-content.sh create mode 100644 list-groups.sh create mode 100644 start-kafka.sh create mode 100644 start-zookeeper.sh create mode 100644 stop-kafka.sh create mode 100644 stop-zookeeper.sh create mode 100644 which-kafka.sh diff --git a/describe-group.sh b/describe-group.sh new file mode 100644 index 0000000..2bd5e03 --- /dev/null +++ b/describe-group.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +KAFKA_IP=`. get-kafka-ip.sh` + +if [[ -z "$KAFKA_IP" ]]; then + echo "Could not detect Kafka IP from config/properties" + exit +fi + +if [[ -z "$1" ]]; then + echo "No group is provided" + exit +fi + +bin/kafka-consumer-groups.sh --bootstrap-server $KAFKA_IP --group $1 --describe \ No newline at end of file diff --git a/get-kafka-ip.sh b/get-kafka-ip.sh new file mode 100644 index 0000000..19914a9 --- /dev/null +++ b/get-kafka-ip.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cat config/server.properties | grep '^listeners' | sed -e 's/\/\///; s/PLAINTEXT//; s/listeners=//;' | awk -F ":" '{if (NF==3) {print $2":"$3} else {print $1":"$2} }' diff --git a/get-topic-content.sh b/get-topic-content.sh new file mode 100644 index 0000000..fcb527c --- /dev/null +++ b/get-topic-content.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +KAFKA_IP=`. get-kafka-ip.sh` + +if [[ -z "$KAFKA_IP" ]]; then + echo "Could not detect Kafka IP from config/properties" + exit +fi + +if [[ -z "$1" ]]; then + echo "No topic is provided"; + exit; +fi + +echo "If you see nothing for about 5-10 seconds - the topic content is empty." +echo "Press Ctrl^C to exit" + +bin/kafka-console-consumer.sh --bootstrap-server $KAFKA_IP --topic $1 --from-beginning \ No newline at end of file diff --git a/list-groups.sh b/list-groups.sh new file mode 100644 index 0000000..b2477a2 --- /dev/null +++ b/list-groups.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +KAFKA_IP=`. get-kafka-ip.sh` + +if [[ -z "$KAFKA_IP" ]]; then + echo "Could not detect Kafka IP from config/properties" + exit +fi + + +bin/kafka-consumer-groups.sh --bootstrap-server $KAFKA_IP --list \ No newline at end of file diff --git a/start-kafka.sh b/start-kafka.sh new file mode 100644 index 0000000..9cd917c --- /dev/null +++ b/start-kafka.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +KAFKA_LOG=`pwd`/logs/kafka.log +echo $KAFKA_LOG +nohup bin/kafka-server-start.sh config/server.properties > $KAFKA_LOG & + diff --git a/start-zookeeper.sh b/start-zookeeper.sh new file mode 100644 index 0000000..e156853 --- /dev/null +++ b/start-zookeeper.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +ZOO_LOGS=`pwd`/logs/zookeeper.log +nohup bin/zookeeper-server-start.sh config/zookeeper.properties > $ZOO_LOGS & + diff --git a/stop-kafka.sh b/stop-kafka.sh new file mode 100644 index 0000000..d99f591 --- /dev/null +++ b/stop-kafka.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +SIGNAL=${SIGNAL:-TERM} +#PIDS=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}') + +#boyko_vn: +PIDS=$(ps ax | grep java | grep kafka | grep -v zookeeper | grep -v grep | awk '{ print $1}') + +if [ -z "$PIDS" ]; then + echo "No kafka server to stop" + exit 1 +else + kill -s $SIGNAL $PIDS +fi diff --git a/stop-zookeeper.sh b/stop-zookeeper.sh new file mode 100644 index 0000000..c5abc57 --- /dev/null +++ b/stop-zookeeper.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +SIGNAL=${SIGNAL:-TERM} +#PIDS=$(ps ax | grep java | grep -i QuorumPeerMain | grep -v grep | awk '{print $1}') + +#boyko_vn +PIDS=$(ps ax | grep java | grep kafka | grep zookeeper | grep -v grep | awk '{ print $1}') + +if [ -z "$PIDS" ]; then + echo "No zookeeper server to stop" + exit 1 +else + kill -s $SIGNAL $PIDS +fi diff --git a/which-kafka.sh b/which-kafka.sh new file mode 100644 index 0000000..65ada88 --- /dev/null +++ b/which-kafka.sh @@ -0,0 +1 @@ +ps ax | grep kafka | grep -v zookeeper | grep -v grep