背景
公司的向上服务是使用的Grafana+Promtail+Loki,Grafana负责数据呈现,Promtail负责日志的收集,Loki负责日志存储。相对于ELK的模式,要小不少,部署也非常容易,每日日志产生量100G以下的项目,都可以使用单例的Loki进行支持。随着项目的发展,日志存储磁盘越来越大,再次记录下配置存储有效期过程,以备有需要的老伙计参考
配置
Loki的配置部分相对还是蛮简单的,我所使用的Loki版本是 2.9.0。最新版本已经到3.1.0了,需要注意的是如果是搭建,最好是确保grafana+promtail+loki的版本兼容。过期部分的官方文档可以看这里 storage/retention,这里直接贴出对应的配置内容
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
compactor:
working_directory: /tmp/loki/retention
compaction_interval: 10m
retention_enabled: true
retention_delete_delay: 2h
retention_delete_worker_count: 150
delete_request_store: filesystem
limits_config:
retention_period: 2160h
max_query_lookback: 2160h
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 2048
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
#storage_config:
# boltdb_shipper:
# active_index_directory: /tmp/loki/boltdb-shipper-active
# cache_location: /tmp/loki/boltdb-shipper-cache
ruler:
alertmanager_url: http://localhost:9093
我所遇到的坑是这里的compactor.delete_request_store
,我理解的既然是store
,是不是就应该填写的是schema_config
中的store
,结果不管是填config
还是填写 boltdb-shipper
都不对,都会导致启动错误
error running loki" err="failed to init delete store. Object client not found for boltdb-shipper
如果将配置注解掉,正确的做法是这里要填写filesystem,即schema_config
中指定的object_store
。
另外需要注意的如果需要开启retention_enabled
那index.period
必须要24h