解决 Grafana Loki 报错 entry too old 拒绝写入异常
分析 Grafana Loki 采集历史日志或时钟不同步时报 entry too old 的根因,提供 reject_old_samples 与 max_chunk_age 优化配置。
问题现象
Promtail 或 Fluent Bit 向 Grafana Loki 推送日志时被拒绝,报错信息显示:
level=warn ts=2026-11-15T10:00:00Z caller=client.go:399 component=client host=loki:3100 msg="error sending batch, will retry" status=400 error="server returned HTTP status 400 Bad Request (400): entry with timestamp 2026-11-14T08:00:00Z ignored, too old, oldest acceptable timestamp is: 2026-11-14T12:00:00Z"
大量历史日志被无情丢弃。
触发根因
- Loki 默认开启了严格的时间窗口校验(
reject_old_samples: true),只接收最近特定时长(如 168h 或 1h)以内的日志。 - 采集节点与 Loki 节点系统时钟不同步(NTP 偏移)。
- 正在回溯导入数天前的旧日志归档文件。
解决步骤与操作命令
步骤一:检查并校准服务器时间
确保所有机器运行 NTP 同步:
sudo chronyc tracking
# 或者
timedatectl status
步骤二:调整 Loki 的旧日志容忍配置
编辑 Loki 配置文件 loki.yaml:
limits_config:
# 允许更宽泛的历史日志窗口
reject_old_samples: false # 或者保持 true 但扩大容忍时间
reject_old_samples_max_age: 168h # 允许 7 天内的日志
creation_grace_period: 10m
max_cache_freshness_per_query: 10m
chunk_store_config:
max_look_back_period: 0s # 允许查询全部历史数据
步骤三:重启 Loki 服务
sudo systemctl restart loki
# 或在 k8s 中
kubectl rollout restart statefulset loki
验证确认
观察 Promtail 日志输出:
不再有 entry too old 相关的警告日志,在 Grafana Explore 页面中能够按过去时间范围正常检索出历史日志内容。


