• 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
  • 相关阅读:
    Kafka事务机制
    RabbitMQ事务机制
    RocketMQ事务消息
    No 'Access-Control-Allow-Origin' header is present on the requested resource.'Ajax跨域访问解决方案
    java + eclipse 工作环境快速配置
    查找.bashrc文件并设置linux快捷命令
    headers参数传值类型
    无需会员将有道云笔记脑图转换xmind
    使用goland调试远程代码
    nginx配置文件使用环境变量
  • 原文地址:https://www.cnblogs.com/chang09/p/16138886.html
Copyright © 2020-2023  润新知