云原生日志(1)Loki安装部署
介绍
Loki
是一个轻量级的日志收集、分析的应用,采用的是 promtail
的方式来获取日志内容并送到loki里面进行存储,最终在 grafana
的 datasource
里面添加数据源进行日志的展示、查询。
官方文档:https://kubernetes.io/docs/concepts/security/pod-security-policy
loki
的持久化存储支持 azure、gcs、s3、swift、local
这5中类型,其中常用的是 s3、local
。另外,它还支持很多种日志搜集类型,像最常用的 logstash、fluentbit
也在官方支持的列表中。
1. 下载Loki安装包
$ mkdir /data/loki && /data/loki
$ curl -O -L "https://github.com/grafana/loki/releases/download/v2.8.6/loki-linux-amd64.zip"
$ unzip loki-linux-amd64.zip
2. 修改配置文件
$ vim loki-local-config.yaml
auth_enabled: false
server:
http_listen_port: 3100 # 端口
ingester:
lifecycler:
address: 10.201.10.231 # 地址
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed
max_chunk_age: 1h # 每小时把数据从内存中写入磁盘
chunk_target_size: 1048576 # Loki will attempt to build chunks up to 1.5MB, flushing first if chunk_idle_period or max_chunk_age is reached first
chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m)
max_transfer_retries: 0 # Chunk transfers disabled
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: /data/loki/data/boltdb-shipper-active
cache_location: /data/loki/data/boltdb-shipper-cache
cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space
shared_store: filesystem
filesystem:
directory: /data/loki/data
compactor:
working_directory: /data/loki/boltdb-shipper-compactor
shared_store: filesystem
limits_config:
reject_old_samples: true
reject_old_samples_max_age: 168h
chunk_store_config:
max_look_back_period: 0s
table_manager:
retention_deletes_enabled: false
retention_period: 0s
ruler:
storage:
type: local
local:
directory: /data/loki/rules
rule_path: /data/loki/rules-temp
alertmanager_url: http://localhost:9093 # alertmanager报警地址
ring:
kvstore:
store: inmemory
enable_api: true
3. 设置服务
$ vim /usr/lib/systemd/system/loki.service
[Unit]
Description=loki
Documentation=https://github.com/grafana/loki/tree/master
After=network.target
[Service]
Type=simple
ExecStart=/data/loki/loki-linux-amd64 -config.file=/data/loki/loki-local-config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
4. 启动、开机自启
$ systemctl start loki
$ systemctl enable loki
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
运维小记!
喜欢就支持一下吧
打赏
微信
支付宝