搭建grafana+loki+promtail日志收集系统

准备工作

下载地址

https://github.com/grafana/loki/releases

安装包放在服务器目录:/opt

复制代码
wget https://github.com/grafana/loki/releases/download/v2.4.2/loki-linux-amd64.zip
wget https://github.com/grafana/loki/releases/download/v2.4.2/promtail-linux-amd64.zip

1、启动loki

1)解压loki-linux-amd64.zip

复制代码
unzip loki-linux-amd64.zip 

2)授权

复制代码
chmod a+x loki-linux-amd64

3)配置文件loki.yaml

复制代码
vi loki.yaml

auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 3110
  grpc_server_max_recv_msg_size: 1073741824  #grpc最大接收消息值,默认4m
  grpc_server_max_send_msg_size: 1073741824  #grpc最大发送消息值,默认4m

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
  max_chunk_age: 20m  #一个timeseries块在内存中的最大持续时间。如果timeseries运行的时间超过此时间,则当前块将刷新到存储并创建一个新块

schema_config:
  configs:
    - from: 2021-01-01
      store: boltdb
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 168h

storage_config:
  boltdb:
    directory: /opt/loki/index #存储索引地址
  filesystem:
    directory: /opt/loki/chunks

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h
  ingestion_rate_mb: 30  #修改每用户摄入速率限制,即每秒样本量,默认值为4M
  ingestion_burst_size_mb: 15  #修改每用户摄入速率限制,即每秒样本量,默认值为6M

chunk_store_config:
        #max_look_back_period: 168h   #回看日志行的最大时间,只适用于即时日志
  max_look_back_period: 0s

table_manager:
  retention_deletes_enabled: false #日志保留周期开关,默认为false
  retention_period: 0s  #日志保留周期

4)启动进程

复制代码
nohup /opt/loki/loki-linux-amd64 -config.file=/opt/loki/loki.yaml >loki.out 2>&1 &

2、启动promtail

1)解压loki-linux-amd64.zip

复制代码
unzip promtail-linux-amd64.zip

2)授权

复制代码
chmod a+x promtail-linux-amd64

3)配置文件promtail.yaml

复制代码
vi promtail.yaml

server:
  http_listen_port: 9080
  grpc_listen_port: 0
  grpc_server_max_recv_msg_size: 15728640
  grpc_server_max_send_msg_size: 15728640

positions:
  filename: /opt/loki/positions.yaml # This location needs to be writeable by promtail.

client:
  url: http://xx.xx.xx.xx:3100/loki/api/v1/push

#https://grafana.com/docs/loki/latest/clients/promtail/configuration/
scrape_configs:
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: messages
      __path__: /var/log/messages
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /var/log/*log
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: secure
      __path__: /var/log/secure
#lastlog
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: lastlog
      __path__: /var/log/lastlog
#cron
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: cron
      __path__: /var/log/cron

4)启动进程

复制代码
nohup /opt/loki/promtail-linux-amd64 -config.file=/opt/loki/promtail.yaml >promtail.out 2>&1 &

3、启动grafana

1)安装

官网安装教程地址:Download Grafana | Grafana Labs

复制代码
wget https://dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm 
sudo yum install grafana-7.4.3-1.x86_64.rpm 

2)启动

复制代码
systemctl start grafana-server

3)查看状态

复制代码
systemctl status grafana-server

4、logcli

1)下载

复制代码
wget https://github.com/grafana/loki/releases/download/v2.4.2/logcli-linux-amd64.zip

2)解压logcli-linux-amd64.zip

复制代码
unzip logcli-linux-amd64.zip

3)授权

复制代码
chmod a+x logcli-linux-amd64.zip

4)查看

vb 复制代码
`{job="cron"} 
    |~ "ERROR"
    != "(python3)"`
相关推荐
codeejun14 小时前
每日一Go-70、Prometheus + Grafana 从采集到告警的完整实战(Go + Kind)
golang·grafana·prometheus
king_harry2 天前
Kylinv10下日志收集系统 Loki + Promtail + Grafana(二进制离线部署)
grafana·loki·promtail
zhojiew3 天前
在Ray集群中使用vLLM部署LLM模型并集成Prometheus和Grafana进行指标观测的实践
grafana·prometheus·vllm
zxd0203114 天前
Prometheus + Grafana 监控平台搭建实战指南
grafana·prometheus
叶~小兮5 天前
Prometheus+Grafana监控平台完整学习笔记
学习·grafana·prometheus
JiaWen技术圈6 天前
使用 Terraform Grafana Provider 实现 Grafana 全栈 IaC 一体化管理的完整方案
云原生·grafana·terraform
JiaWen技术圈7 天前
可观测体系最佳实践:Prometheus+Grafana+Loki+Jaeger
grafana·prometheus
数据库小学妹7 天前
MySQL 性能监控实战:从零搭建 Prometheus + Grafana 监控告警体系(附排查 SOP)
mysql·性能优化·grafana·prometheus·dba
heimeiyingwang10 天前
【架构实战】监控告警Prometheus+Grafana:让系统问题无处遁形
架构·grafana·prometheus
成为你的宁宁10 天前
【Prometheus+Grafana 监控平台二进制安装配置(图文实操详解)】
grafana·prometheus