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

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

环境

  • 分布式项目部署在windows环境下,日志分布在多台windows服务器下,日志大、且查询不便。特此搭建分布式日志收集分析查询系统。

组件介绍

  • 本套分布式日志查询系统使用loki、promtail、grafana
  • Promtail是代理,负责收集日志并将其发送给Loki。
  • Loki是主服务器,负责存储日志和处理查询。
  • Grafana用于查询和显示日志。

在windows环境上搭建过程

1 安装Grafana

  • 下载地址:https://grafana.com/grafana/download?platform=windows

  • 下载【grafana-8.0.6.windows-amd64.zip】安装包即可,并解压到【D:\myprograms\logmanager\grafana-8.0.6】

  • 进入【D:\myprograms\logmanager\grafana-8.0.6\bin】目录,双击【grafana-server.exe】启动

  • 启动成功之后,http://localhost:3000/即可

  • 初始登录账户:admin/admin

2 安装loki

  • 安装可参考 https://grafana.com/docs/loki/latest/installation/local/

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

  • 下载【loki-windows-amd64.exe.zip】安装包,并进行解压到【D:\myprograms\logmanager\loki-windows-amd64】,解压得到【loki-windows-amd64.exe】

  • 在【D:\myprograms\logmanager\loki-windows-amd64】目录下添加【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: 2020-06-22
          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
    
  • 打开cmd定位到exe目录,执行命令:.\loki-windows-amd64.exe --config.file=loki-local-config.yaml,loki服务启动成功。

    • 启动命令:

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

在这里插入图片描述

3 安装promtail

  • 安装说明:https://grafana.com/docs/loki/latest/clients/promtail/installation/

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

  • 下载【promtail-windows-amd64.exe.zip】安装包,并解压到【D:\myprograms\logmanager\promtail-windows-amd64】目录,得到【promtail-windows-amd64.exe】

  • 在【D:\myprograms\logmanager\promtail-windows-amd64】目录下添加【promtail-local-config.yaml】文件,内容如下

    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__: E:\logs\testlogs\*.log
    - job_name: system
      static_configs:
      - targets:
          - localhost
        labels:
          job: viplogs
          __path__: E:\logs\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 设置数据源

  • 进入Data Sources添加数据源,选择Loki,URL为loki的地址: http://127.0.0.1:3100 ,Name自己定义

    在这里插入图片描述
    在这里插入图片描述

  • 然后进入Explore就可以搜索查询日志了。日志查询由两部分组成:日志流选择器搜索表达式。出于性能原因,需要先通过选择日志标签来选择日志流。查询字段Log labels旁边的按钮显示了可用日志流的标签列表

    • 标签匹配符:

      • = 完全相等。

      • != 不相等。

      • =~ 正则表达式匹配。

      • !~ 不进行正则表达式匹配。

        例:{filename=“E:\logs\testlogs\1.log”}

    • 搜索表达式:

      • |= 行包含字符串。

      • != 行不包含字符串。

      • |~ 行匹配正则表达式。

      • !~ 行与正则表达式不匹配。

        例:{filename=“E:\logs\testlogs\1.log”} |~ “根据方案”

在这里插入图片描述

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值