前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Grafana+loki+promtail入门级部署分布式日志系统(windows环境)

使用Grafana+loki+promtail入门级部署分布式日志系统(windows环境)

原创
作者头像
怒放吧德德
发布2022-11-12 17:59:40
2.7K0
发布2022-11-12 17:59:40
举报
文章被收录于专栏:知识储备知识储备

?生命不息,写作不止 ? 继续踏上学习之路,学之分享笔记 ? 总有一天我也能像各位大佬一样 ? 一个有梦有戏的人 @怒放吧德德 ?分享学习心得,欢迎指正,大家一起学习成长!

简介

由于需求对日志进行监控,但是日志又很大,不能直接通过流的方式直接将text读取出来,可以使用grafana+loki+promtail搭建一个轻量级的日志系统,部署也简单方便。grafana提供可视化展示日志,然而loki是存储日志和处理查询,Promtail相当于loki的代理,收集日志发给loki。

1、安装grafana

登录如图

登录界面
登录界面

2、安装loki

下载地址:https://github.com/grafana/loki/releases

下载loki-windows-amd64.exe.zip安装包,并进行解压到F:\soft\grafana\logmanager,解压得到loki-windows-amd64.exe

F:\soft\grafana\logmanager目录下添加loki-local-config.yaml文件,内容如下

代码语言:javascript
复制
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: 2022-08-06
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 672h #每张表的时间范围28天

storage_config:
boltdb:
directory: /tmp/loki/index # 索引文件存储地址

filesystem:
directory: /tmp/loki/chunks # 块存储地址

limits_config:
enforce_metric_name: false
reject_old_samples: true

chunk_store_config:
max_look_back_period: 24h # 最大可查询历史日期 28天,这个时间必须是schema_config中的period的倍数,否则报错。

table_manager: # 配置保留多少天的数据,那么之前数据会被清除,Loki中默认保留所有数据
retention_deletes_enabled: true
retention_period: 24h

打开cmd定位到exe目录,执行命令:.\loki-windows-amd64.exe --config.file=loki-local-config.yaml,loki服务启动成功

配置通信端口号:

代码语言:javascript
复制
server: http_listen_port: 3200 # http访问端口 grpc_listen_port: 9096 # 通信端口
# 启动:
.\loki-windows-amd64.exe --config.file=loki-local-config.yaml

3、安装promtail

  • 下载地址:https://github.com/grafana/loki/releases
  • 下载promtail-windows-amd64.exe.zip安装包,并解压到F:\soft\grafana\promtail目录,得到promtail-windows-amd64.exe
  • F:\soft\grafana\promtail目录下添加promtail-local-config.yaml文件,内容如下
代码语言:javascript
复制
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: viplogs
__path__: F:\soft\grafana\testlogs\*.log
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: viplogs
__path__: F:\soft\grafana\testlogs\*.log

打开cmd定位到exe目录,执行命令: .\promtail-windows-amd64.exe --config.file=promtail-local-config.yaml,loki服务启动成功。

.\promtail-windows-amd64.exe --config.file=promtail-local-config.yaml

安装启动完毕就可以打开查看

4、使用Grafana+loki+promtail查看日志

登录grafana后在Data sources -> Add data source选择loki配置好相应信息即可

输入labels标签,右上角可以设置查看时间,然后查询就可以看到,并且支持定时查询日志,笔者暂时没有开启收集日志,并且是使用loki+logback收集的日志(后期会提供相应的篇章介绍),因此截图中没有日志,但能看到标签。

这样就能够查看日志了,loki是比较轻量级的日志监控系统,通过logback可以定制自己打印日志,还能够自己实现可视化,对于一些工业项目中,可以将日志显示在后台上,方便实施人员查看,这个以后会有相关文章来介绍,这个只是简单的介绍。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介
  • 1、安装grafana
  • 2、安装loki
  • 3、安装promtail
  • 4、使用Grafana+loki+promtail查看日志
相关产品与服务
Grafana 服务
Grafana 服务(TencentCloud Managed Service for Grafana,TCMG)是腾讯云基于社区广受欢迎的开源可视化项目 Grafana ,并与 Grafana Lab 合作开发的托管服务。TCMG 为您提供安全、免运维 Grafana 的能力,内建腾讯云多种数据源插件,如 Prometheus 监控服务、容器服务、日志服务 、Graphite 和 InfluxDB 等,最终实现数据的统一可视化。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com