简体   繁体   English

自动更改kafka主题分区领导者

[英]Automatic change kafka topic partition leader

I have an issue with my Kafka cluster. 我的Kafka群集存在问题。 I have 3 brokers, so when I stop the broker 1 (for example), each topic partition with leader 1 change his leader with the seconde broker in replica configuration. 我有3个代理,所以当我停止代理1(例如)时,每个主题分区与领导者1在副本配置中使用seconde代理更改其领导者。 So this is the good behavior and it works fine. 所以这是好的行为,它运作良好。

But when I restart the broker 1 I need to execute: 但是当我重新启动代理1时,我需要执行:

./kafka-preferred-replica-election.sh --zookeeper myHost

because the current leader is the other replica. 因为现在的领导者是另一个副本。

So my question is : there is a way to configure Kafka to do it automatically ? 所以我的问题是:有一种方法可以配置Kafka自动执行此操作吗?

thx 谢谢

I'm assuming your default (when all brokers are running) assignment is balanced, and the preferred leaders are evenly spread. 我假设您的默认值(当所有经纪人都在运行时)分配是平衡的,并且首选的领导者是均匀分布的。

Yes Kafka can re-elect the preferred leaders for all the partitions automatically when a broker is restarted. 是的,当重新启动代理时,Kafka可以自动重新选择所有分区的首选领导者。 This is actually enabled by default, see auto.leader.rebalance.enable . 这实际上是默认启用的,请参阅auto.leader.rebalance.enable

Upon restarting a broker, Kafka can take up to leader.imbalance.check.interval.seconds to trigger the re-election. 重启代理后,Kafka可以接受leader.imbalance.check.interval.seconds来触发重选。 This defaults to 5 minutes. 默认为5分钟。 So maybe you just did not wait long enough! 所以也许你没等多久!

There is also leader.imbalance.per.broker.percentage which defines the percentage of non-preferred leaders allowed. 还有leader.imbalance.per.broker.percentage ,它定义了允许的非首选领导者的百分比。 This default to 10%. 默认为10%。

For the full details about these configuration, see the broker config section on Kafka's website. 有关这些配置的完整详细信息,请参阅Kafka网站上的代理配置部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM