修改副本数

来源:互联网 发布:阿里云学生机和腾讯云 编辑:程序博客网 时间:2024/04/28 11:21
1、确定需要增加副本的topic列表,确定topic的分区、副本详情信息,编写副本修改计划。例如原topic的partion个数为3,副本数为1
原topic副本分配情况如下
{"version":1,
 "partitions":[{"topic":"rangertest","partition":0,"replicas":[10000]},
               {"topic":"rangertest","partition":1,"replicas":[10001]},
               {"topic":"rangertest","partition":2,"replicas":[10002]}]
}
现需要分区数不变情况下增加副本数为2,现将重新分配后的topic分区、副本配置信息存储为json格式文件,命名为increase-replication-factor.json文件(文件名任意),
{"version":1,
 "partitions":[{"topic":"rangertest","partition":0,"replicas":[10000,10001]},
               {"topic":"rangertest","partition":1,"replicas":[10001,10000]},
               {"topic":"rangertest","partition":2,"replicas":[10002,10001]}]
}


2、执行增加副本数脚本命令、
> bin/kafka-reassign-partitions.sh  --zookeeper localhost:2181/kafka --reassignment-json-file increase-replication-factor.json --execute
Current partition replica assignment


{"version":1,"partitions":[{"topic":"rangertest","partition":2,"replicas":[10002]},{"topic":"rangertest","partition":1,"replicas":[10001]},{"topic":"rangertest","partition":0,"replicas":[10000]}]}


Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions {"version":1,"partitions":[{"topic":"rangertest","partition":0,"replicas":[10000,10001]},{"topic":"rangertest","partition":1,"replicas":[10001,10000]},{"topic":"rangertest","partition":2,"replicas":[10002,10001]}]}
3、脚本验证执行结果
bin/kafka-reassign-partitions.sh  --zookeeper localhost:2181/kafka --reassignment-json-file increase-replication-factor.json --verify
Status of partition reassignment:
Reassignment of partition [rangertest,0] completed successfully
Reassignment of partition [rangertest,1] completed successfully
Reassignment of partition [rangertest,2] completed successfully


4、手动topic脚本验证也行
bin/kafka-topics.sh --zookeeper localhost:2181/kafka --topic rangertest --describe
Topic:rangertest        PartitionCount:3        ReplicationFactor:2     Configs:
        Topic: rangertest       Partition: 0    Leader: 10000   Replicas: 10000,10001   Isr: 10000,10001
        Topic: rangertest       Partition: 1    Leader: 10001   Replicas: 10001,10000   Isr: 10001,10000
        Topic: rangertest       Partition: 2    Leader: 10002   Replicas: 10002,10001   Isr: 10002,10001
0 0
原创粉丝点击