kafka 修改副本数
2019-12-07 本文已影响0人
香山上的麻雀
本文完全参考官网:
官网链接:https://kafka.apache.org/21/documentation.html#basic_ops_increase_replication_factor
例如,以下示例将主题foo的分区0的复制因子从1增加到3。在增加复制因子之前,该分区的唯一副本存在于broker.id为5的节点上,我们将在broker.id为6和7的节点上各增加一个副本。
第一步先创建一个Json文件,格式如下:
>cat increase-replication-factor.json
{"version":1,
"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]}
然后,将json文件与--execute选项一起使用以开始重新分配过程:
> bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 \
--reassignment-json-file increase-replication-factor.json --execute
运行结果:
Current partition replica assignment
{"version":1,
"partitions":[{"topic":"foo","partition":0,"replicas":[5]}]}
Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions
{"version":1,
"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]}
验证结果:
> bin/kafka-topics.sh --zookeeper localhost:2181 --topic foo --describe
Topic:foo PartitionCount:1 ReplicationFactor:3 Configs:
Topic: foo Partition: 0 Leader: 5 Replicas: 5,6,7 Isr: 5,6,7
多分区修改副本数示例:
{"version":1,
"partitions":[{"topic":"event","partition":0,"replicas":[530,531]},
{"topic":"event","partition":1,"replicas":[531,528]},
{"topic":"event","partition":2,"replicas":[528,529]}
]
}