有关一些日志聚合的起源和原则,请参阅我的另一篇文章“用于编程入门的日志聚合系统”。
[En]
For the origin and principles of some log aggregations, see my other article, “Log aggregation system for getting started with programming”.
https://www.cnblogs.com/uncleguo/p/15948763.html
Loki日志聚合系统是由 Loki + Promtail+Grafana三部分组成的,这三个依次分别为 日志存储引擎,日志收集器,GUI界面,下面我们来简单实践部署下。
1.安装运行Loki及promtail
- Loki 负责日志测存储,搜索
- Promtail 负责收集日志,通过网络发送给Loki
首先去发布页面下载对应的Loki及Promtail版本。https://github.com/grafana/loki/releases/
Centos下载如下链接,下载完成后,解压到相同目录。
Loki:https://github.com/grafana/loki/releases/download/v2.4.2/loki-linux-amd64.zip
Promtail:https://github.com/grafana/loki/releases/download/v2.4.2/promtail-linux-amd64.zip
cd到解压目录中, wget下载默认配置文件模板,可以按需修改,也可以先用模板简单跑起来,增加信心:-)
wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
wget https://raw.githubusercontent.com/grafana/loki/main/clients/cmd/promtail/promtail-local-config.yaml
默认配置内容可以简单看下,比较容易理解。Promtail的默认配置是收集/var/log/*log,发送到本机的Loki http://localhost:3100/loki/api/v1/push 。可以根据需要调整。
以下命令运行Loki 及 Promtail,日志收集和存储就已经工作了。
./promtail-linux-amd64 -config.file=promtail-local-config.yaml
./loki-linux-amd64 -config.file=loki-local-config.yaml
2.安装运行Grafana
Grafana可以提供一个图形界面,以便查询日志,以下位置下载centos tar.gz版本。
wget https://dl.grafana.com/oss/release/grafana-8.4.3.linux-amd64.tar.gz
tar -zxvf grafana-8.4.3.linux-amd64.tar.gz
cd进解压目录运行
cd grafana-8.4.3
./bin/grafana-server web
成功运行后, 默认在3000端口提供服务, 默认的用户名密码为 admin/admin (注意替换实际ip) http://192.168.1.1:3000/login
3.配置Grafana数据源
为Grafana配置Loki作为数据源,以便进行日志可视化查看搜索。
可以查询了。
4 .日志滚动配置
日志总是流动的,它们会被自动删除太长时间,以避免填满存储空间。
[En]
Logs are always flowing, and they are automatically deleted for too long to avoid filling up storage.
修改Loki配置文件 loki-local-config.yaml,追加如下内容。
compactor:
working_directory: /data/retention
shared_store: filesystem
compaction_interval: 10m
retention_enabled: true
retention_delete_delay: 2h
retention_delete_worker_count: 150
storage_config:
boltdb_shipper:
active_index_directory: /data/index
cache_location: /data/boltdb-cache
shared_store: filesystem
limits_config:
retention_period: 168h
其中retention_period为保留时间,这里168小时是7天。
至此,收工~!
Original: https://www.cnblogs.com/uncleguo/p/15975647.html
Author: 锅叔
Title: Centos部署Loki日志聚合系统
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/524034/
转载文章受原作者版权保护。转载请注明原作者出处!