先查看 topic 详情,当前副本数为 2 。
sh-4.4$ kafka-topics --describe --zookeeper zookeeper-1 --topic test_topic
Topic: test_topic PartitionCount: 8 ReplicationFactor: 2 Configs:
Topic: test_topic Partition: 0 Leader: 2 Replicas: 2,3 Isr: 2
Topic: test_topic Partition: 1 Leader: 4 Replicas: 4,2 Isr: 4,2
Topic: test_topic Partition: 2 Leader: 5 Replicas: 5,3 Isr: 5
Topic: test_topic Partition: 3 Leader: 1 Replicas: 1,4 Isr: 1,4
Topic: test_topic Partition: 4 Leader: 2 Replicas: 2,5 Isr: 2,5
Topic: test_topic Partition: 5 Leader: 2 Replicas: 3,2 Isr: 2
Topic: test_topic Partition: 6 Leader: 4 Replicas: 4,3 Isr: 4
Topic: test_topic Partition: 7 Leader: 5 Replicas: 5,4 Isr: 5,4
目标将 ReplicationFactor
调整为 3 。
编写重分配配置文件,命名为: exec.json
{
"version": 1,
"partitions": [
{
"topic": "test_topic",
"partition": 0,
"replicas": [
2,4,1
]
},
{
"topic": "test_topic",
"partition": 1,
"replicas": [
4,2,5
]
},
{
"topic": "test_topic",
"partition": 2,
"replicas": [
5,1,2
]
},
{
"topic": "test_topic",
"partition": 3,
"replicas": [
1,4,5
]
},
{
"topic": "test_topic",
"partition": 4,
"replicas": [
2,5,4
]
},
{
"topic": "test_topic",
"partition": 5,
"replicas": [
5,2,1
]
},
{
"topic": "test_topic",
"partition": 6,
"replicas": [
4,5,2
]
},
{
"topic": "test_topic",
"partition": 7,
"replicas": [
5,4,2
]
}
]
}
kafka-reassign-partitions \
--zookeeper zookeeper-1 \
--reassignment-json-file exec.json \
--execute
再次查看
sh-4.4$ kafka-topics --describe --zookeeper zookeeper-1 --topic test_topic
Topic: test_topic PartitionCount: 8 ReplicationFactor: 3 Configs:
Topic: test_topic Partition: 0 Leader: 2 Replicas: 2,4,1 Isr: 2,1,4
Topic: test_topic Partition: 1 Leader: 4 Replicas: 4,2,5 Isr: 4,2,5
Topic: test_topic Partition: 2 Leader: 5 Replicas: 5,1,2 Isr: 5,1,2
Topic: test_topic Partition: 3 Leader: 1 Replicas: 1,4,5 Isr: 1,4,5
Topic: test_topic Partition: 4 Leader: 2 Replicas: 2,5,4 Isr: 2,5,4
Topic: test_topic Partition: 5 Leader: 2 Replicas: 5,2,1 Isr: 2,5,1
Topic: test_topic Partition: 6 Leader: 4 Replicas: 4,5,2 Isr: 4,5,2
Topic: test_topic Partition: 7 Leader: 5 Replicas: 5,4,2 Isr: 5,4,2