shells/kafka.sh
2022/4/14 7:16:39
本文主要是介绍shells/kafka.sh,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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
这篇关于shells/kafka.sh的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-27[开源] 一款轻量级的kafka可视化管理平台
- 2024-10-23Kafka消息丢失资料详解:初学者必看教程
- 2024-10-23Kafka资料新手入门指南
- 2024-10-23Kafka解耦入门:新手必读教程
- 2024-10-23Kafka入门:新手必读的简单教程
- 2024-10-23Kafka入门:新手必读的简单教程
- 2024-10-23Kafka消息丢失入门:新手必读指南
- 2024-10-23Kafka消息队列入门:新手必看的简单教程
- 2024-10-23Kafka消息队列入门与应用
- 2024-10-23Kafka重复消费入门:轻松掌握Kafka重复消息处理技巧