当前位置: 代码迷 >> 综合 >> topic partition leader rebalance
  详细解决方案

topic partition leader rebalance

热度:2   发布时间:2024-01-25 11:55:46.0

leader rebalance之前,有好几个分区的leader都在broker1上

[root@hzv_stat_es1 ~]# kafka-topics.sh --describe --zookeeper localhost:2181 --topic resshows_test
Topic:resshows_test  PartitionCount:6    ReplicationFactor:2 Configs:retention.ms=345600000,cleanup.policy=deleteTopic: resshows_test Partition: 0    Leader: 1   Replicas: 1,2   Isr: 1,2Topic: resshows_test Partition: 1    Leader: 2   Replicas: 2,3   Isr: 2,3Topic: resshows_test Partition: 2    Leader: 1   Replicas: 3,1   Isr: 1,3Topic: resshows_test Partition: 3    Leader: 1   Replicas: 1,3   Isr: 1,3Topic: resshows_test Partition: 4    Leader: 1   Replicas: 2,1   Isr: 1,2Topic: resshows_test Partition: 5    Leader: 3   Replicas: 3,2   Isr: 2,3

编写rebalance文件
vi resshows_test.json

{"partitions":[{"topic":"resshows_test","partition": 0},{"topic":"resshows_test","partition": 1},{"topic":"resshows_test","partition": 2},{"topic":"resshows_test","partition": 3},{"topic":"resshows_test","partition": 4},{"topic":"resshows_test","partition": 5}]}

leader重新均衡

kafka-preferred-replica-election.sh --zookeeper localhost:2181 --path-to-json-file resshows_test.json

均衡之后

[root@hzv_stat_es1 ~]# kafka-topics.sh --describe --zookeeper localhost:2181 --topic resshows_test
Topic:resshows_test  PartitionCount:6    ReplicationFactor:2 Configs:retention.ms=345600000,cleanup.policy=deleteTopic: resshows_test Partition: 0    Leader: 1   Replicas: 1,2   Isr: 1,2Topic: resshows_test Partition: 1    Leader: 2   Replicas: 2,3   Isr: 2,3Topic: resshows_test Partition: 2    Leader: 3   Replicas: 3,1   Isr: 1,3Topic: resshows_test Partition: 3    Leader: 1   Replicas: 1,3   Isr: 1,3Topic: resshows_test Partition: 4    Leader: 2   Replicas: 2,1   Isr: 1,2Topic: resshows_test Partition: 5    Leader: 3   Replicas: 3,2   Isr: 2,3
  相关解决方案