linux查询日志_5分钟搭建轻量级日志系统Loki

Loki 是一个水平可扩展,高可用性,多租户日志聚合系统,灵感来自 Prometheus ,其设计非常经济高效,易于操作。它不索引日志的内容,而是为每个日志流设置一组标签。

与其他日志聚合系统相比,Loki:

  • 不对日志进行全文本索引。通过存储压缩的,非结构化的日志以及仅索引元数据,Loki更加易于操作且运行成本更低。
  • 使用与Prometheus相同的标签对日志流进行索引和分组,从而使您能够使用与Prometheus相同的标签在指标和日志之间无缝切换。
  • 特别适合存储Kubernetes Pod日志。诸如Pod标签之类的元数据会自动被抓取并建立索引。
  • 在Grafana中原生支持(需要Grafana v6.0及以上)。

基于Loki的日志记录堆栈包含3个组件:

  • promtail是代理,负责收集日志并将其发送给Loki。
  • loki是主服务器,负责存储日志和处理查询。
  • Grafana用于查询和显示日志。

开始

大部分文章都是基于 k8s 、docker-compose去安装的,这里我们用二进制安装

Loki

类似 elasticsearch

安装
curl -O -L "https://github.com/grafana/loki/releases/download/v1.5.0/loki-linux-amd64.zip"unzip loki-linux-amd64.zipchmod a+x loki-linux-amd64./loki-linux-amd64
配置文件 config.yaml
auth_enabled: falseserver:  http_listen_port: 3100ingester:  lifecycler:    address: 127.0.0.1    ring:      kvstore:        store: inmemory      replication_factor: 1    final_sleep: 0s  chunk_idle_period: 5m  chunk_retain_period: 30sschema_config:  configs:    - from: 2018-04-15      store: boltdb      object_store: filesystem      schema: v9      index:        prefix: index_        period: 168hstorage_config:  boltdb:    directory: /tmp/loki/index  filesystem:    directory: /tmp/loki/chunkslimits_config:  enforce_metric_name: false  reject_old_samples: true  reject_old_samples_max_age: 168hchunk_store_config:  max_look_back_period: 0table_manager:  chunk_tables_provisioning:    inactive_read_throughput: 0    inactive_write_throughput: 0    provisioned_read_throughput: 0    provisioned_write_throughput: 0  index_tables_provisioning:    inactive_read_throughput: 0    inactive_write_throughput: 0    provisioned_read_throughput: 0    provisioned_write_throughput: 0  retention_deletes_enabled: false  retention_period: 0
Promtail

比如你要收集Nginx的错误日志,那就要在Nginx那台服务器部署 Promtail,类似 fluentd

安装
curl -O -l "https://github.com/grafana/loki/releases/download/v1.5.0/promtail-linux-amd64.zip"unzip promtail-linux-amd64.zipchmod a+x promtail-linux-amd64./promtail-linux-amd64
配置文件 config.yaml
# Promtail Server Configserver:  http_listen_port: 9080  grpc_listen_port: 0# Positionspositions:  filename: /tmp/positions.yaml# Loki服务器的地址clients:  - url: http://172.18.11.161:3100/loki/api/v1/pushscrape_configs:  - job_name: nginx    static_configs:      - targets:          - localhost        labels:          job: nginx-error          host: localhost          __path__: /usr/local/nginx/logs/error.log
Grafana

打开Grafana,添加数据源,选

634beddce981e6c81059ca367634ef39.png
4f02b956b7246fe114104739769c0bfe.png

使用

打开 Grafana,点击 Explore ,

1c70573fa75c1035083a0cbb8a694d87.png

Log labels 输入 {job="nginx-error"}

6567f22fb4777d4410ded73331560b30.png
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值