zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    css3简易实现图标动画由小到大逐个显现
    下拉图标呼吸效果制作
    设置图片从页面四周渐入效果的锚点方法
    关于导航宽度高度自适应的小栗子
    Odd-e CSD Course Day 5
    Odd-e CSD Course Day 2
    Odd-e CSD Course Day 3
    Odd-e CSD Course Day 1
    Odd-e CSD Course Day 4
    [心得] SQL Server Partition(表分區) 資料分佈探討
  • 原文地址:https://www.cnblogs.com/shanhua-fu/p/11955733.html
Copyright © 2011-2022 走看看