kafka修改分区和副本数

kafka修改分区和副本数

查看现在副本分配情况

../bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --describe  --topic test1

Topic:test1       PartitionCount:3        ReplicationFactor:2     Configs:
        Topic: test1      Partition: 0    Leader: 2       Replicas: 2,4   Isr: 2,4
        Topic: test1      Partition: 1    Leader: 3       Replicas: 3,5   Isr: 3,5
        Topic: test1      Partition: 2    Leader: 4       Replicas: 4,1   Isr: 4,1

topic 分区扩容

./kafka-topics.sh --zookeeper 127.0.0.1:2181 -alter --partitions 4 --topic test1

修改备份数量

这个文件自己创建 格式按照下面的格式就可以了

根据topic的分区情况自行修改 partitions-topic.json 文件配置

{
        "partitions":
                [
                {
                        "topic": "test1",
                        "partition": 0,
                        "replicas": [1,2]
                },
                {
                        "topic": "test1",
                        "partition": 1,
                        "replicas": [0,3]
                },
                {
                        "topic": "test1",
                        "partition": 2,
                        "replicas": [4,5]
                }
                ],
        "version":1
}

执行副本搬迁

 ../bin/kafka-reassign-partitions.sh --zookeeper 127.0.0.1:2181 --reassignment-json-file partitions-topic.json --execute  

查看迁移情况:

../bin/kafka-reassign-partitions.sh --zookeeper 127.0.0.1:2181 --reassignment-json-file partitions-topic.json --verify

Status of partition reassignment:
Reassignment of partition [mx_prd_nginx_access,0] is still in progress
Reassignment of partition [mx_prd_nginx_access,1] completed successfully
Reassignment of partition [mx_prd_nginx_access,2] is still in progress

注释

kafka-reassign-partitions.sh工具来重新分布分区。该工具有三种使用模式:

  1. generate模式,给定需要重新分配的Topic,自动生成reassign plan(并不执行)
  2. execute模式,根据指定的reassign plan重新分配Partition
  3. verify模式,验证重新分配Partition是否成功

我的 github 博客 https://sukbeta.github.io/kafka-Modify-Partitions-and-ReplicationFactor/

    原文作者:北极企鹅ys
    原文地址: https://www.jianshu.com/p/64b32a2fd998
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞