优雅的关闭kafka

原创
半兽人 发表于: 2015-03-10   最后更新时间: 2020-12-22 17:00:53  
{{totalSubscript}} 订阅, 29,757 游览

The Kafka cluster will automatically detect any broker shutdown or failure and elect new leaders for the partitions on that machine. This will occur whether a server fails or it is brought down intentionally for maintenance or configuration changes. For the later cases Kafka supports a more graceful mechanism for stoping a server then just killing it. When a server is stopped gracefully it has two optimizations it will take advantage of:
Kafka集群自动检测broker关闭或者失败,并且在该机器上的分区选举新的leaders,当服务器出现故障或故意进行维护或配置更改时,为这种情况,Kafka支持一个更优雅机制关闭服务然后kill它,当服务器正常停止,它有2个最佳:

It will sync all its logs to disk to avoid needing to do any log recovery when it restarts (i.e. validating the checksum for all messages in the tail of the log). Log recovery takes time so this speeds up intentional restarts.
它把所有日志同步到磁盘里,当重启时,以避免需要做任何的日志恢复。日志恢复需要时间,所以这样可以加快有意启动。

It will migrate any partitions the server is the leader for to other replicas prior to shutting down. This will make the leadership transfer faster and minimize the time each partition is unavailable to a few milliseconds.
在关闭之间,它将所有leader分区服务器移动到其他的副本,并且把每个分区不可用的几毫秒的时间降至更低。

Syncing the logs will happen automatically happen whenever the server is stopped other than by a hard kill, but the controlled leadership migration requires using a special setting:
当发生服务器停止不是通过强制kill,就会自动同步日志,但是leader迁移需要使用特殊的设置:

controlled.shutdown.enable=true

Note that controlled shutdown will only succeed if all the partitions hosted on the broker have replicas (i.e. the replication factor is greater than 1 and at least one of these replicas is alive). This is generally what you want since shutting down the last replica would make that topic partition unavailable.
注意,控制关闭broker和副本上的所有分区才行(即,副本大于1并且这些副本至少一个活着)。这通常因为你关闭最后一个副本将使这个主题分区不可用。

更新于 2020-12-22
在线,4分钟前登录

Yangy 3年前

你好,我使用kafka-manager的时候在里面看不到消费情况,lag,就是Consumers这个下面是空的,我在bin/kafka-server-start.sh下添加了export JMX_PORT="9999",也勾选了Enable JMX Polling (Set JMX_PORT env variable before starting kafka server)这条,能帮忙看下吗?

半兽人 -> Yangy 3年前

你怎么没到kafka-manager那个文章里提问呢。
你有消费者正在运行吗?

Yangy -> 半兽人 3年前

有消费者在消费的

自由如风 -> Yangy 3年前

Poll consumer information (Not recommended for large # of consumers if ZK is used for offsets tracking on older Kafka versions)
这个勾选了吗?

大熊 4年前

你好,想问一下,一般要让kafka正常停止是要设置 controlled.shutdown.enable=true配置项, 然后用kafka-server-stop.sh 脚本停止?

半兽人 -> 大熊 4年前

kill停止也可以,不要强制-9就行。

大熊 -> 半兽人 4年前

所以 controlled.shutdown.enable=true是一定要设置的?

大熊 -> 半兽人 4年前

我看到kafka-server-stop.sh 是 kill -s TERM $PIDS的方式,所以当收到term信号的时候,同时又发现了controlled.shutdown.enable=true,就会正常停止kafka?如果controlled.shutdown.enable=false,会不会导致index文件损坏?

半兽人 -> 大熊 4年前

不会,这个设置了会主动通知进行leader选举,正常不设置就会按照默认的规则切换,只是慢一点点。

大熊 -> 半兽人 4年前

感谢感谢啊

查看kafka更多相关的文章或提一个关于kafka的问题,也可以与我们一起分享文章