Grafana loki部署及使用及问题处理方法(超详细)

2 篇文章 0 订阅
2 篇文章 0 订阅

一、下载软件

因为我是本地测试,所以用的windows版本的包,loki服务window版本的安装包下载地址:下载地址,选择

promtail-windows版本的安装包下载地址:下载地址

Grafana服务的下载地址:下载地址

二、配置文件

在解压后的根目录下,新建loki-local-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: 2022-02-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

 新增promtail-local-config.yaml配置文件,内容如下:

server: 
  http_listen_port: 9080
  grpc_listen_port: 0

positions: 
  filename: /tmp/positions.yaml

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

scrape_configs: 
- job_name: system
  static_configs: 
  - targets:
      - 127.0.0.1
    labels: 
      job: testlogs
#第1个监控日志目录
      __path__: C:\Users\Administrator\Desktop\fsdownload\*.log
- job_name: system1
  static_configs: 
  - targets:
      - 127.0.0.1
    labels: 
#第2个监控日志目录
      job: alogs
      __path__: D:\work\product\MES\windows-pro\logs\*.log

三、创建启动脚本

在根目录下新增loki的启动的windows命令行脚本,内容如下:

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

在根目录下新增promtail的启动的windows命令行脚本,内容如下:

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

四、配置loki

安装好Grafana后,先启动上面的loki服务,后启动promtail服务,浏览器访问grafana,地址:http://127.0.0.1:3000/

 点击左下角的设置图标,选择Configuration

 Add Data source,选择loki

 输入loki的URL,默认就是http://127.0.0.1:3100

 点击下面的Save&test,若提示“Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.”,检查上面配置的promtail-local-config.yaml中的“_path_”路径是否存在,若test成功,则会有如下测试:

 五、验证效果

点击左侧工具栏,选择Explore

选择要查询的日志标签,然后输入要搜索的日志文本内容,点击回国或右上角的“Run query”,

 1.64G的日志文件,秒极返回查询结果

 

 

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值