DEBUG.WIKI
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证

解决 Fluent Bit 报错 cannot allocate chunk memory limit reached

分析 Fluent Bit 向 ES 推送日志报 cannot allocate chunk memory 根因,详解 Mem_Buf_Limit、磁盘缓冲模式与限流调优方案。

问题现象

Fluent Bit 日志采集守护进程日志中频繁出现内存分配失败告警,部分输入流被强制暂停:

[warn] [engine] chunk cannot allocate memory, limit reached: input=tail.0
[warn] [input:tail:tail.0] /var/log/containers/*.log paused (buffer full)

触发根因

  1. 输入端产生的日志速率远超输出端 Flush 速率,触碰了 Mem_Buf_Limit 保护阈值。
  2. 纯内存缓冲模式下未开启文件持久化缓冲。

诊断排查步骤

  1. 检查当前 Fluent Bit 的内存指标与缓冲区状态:
curl -s http://127.0.0.1:2020/api/v1/storage

解决步骤与操作命令

步骤一:开启磁盘持久化缓冲(彻底打破内存限制)

在 fluent-bit.conf 中为 Input 插件增加 storage.type filesystem:

[SERVICE]
    Flush           1
    Storage.path    /var/log/fluentbit/buffer
    Storage.sync    normal
    Storage.backlog.mem_limit 10M

[INPUT]
    Name            tail
    Path            /var/log/containers/*.log
    Mem_Buf_Limit   30MB
    Storage.type    filesystem

步骤二:增加 Output 端并发与重试退避

[OUTPUT]
    Name            es
    Match           *
    Host            elasticsearch
    Workers         4
    Retry_Limit     10

验证方法

滚动重启 Fluent Bit:

systemctl restart fluent-bit

在瞬时日志洪峰冲击下,数据平稳溢出落盘缓存并依次推送到 ES,不再出现 cannot allocate chunk memory 告警。