手动调整broker扩容后的旧topic分区

在broker扩容了两台机器之后,想让旧topic:quickstart76-events的分区也能铺满broker

1、创建一个topics-to-move.json json文件

$ vim topics-to-move.json json
{
    "topics": [
	{"topic":"quickstart76-events"}
    ],
    "version":1
}

2、执行命令:

$ /data/kafka_2.13-3.0.0/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.233.132:9092 --topics-to-move-json-file ./topics-to-move.json --broker-list "0,1,2,3,4,5" --generate

得到输出:

Current partition replica assignment
{"version":1,"partitions":[{"topic":"quickstart76-events","partition":0,"replicas":[3,2],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":1,"replicas":[1,3],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":2,"replicas":[0,1],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":3,"replicas":[2,0],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":4,"replicas":[3,1],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":5,"replicas":[1,0],"log_dirs":["any","any"]}]}

Proposed partition reassignment configuration
{"version":1,"partitions":[{"topic":"quickstart76-events","partition":0,"replicas":[4,5],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":1,"replicas":[5,0],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":2,"replicas":[0,1],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":3,"replicas":[1,2],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":4,"replicas":[2,3],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":5,"replicas":[3,4],"log_dirs":["any","any"]}]}

将Proposed partition reassignment configuration的json保存到expand-cluster-reassignment.json文件中

$vim expand-cluster-reassignment.json
{"version":1,"partitions":[{"topic":"quickstart76-events","partition":0,"replicas":[4,5],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":1,"replicas":[5,0],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":2,"replicas":[0,1],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":3,"replicas":[1,2],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":4,"replicas":[2,3],"log_dirs":["any","any"]},{"topic":"quickstart76-events","partition":5,"replicas":[3,4],"log_dirs":["any","any"]}]}

执行命令:

/data/kafka_2.13-3.0.0/bin/kafka-reassign-partitions.sh --bootstrap-server 192.168.233.132:9092 --reassignment-json-file ./expand-cluster-reassignment.json --execute

执行完之后查看topic分区:

$ /data/kafka_2.13-3.0.0/bin/kafka-topics.sh --bootstrap-server 192.168.233.132:9092 --topic quickstart76-events --describe
Topic: quickstart76-events	TopicId: RTYJMgt-SbSPERLyUkAI6Q	PartitionCount: 6	ReplicationFactor: 2	Configs: segment.bytes=1073741824
	Topic: quickstart76-events	Partition: 0	Leader: 4	Replicas: 4,5	Isr: 4,5
	Topic: quickstart76-events	Partition: 1	Leader: 5	Replicas: 5,0	Isr: 5,0
	Topic: quickstart76-events	Partition: 2	Leader: 0	Replicas: 0,1	Isr: 0,1
	Topic: quickstart76-events	Partition: 3	Leader: 1	Replicas: 1,2	Isr: 1,2
	Topic: quickstart76-events	Partition: 4	Leader: 2	Replicas: 2,3	Isr: 2,3
	Topic: quickstart76-events	Partition: 5	Leader: 3	Replicas: 3,4	Isr: 3,4

看到分区已经铺满broker了。

你可能感兴趣的:(excel,kafka)