轻量级日志采集系统Loki+grafana搭建
轻量级日志采集系统Loki+grafana搭建
一.Loki介绍
整体架构
Loki的架构非常简单,使用了和prometheus一样的标签来作为索引,也就是说,你通过这些标签既可以查询日志的内容也可以查询到监控的数据,不但减少了两种查询之间的切换成本,也极大地降低了日志索引的存储。
Loki将使用与prometheus相同的服务发现和标签重新标记库,编写了pormtail, 在k8s中promtail以daemonset方式运行在每个节点中,通过kubernetes api等到日志的正确元数据,并将它们发送到Loki。
下面是日志的存储架构:
二.使用二进制包简单搭建
使用docker-composer可能比较方便,我们这里采用二进制包安装
1.安装loki主程序包
loki-linux-amd64.zip
查看配置文件
[root@centos7 Loki]# cat loki-config.yaml
auth_enabled: false
server:
http_listen_port: 3100
ingester:
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 5m
chunk_retain_period: 30s
max_transfer_retries: 0
schema_config:
configs:
- from: 2018-04-15
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h
storage_config:
boltdb:
directory: /loki/index
filesystem:
directory: /loki/chunks
limits_config:
enforce_metric_name: false
reject_old_samples: true
reject_old_samples_max_age: 168h
chunk_store_config:
max_look_back_period: 0s
table_manager:
retention_deletes_enabled: false
指定配置文件,启动服务
nohup ./loki -config.file=loki-config.yaml &
2.采集promtail节点配置
这里我们使用的是采集小米数据库代理中间件gaea的日志为例,其他的日志只要写好节点采集路径及名称就可以了
下载二进制包promtail-linux-amd64.zip
查看节点采集配置文件
[root@db promtail]# cat promtail-config.yaml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://*******:31000/loki/api/v1/push
scrape_configs:
-
job_name: system
static_configs:
- targets:
- localhost
labels:
job: 92-gaea
path: /data/gaea/logs/gaea.*
- localhost
- targets:
启动采集服务
nohup ./promtail -config.file=promtail-config.yaml &
3.loki服务器端安装展示模版grafana
下载包直接yum安装即可,安装完启动服务
yum install -y grafana-7.0.5-1.x86_64.rpm
三.grafana展示查看数据
1.添加loki数据源
2.打开展示板
3.查看日志数据
四.查询基本语法
= 完全相同。
!= 不平等。
=~ 正则表达式匹配。
!~ 不要正则表达式匹配。
{job=“mysql”} |= “error”
{name=“kafka”} |~ “tsdb-ops.*io:2017”
参考链接:
https://blog.51cto.com/anfishr/2511063
总结
以上是生活随笔为你收集整理的轻量级日志采集系统Loki+grafana搭建的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【脚本整理】docker-compose
- 下一篇: 【实战】数据可视化系统后端开发环境搭建