查看详情已经变成4个分区
itcast@Server-node:/mnt/d/kafka-cluster/kafka-1$ bin/kafka-topics.sh --describe
–zookeeper localhost:2181 --topic heima
-par
Topic:heima-par PartitionCount:4 ReplicationFactor:3 Configs:
Topic: heima-par Partition: 0 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
Topic: heima-par Partition: 1 Leader: 0 Replicas: 0,2,1 Isr: 0
Topic: heima-par Partition: 2 Leader: 1 Replicas: 1,0,2 Isr: 1,0,2
Topic: heima-par Partition: 3 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
这样会导致broker2维护更多的分区
- 第三步:再添加一个broker节点
查看主题信息
itcast@Server-node:/mnt/d/kafka-cluster/kafka-1$ bin/kafka-topics.sh --describe
–zookeeper localhost:2181 --topic heima
-par
Topic:heima-par PartitionCount:4 ReplicationFactor:3 Configs:
Topic: heima-par Partition: 0 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
Topic: heima-par Partition: 1 Leader: 0 Replicas: 0,2,1 Isr: 0
Topic: heima-par Partition: 2 Leader: 1 Replicas: 1,0,2 Isr: 1,0,2
Topic: heima-par Partition: 3 Leader: 2 Replicas: 2,1,0 Isr: 2,1,0
从上面输出信息可以看出新添加的节点并没有分配之前主题的分区
- 第四步:重新分配
现在我们需要将原先分布在broker 1-3节点上的分区重新分布到broker 1-4节点上,借助kafka-reassign-partitions.sh工具生成reassign plan
,不过我们先得按照要求定义一个文件,里面说明哪些topic需要重新分区,文件内容如下:
itcast@Server-node:/mnt/d/kafka-cluster/kafka-1$ cat reassign.json {
“topics”:[{“topic”:“heima-par”}],
“version”:1
}
然后使用 kafka-reassign-partitions.sh 工具生成reassign plan
然后执行脚本 bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to -move-json-file reassign.json --broker-list "0,1,2,3" --generate
itcast@Server-node:/mnt/d/kafka-cluster/kafka-1$ bin/kafka-reassign-
partitions.sh --zookeeper localhost:2181 --topics-to
-move-json-file reassign.json --broker-list “0,1,2,3” --generate
Current partition replica assignment
{“version”:1,“partitions”:[{“topic”:“heima-par”,“partition”:2,“replicas”: [1,0,2],“log_dirs”:[“any”,“any”,“any”]},
{“topic”:“heima- par”,“partition”:1,“replicas”:[0,2,1],“log_dirs”:[“any”,“any”,“any”]},
{“topic”:“heima-par”,“partition”:0,“replicas”:[2,1,