• 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
  • 相关阅读:
    CentOS 6.2安装Darwin Streaming Server
    流媒体技术笔记(协议相关)
    流媒体技术笔记(视频编码相关)
    CentOS6.2下编译mpeg4ip
    用popen函数操作其它程序的输入和输出
    给centos6.2安装yum源
    启动新进程(fork和exec系列函数实现)
    扩展Asterisk1.8.7的Dialplan Applications
    源码安装ffmpeg(带libx264)
    扩展Asterisk1.8.7的AMI接口
  • 原文地址:https://www.cnblogs.com/shanhua-fu/p/11955733.html
Copyright © 2020-2023  润新知