topic partition leader rebalance

leader rebalance之前,有好幾個分區的leader都在broker1上

[root@es1 ~]# kafka-topics.sh --describe --zookeeper localhost:2181 --topic resshows_test
Topic:resshows_test  PartitionCount:6    ReplicationFactor:2 Configs:retention.ms=345600000,cleanup.policy=delete
    Topic: resshows_test Partition: 0    Leader: 1   Replicas: 1,2   Isr: 1,2
    Topic: resshows_test Partition: 1    Leader: 2   Replicas: 2,3   Isr: 2,3
    Topic: resshows_test Partition: 2    Leader: 1   Replicas: 3,1   Isr: 1,3
    Topic: resshows_test Partition: 3    Leader: 1   Replicas: 1,3   Isr: 1,3
    Topic: resshows_test Partition: 4    Leader: 1   Replicas: 2,1   Isr: 1,2
    Topic: 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@es1 ~]# kafka-topics.sh --describe --zookeeper localhost:2181 --topic resshows_test
Topic:resshows_test  PartitionCount:6    ReplicationFactor:2 Configs:retention.ms=345600000,cleanup.policy=delete
    Topic: resshows_test Partition: 0    Leader: 1   Replicas: 1,2   Isr: 1,2
    Topic: resshows_test Partition: 1    Leader: 2   Replicas: 2,3   Isr: 2,3
    Topic: resshows_test Partition: 2    Leader: 3   Replicas: 3,1   Isr: 1,3
    Topic: resshows_test Partition: 3    Leader: 1   Replicas: 1,3   Isr: 1,3
    Topic: resshows_test Partition: 4    Leader: 2   Replicas: 2,1   Isr: 1,2
    Topic: resshows_test Partition: 5    Leader: 3   Replicas: 3,2   Isr: 2,3
發佈了117 篇原創文章 · 獲贊 36 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章