查看topic sqbj的分区副本
副本数量为3 我们想把副本改成1用来提高服务器性能(建议为2 可以保障高可用)
[root@p-96b7-ggco-0002 kafka]# ./bin/kafka-topics.sh --describe --zookeeper 127.0.0.1:2181 --topic sqbj
Topic: sqbj PartitionCount: 8 ReplicationFactor: 3 Configs:
Topic: sqbj Partition: 0 Leader: 1 Replicas: 1,3,2 Isr: 1,3,2
Topic: sqbj Partition: 1 Leader: 2 Replicas: 2,1,3 Isr: 1,3,2
Topic: sqbj Partition: 2 Leader: 3 Replicas: 3,2,1 Isr: 1,3,2
Topic: sqbj Partition: 3 Leader: 1 Replicas: 1,2,3 Isr: 1,3,2
Topic: sqbj Partition: 4 Leader: 2 Replicas: 2,3,1 Isr: 1,3,2
Topic: sqbj Partition: 5 Leader: 3 Replicas: 3,1,2 Isr: 1,3,2
Topic: sqbj Partition: 6 Leader: 1 Replicas: 1,3,2 Isr: 1,3,2
Topic: sqbj Partition: 7 Leader: 2 Replicas: 2,1,3 Isr: 2,1,3
创建副本缩容计划
[root@p-96b7-ggco-0002 kafka]# cat increase-replication-factor.json
{
"version":1,
"partitions":[{"topic":"sqbj","partition":0,"replicas":[3]},
{"topic":"sqbj","partition":1,"replicas":[1]},
{"topic":"sqbj","partition":2,"replicas":[2]},
{"topic":"sqbj","partition":3,"replicas":[3]},
{"topic":"sqbj","partition":4,"replicas":[1]},
{"topic":"sqbj","partition":5,"replicas":[2]},
{"topic":"sqbj","partition":7,"replicas":[3]},
{"topic":"sqbj","partition":6,"replicas":[1]}]
}
[root@p-96b7-ggco-0002 kafka]# ./bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --execute
Current partition replica assignment
{"version":1,"partitions":[{"topic":"sqbj","partition":7,"replicas":[2,1,3],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":3,"replicas":[1,2,3],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":0,"replicas":[1,3,2],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":4,"replicas":[2,3,1],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":1,"replicas":[2,1,3],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":5,"replicas":[3,1,2],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":2,"replicas":[3,2,1],"log_dirs":["any","any","any"]},{"topic":"sqbj","partition":6,"replicas":[1,3,2],"log_dirs":["any","any","any"]}]}
Save this to use as the --reassignment-json-file option during rollback
Successfully started reassignment of partitions.
验证
[root@p-96b7-ggco-0002 kafka]# ./bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file increase-replication-factor.json --verify
Status of partition reassignment:
Reassignment of partition sqbj-7 completed successfully
Reassignment of partition sqbj-3 completed successfully
Reassignment of partition sqbj-0 completed successfully
Reassignment of partition sqbj-4 completed successfully
Reassignment of partition sqbj-1 completed successfully
Reassignment of partition sqbj-5 completed successfully
Reassignment of partition sqbj-2 completed successfully
Reassignment of partition sqbj-6 completed successfully
[root@p-96b7-ggco-0002 kafka]# ./bin/kafka-topics.sh --describe --zookeeper 127.0.0.1:2181 --topic sqbj
Topic: sqbj PartitionCount: 8 ReplicationFactor: 1 Configs:
Topic: sqbj Partition: 0 Leader: 3 Replicas: 3 Isr: 3
Topic: sqbj Partition: 1 Leader: 1 Replicas: 1 Isr: 1
Topic: sqbj Partition: 2 Leader: 2 Replicas: 2 Isr: 2
Topic: sqbj Partition: 3 Leader: 3 Replicas: 3 Isr: 3
Topic: sqbj Partition: 4 Leader: 1 Replicas: 1 Isr: 1
Topic: sqbj Partition: 5 Leader: 2 Replicas: 2 Isr: 2
Topic: sqbj Partition: 6 Leader: 1 Replicas: 1 Isr: 1
Topic: sqbj Partition: 7 Leader: 3 Replicas: 3 Isr: 3