• kafka 批量添加topic 副本数


    shell 脚本:

    1)列出只有一个副本的topic,保存到一个文件中:

    [root@hdp05 src]# cat fush.sh 
    #!/bin/bash 
    #
    
    
    topics=`/usr/hdp/2.6.4.0-91/kafka/bin/kafka-topics.sh --zookeeper 192.168.50.101:2181 -list`
    
    for i in $topics;do
      replicsNum=`/usr/hdp/2.6.4.0-91/kafka/bin/kafka-topics.sh --zookeeper 192.168.50.101:2181 -describe --topic $i|grep ReplicationFactor|awk '{print $3}'|awk -F: '{print $2}'`
      if [ $replicsNum == 1 ];then
         echo  $i >> /usr/local/src/topic.txt
      fi
    done

    2)执行扩容副本操作

    [root@hdp05 src]# vim exce.sh 
    #!/bin/bash
    #
    
    #topics=`cat /usr/local/src/topic.txt`
    topics=`cat /usr/local/src/topic01.txt`
    for i in $topics;do
    
       leader=`/usr/hdp/2.6.4.0-91/kafka/bin/kafka-topics.sh --zookeeper 192.168.50.101:2181 -describe --topic $i|grep Leader|awk '{prin
    t $6}'`
       leader0=`echo $leader  |awk '{print $1}'`
       leader1=`echo $leader  |awk '{print $2}'`
       echo $leader0 > /usr/local/src/leadering.txt
       echo $leader1 >> /usr/local/src/leadering.txt
    
       leadercha=`grep -vxFf /usr/local/src/leadering.txt /usr/local/src/leaderNum.txt`
       echo $leadercha
       echo $i
        echo '{"version":1,"partitions":[{"topic":"'$i'","partition":0,"replicas":['$leader0','$leadercha']},{"topic":"'$i'","partition"
    :1,"replicas":['$leader1','$leadercha']}]}' > /usr/local/src/topic-reassignment.json
    
       /usr/hdp/2.6.4.0-91/kafka/bin/kafka-reassign-partitions.sh --zookeeper 192.168.50.101:2181 --reassignment-json-file /usr/local/sr
    c/topic-reassignment.json --execute
    
       sleep 5
    done
  • 相关阅读:
    12款JavaScript表单插件
    10个强大的Javascript表单验证插件推荐
    memcached服务器搭建
    15 个非常吸引人的 jQuery 弹窗插件
    37个超级棒的 jQuery菜单插件
    nginx添加ssl证书认证
    27个jQuery网页拖放操作的插件
    memcached集群负载均衡
    python基础2
    ADO SQL数据库
  • 原文地址:https://www.cnblogs.com/shanhua-fu/p/11955733.html
Copyright © 2020-2023  润新知