解决 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)
触发根因
- 输入端产生的日志速率远超输出端 Flush 速率,触碰了
Mem_Buf_Limit保护阈值。 - 纯内存缓冲模式下未开启文件持久化缓冲。
诊断排查步骤
- 检查当前 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 告警。


