Victor Bu

户外, 旅行, 读书, 生活, 有趣

  • 首页
  • 旅行
  • 户外
  • 读书
  • 急救
  • 挨踢
所有文章 友链 关于我

Victor Bu

户外, 旅行, 读书, 生活, 有趣

  • 首页
  • 旅行
  • 户外
  • 读书
  • 急救
  • 挨踢

日志聚合工具之 Loki

2020-09-27

本文使用的 Loki 和 Promtail 版本为 1.6.1,Grafana 版本为 7.2.0;部署在 Linux 服务器

Loki 负责日志的存储和查询;Promtail 负责日志的采集并推送给 Loki;Grafana 负责日志展示

一、Loki

Loki 下载地址:https://github.com/grafana/loki/releases,下载 loki-linux-amd64.zip

在 Loki 的源码里找到对应版本的配置文件:/cmd/loki/loki-local-config.yaml,文件内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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: /tmp/loki/index

filesystem:
directory: /tmp/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
retention_period: 0s

根据具体情况决定是否修改上述配置,然后执行以下命令:

1
2
3
unzip loki-linux-amd64.zip

nohup ./loki-linux-amd64 -config.file=loki-local-config.yaml >/dev/null 2>&1 &

二、Promtail

Promtail 下载地址:https://github.com/grafana/loki/releases,下载 promtail-linux-amd64.zip

在 Loki 的源码里找到对应版本的配置文件:/cmd/promtail/promtail-local-config.yaml,文件内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /tmp/positions.yaml

clients:
- url: http://localhost:3100/loki/api/v1/push

scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log

根据具体情况决定是否修改上述配置或者添加 job,然后执行以下命令:

1
2
3
unzip promtail-linux-amd64.zip

nohup ./promtail-linux-amd64 -config.file=promtail-local-config.yaml >/dev/null 2>&1 &

三、Grafana

3.1. 下载并启动

如果之前没有安装过 Grafana,需要先下载安装,下载地址:https://grafana.com/grafana/download

执行以下命令:

1
2
3
4
5
tar -xzvf grafana-7.2.0.linux-amd64.tar.gz

cd grafana-7.2.0

nohup ./bin/grafana-server >/dev/null 2>&1 &

如果不是在 grafana 所在目录执行运行命令需要添加参数,如:-homepath /xx/grafana-7.2.0

其中 xx 为自定义目录

默认端口为 3000,用户名密码均为 admin

3.2. 配置

  1. 登录 Grafana,在 Configuration > Data Sources 点击 “Add data source” 按钮,选中 Loki
  2. URL 填入 http://localhost:3100,并保存
  3. 在 Explore 中选中上面添加的 Loki 数据源 既可以看到日志信息
赏

谢谢你请我吃糖果

支付宝
微信
  • Loki
  • Promtail
  • Grafana
  • IT

扫一扫,分享到微信

微信分享二维码
Prometheus 使用之 node exporter
在 Spring Boot 配置 Kafka 安全认证
© 2021 Victor Bu
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链
  • 关于我

tag:

  • 海岛
  • 香港
  • 攻略
  • 急救
  • 徒步
  • 泰国
  • 东南亚
  • 柬埔寨
  • 越南
  • 甘肃
  • 深圳
  • 香港文化博物馆
  • 树莓派
  • Raspbian
  • Python
  • Samba
  • CentOS 7
  • Linux
  • Windows
  • Travis CI
  • Hexo
  • GitHub
  • GIS
  • Leaflet
  • VLC
  • SQL Server
  • hls
  • m3u8
  • WindowsAPICodePack-Shell
  • DotNetty
  • Modbus
  • CRC
  • HJ212
  • ngrok
  • js
  • Java
  • Spring
  • Spring Boot
  • Mybatis
  • Spring MVC
  • Netty
  • RESTful API
  • Unit testing
  • PLC
  • JPA
  • MySQL
  • Redis
  • Shell32
  • IDE
  • IDEA
  • MyBatis
  • Microservices
  • Spring Cloud
  • Eureka
  • Spring Security
  • OAuth2
  • JWT
  • Ribbon
  • Feign
  • Hystrix
  • Hystrix Dashboard
  • Turbine
  • Zuul
  • Spring Cloud Config
  • Spring Cloud Sleuth
  • Zipkin
  • Spring Boot Admin
  • UUID
  • Hibernate
  • Swagger
  • snowflake
  • CORS
  • RabbitMQ
  • Elasticsearch
  • Sharding-JDBC
  • MongoDB
  • Tomcat
  • JDK
  • MQTT
  • WebSocket
  • Kafka
  • Alibaba
  • Nacos
  • Spring Cloud Gateway
  • Dubbo
  • Sentinel
  • SkyWalking
  • Seata
  • MyBatis-Plus
  • RestTemplate
  • Jasypt
  • XXL-JOB
  • JJWT
  • Hyper-V
  • Flyway
  • Elastic
  • Kibana
  • Beats
  • Logstash
  • canal
  • MinIO
  • OSS
  • Shell
  • inotify
  • Paho
  • Loki
  • Promtail
  • Grafana
  • Prometheus
  • node exporter
  • Docker
  • Kubernetes
  • Alibaba Cloud
  • Jenkins
  • Maven
  • Git
  • Node.js
  • EMQ X
  • Google Authenticator
  • 医疗

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • 友情链接1
  • 友情链接2
  • 友情链接3
  • 友情链接4
  • 友情链接5
  • 友情链接6
很惭愧

只做了一点微小的工作
谢谢大家