1 #!/bin/sh 2 comm=/opt/module/kafka/bin/kafka-server-start.sh 3 commd=/opt/module/kafka/bin/kafka-server-stop.sh 4 topic=/opt/module/kafka/bin/kafka-topics.sh 5 producer=/opt/module/kafka/bin/kafka-console-producer.sh 6 consumer=/opt/module/kafka/bin/kafka-console-consumer.sh 7 conf=/opt/module/kafka/config/server.properties 8 function warning(){ 9 echo "----- 无效参数个数,用法为: ----- " 10 echo "----- $0 {start|stop|list} -----" 11 echo "----- $0 {create} {topic} {partions} {replication-factor} -----" 12 echo "----- $0 {delete} {topic} -----" 13 echo "----- $0 {producer} {topic} -----" 14 echo "----- $0 {consumer} {topic} -----" 15 } 16 if [ $# -gt 4 ]; 17 then 18 warning 19 exit 20 fi 21 case $1 in 22 start){ 23 echo "-------------------启动 kafka 集群---------------" 24 for((i=106 ; i<=108 ; i++ )) 25 do 26 ssh hadoop${i} $comm "-daemon" $conf 27 echo "------hadoop$i:--start kafka服务--done-----" 28 done 29 };; 30 stop){ 31 echo "-------------------关闭 kafka 集群---------------" 32 for((i=106 ; i<=108 ; i++ )) 33 do 34 ssh hadoop${i} $commd 35 echo "------hadoop$i:--stop kafka服务--done------" 36 done 37 };; 38 create){ 39 echo "--------------create topic $2---------------" 40 $topic "--create" "--topic" $2 "--zookeeper" "hadoop106" "--partitions" $3 "--replication-factor" $4 41 echo "------topic create done------" 42 };; 43 delete){ 44 echo "--------------delete topic $2---------------" 45 $topic "--delete" "--topic" $2 "--zookeeper" "hadoop106" 46 echo "------topic delete done------" 47 };; 48 producer){ 49 echo "--------------create producer to topic $2---------------" 50 $producer "--broker-list" "hadoop106:9092" "hadoop107:9092" "hadoop108:9092" "--topic" $2 51 echo "------producer create done------" 52 };; 53 consumer){ 54 echo "--------------create consumer from topic $2---------------" 55 $consumer "--bootstrap-server" "hadoop106:9092" "hadoop107:9092" "hadoop108:9092" "--from-beginning" "--topic" $2 56 echo "------consumer create done------" 57 };; 58 list){ 59 echo "--------------list topic ---------------" 60 $topic "--list" "--zookeeper" "hadoop106" 61 echo "------done------" 62 };; 63 64 *){ 65 warning 66 exit 67 };; 68 esac
粘:
#!/bin/sh comm=/opt/module/kafka/bin/kafka-server-start.sh commd=/opt/module/kafka/bin/kafka-server-stop.sh topic=/opt/module/kafka/bin/kafka-topics.sh producer=/opt/module/kafka/bin/kafka-console-producer.sh consumer=/opt/module/kafka/bin/kafka-console-consumer.sh conf=/opt/module/kafka/config/server.properties function warning(){ echo "----- 无效参数个数,用法为: ----- " echo "----- $0 {start|stop|list} -----" echo "----- $0 {create} {topic} {partions} {replication-factor} -----" echo "----- $0 {delete} {topic} -----" echo "----- $0 {producer} {topic} -----" echo "----- $0 {consumer} {topic} -----" } if [ $# -gt 4 ]; then warning exit fi case $1 in start){ echo "-------------------启动 kafka 集群---------------" for((i=106 ; i<=108 ; i++ )) do ssh hadoop${i} $comm "-daemon" $conf echo "------hadoop$i:--start kafka服务--done-----" done };; stop){ echo "-------------------关闭 kafka 集群---------------" for((i=106 ; i<=108 ; i++ )) do ssh hadoop${i} $commd echo "------hadoop$i:--stop kafka服务--done------" done };; create){ echo "--------------create topic $2---------------" $topic "--create" "--topic" $2 "--zookeeper" "hadoop106" "--partitions" $3 "--replication-factor" $4 echo "------topic create done------" };; delete){ echo "--------------delete topic $2---------------" $topic "--delete" "--topic" $2 "--zookeeper" "hadoop106" echo "------topic delete done------" };; producer){ echo "--------------create producer to topic $2---------------" $producer "--broker-list" "hadoop106:9092" "hadoop107:9092" "hadoop108:9092" "--topic" $2 echo "------producer create done------" };; consumer){ echo "--------------create consumer from topic $2---------------" $consumer "--bootstrap-server" "hadoop106:9092" "hadoop107:9092" "hadoop108:9092" "--from-beginning" "--topic" $2 echo "------consumer create done------" };; list){ echo "--------------list topic ---------------" $topic "--list" "--zookeeper" "hadoop106" echo "------done------" };; *){ warning exit };; esac
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/244992.html