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并且这些副本至少一个活着)。这通常因为你关闭最后一个副本将使这个主题分区不可用。
你好,我使用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)这条,能帮忙看下吗?
你怎么没到kafka-manager那个文章里提问呢。
你有消费者正在运行吗?
有消费者在消费的
Poll consumer information (Not recommended for large # of consumers if ZK is used for offsets tracking on older Kafka versions)
这个勾选了吗?
你好,想问一下,一般要让kafka正常停止是要设置 controlled.shutdown.enable=true配置项, 然后用kafka-server-stop.sh 脚本停止?
kill
停止也可以,不要强制-9
就行。所以 controlled.shutdown.enable=true是一定要设置的?
我看到kafka-server-stop.sh 是 kill -s TERM $PIDS的方式,所以当收到term信号的时候,同时又发现了controlled.shutdown.enable=true,就会正常停止kafka?如果controlled.shutdown.enable=false,会不会导致index文件损坏?
不会,这个设置了会主动通知进行leader选举,正常不设置就会按照默认的规则切换,只是慢一点点。
感谢感谢啊