DEBUG.WIKI
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
晚安云;香港 CN2 ¥15/月
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 Kafka 报错 The coordinator is not available 协调者不可用修复

排查 Kafka 消费者提交位点提示 NOT_COORDINATOR / The coordinator is not available 错误,检查 __consumer_offsets 分区 Leader 状态。

问题现象

Kafka 消费者在加入消费组或执行位点提交时控制台抛出警告:

org.apache.kafka.clients.consumer.CommitFailedException: 
Commit cannot be completed since the group has already rebalanced and assigned 
tthe partitions to another member.
Caused by: org.apache.kafka.common.errors.NotCoordinatorException: 
The coordinator is not available.

消费组处于 UNKNOWN 状态,消息消费持续停滞。

触发根因

Kafka 使用内部核心主题 __consumer_offsets 存储各个消费组的位点与协调状态。当承载目标消费组元数据分区的 Broker 宕机、重启,或者 __consumer_offsets 的某个 Partition 丢失了 Leader(处于不可用状态)时,客户端发送的协调请求无法得到响应。

解决步骤

1. 检查内部元数据主题各分区健康状态

运行官方诊断命令:

bin/kafka-topics.sh --bootstrap-server localhost:9092 \
  --describe --topic __consumer_offsets | grep -v "Isr:"

查看是否存在 Leader: none 或 ISR 列表不全的分区。

2. 检查各 Broker 的 Controller 选举日志

在当前活动的 Controller 节点日志中,确认 Broker 元数据更新是否正常同步:

grep -E "(MetadataLoader|GroupCoordinator)" /data/kafka/logs/server.log | tail -n 20

3. 消费者客户端适度调大重试等待

确保客户端重试超时大于集群自动选举收敛周期(通常需要 3~5 秒):

retry.backoff.ms=500

验证确认

查看消费组运行状态:

bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group my_group

输出展示 State: Stable,各个分区正常分配给活跃消费者。