需要低成本、可水平扩展的日志聚合,和 Prometheus/Grafana 使用同一套标签体系。适合 Kubernetes 容器日志、多租户日志和长期归档。
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install loki grafana/loki \
--namespace logging --create-namespace \
--set deploymentMode=Distributed \
--set loki.storage.type=s3 \
--set loki.storage.s3.endpoint=minio.storage:9000 \
--set loki.storage.s3.bucketnames.chunks=loki-chunks \
--set loki.storage.s3.bucketnames.ruler=loki-ruler \
--set loki.storage.s3.accessKeyId=minio \
--set loki.storage.s3.secretAccessKey=minio123 \
--set loki.storage.s3.s3ForcePathStyle=true
kubectl -n logging get pods
kubectl -n logging get svc
分布式模式包含 distributor、ingester、querier、query-frontend、compactor 和 index-gateway。
helm install alloy grafana/alloy --namespace logging \
--set 'alloy.configMap.content=...'
采集端需要打上 cluster、namespace、pod、container 等标签。
--set loki.limits_config.retention_period=720h
--set loki.compactor.retention_enabled=true
--set loki.limits_config.ingestion_rate_mb=10
--set loki.limits_config.ingestion_burst_size_mb=20
--set loki.limits_config.max_query_length=721h
{namespace="prod"} |= "error"
sum by (pod) (rate({namespace="prod"} |= "error" [5m]))
|= 扫描全量日志,未先按标签缩小范围,查询超时。logcli — 命令行查询 Lokipromtail / alloy — 日志采集kubectl — 查看组件与日志mc — 检查对象存储grafana — 查询与看板