Loki 如何配置 S3 作为存储后端?
Loki 用 S3 存日志块的配置:storage_config 中 aws 段指定 bucket、endpoint、密钥,schema_config 配合 boltdb-shipper/tsdb 共享存储。本文给出完整 YAML、MinIO 等兼容端的写法与常见错误。
核心在 storage_config:把共享存储(shared_store)指向 s3,配置 bucket 名、endpoint 与访问密钥——日志块与索引都存进对象存储,本地只留缓存。
完整配置示例
auth_enabled: false
server:
http_listen_port: 3100
ingester:
chunk_idle_period: 5m
max_chunk_age: 1h
wal:
enabled: true
dir: /loki/wal
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: s3
schema: v13
index:
prefix: index_
period: 24h
storage_config:
tsdb_shipper:
active_index_directory: /loki/index
cache_location: /loki/cache
shared_store: s3
aws:
bucketnames: my-loki-logs
endpoint: s3.amazonaws.com # MinIO 填自己的地址,如 minio:9000
access_key_id: ${AWS_ACCESS_KEY_ID}
secret_access_key: ${AWS_SECRET_ACCESS_KEY}
insecure: false # MinIO 走 http 时设 true
s3forcepathstyle: true # MinIO 等兼容端必须开启
要点说明
- WAL 必须开:
wal.enabled: true保证宕机时已接收未刷盘的日志不丢; - MinIO/对象存储兼容端:
s3forcepathstyle: true+insecure: true(无 TLS 时); - 生产用 IAM 角色:EKS 用 IRSA 给 Pod 授权,密钥不落配置。
观测云对照
观测云日志数据由云端统一存储并支持按存储策略设置保留期与归档,多索引分桶管理——不需要自建 Loki + S3 这一层。
常见问题(FAQ)
Q:报 403 SignatureDoesNotMatch? 密钥错或时钟漂移;MinIO 场景先确认 s3forcepathstyle。
Q:旧索引格式 boltdb-shipper 还能用吗? 能用但官方推荐 tsdb,新部署直接上 v13 schema。