首页 > 其他分享 >日志监控平台搭建(Loki+promtail+grafana)

日志监控平台搭建(Loki+promtail+grafana)

时间:2022-11-22 22:15:46浏览次数:48  
标签:__ promtail Loki job loki 日志 grafana

搭建Loki+promtail+grafana日志监控平台,可以直接在grafana的UI界面查看系统应用日志,使日志查看起来更方便、快捷。


    Loki:主服务器,负责存储日志和处理查询。 

  Promtail:代理,负责收集日志并将其发送给Loki。

  Grafana:用于查询和显示日志。


1. 离线获取安装文件

  适用于内网服务器,无法访问互联网,获取安装文件后上传至服务器指定目录。

1.1  方式一:下载

Loki的GitHub地址:https://github.com/grafana/loki
配置文件官网地址:https://grafana.com/docs/loki/latest/installation/local/
Grafana下载官网:https://grafana.com/grafana/download

1.2 方式二:网盘获取

loki、promtail应用及配置文件网盘链接:https://pan.baidu.com/s/1VKw4u329nIsfKARGVa9nvg    提取码:yplj

2. 日志平台搭建

2.1 loki安装

2.1.1 下载文件

#创建目录
mkdir -p /opt/loki

#下载压缩文件
cd /opt/loki
curl -O -L https://github.com/grafana/loki/releases/download/v2.0.0/loki-linux-amd64.zip

#下载配置文件
wget --no-check-certificate https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml

#解压文件
unzip loki-linux-amd64.zip

#执行文件授权
chmod a+x loki-linux-amd64

2.1.2 修改配置文件(loki-local-config.yaml)

  配置如下:

auth_enabled: false

server:
  http_listen_port: 3100   #如是云服务需打开3100端口
  grpc_listen_port: 9096

common:
  path_prefix: /opt/loki
  storage:
    filesystem:
      chunks_directory: /opt/loki/chunks
      rules_directory: /opt/loki/rules
  replication_factor: 1
  ring:
    instance_addr: 127.0.0.1   #loki访问路径,可不做修改
    kvstore:
      store: inmemory

#query_range:
  #results_cache:
    #cache:
      #embedded_cache: false
        #enabled: false
        #distributed: false
        #max_size_mb: 100

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h

limits_config:
  enforce_metric_name: false
  reject_old_samples: true          # 是否拒绝老样本
  reject_old_samples_max_age: 336h  # 336小时之前的样本将会被删除
  ingestion_rate_mb: 32             # 每秒允许promtail传输32MB,默认为4
  ingestion_burst_size_mb: 64  
  per_stream_rate_limit: 1000MB
  max_entries_limit_per_query: 10000

chunk_store_config:
  max_look_back_period: 336h        # 为避免查询超过保留期的数据,必须小于或等于下方的时间值

table_manager:
  retention_deletes_enabled: true   # 保留删除开启
  retention_period: 336h            # 超过336h的块数据将被删除


ruler:
  alertmanager_url: http://localhost:9093

# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
#  reporting_enabled: false

2.1.3 启动loki服务

# 启动Loki命令  默认端口为 3100
nohup ./loki-linux-amd64 -config.file=loki-local-config.yaml  > loki.log 2>&1 &

2.2 promtail安装

2.1.1 下载文件

#下载压缩文件
cd /opt/loki
curl -O -L https://github.com/grafana/loki/releases/download/v2.0.0/promtail-linux-amd64.zip

#下载配置文件
wget --no-check-certificate https://raw.githubusercontent.com/grafana/loki/master/clients/cmd/promtail/promtail-local-config.yaml

#解压文件
unzip promtail-linux-amd64.zip

#执行文件授权
chmod a+x promtail-linux-amd64

2.2.2 修改配置文件(promtail-local-config.yaml)

  修改 clients, 将host改为服务器地址 ; 添加 scrape_configs 对应的 labels 进行日志收集。

  配置如下,涉及到7个应用的日志查看:

server:
  http_listen_port: 9080  #云服务器需开放9080端口
  grpc_listen_port: 0

positions:
  filename: /opt/promtail/positions.yaml   #positions存放路径在promtail工具地址下

clients:
  - url: http://192.168.0.105:3100/loki/api/v1/push    #修改为loki服务器IP

scrape_configs:
- job_name: fap
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_fap"
      __path__: /opt/cwy8.32/product/module/P/FAP/nohup.out

- job_name: portal
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_portal"
      __path__: /opt/cwy8.32/product/module/P/PORTAL/nohup.out

- job_name: cwy
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_cwy"
      __path__: /opt/cwy8.32/product/module/A/CWY/nohup.out

- job_name: fasp_register
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_fasp_register"
      __path__: /opt/cwy8.32/product/module/A/FASP/register-nohup.out

- job_name: fasp_gateway
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_fasp_gateway"
      __path__: /opt/cwy8.32/product/module/A/FASP/gateway-nohup.out

- job_name: fasp_base
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_fasp_base"
      __path__: /opt/cwy8.32/product/module/A/FASP/base-nohup.out

- job_name: fasp_web
  static_configs:
  - targets:
      - localhost
    labels:
      job: "HSJ_fasp_web"
      __path__: /opt/cwy8.32/product/module/A/FASP/web-nohup.out

2.2.3 启动promtail服务

#到收集日志的服务器上配置 Promtail 并启动,传输文件到收集日志的服务器。 Promtail默认端口是9080
nohup ./promtail-linux-amd64 -config.file=promtail-local-config.yaml > promtail.log 2>&1 &

2.3 配置grafana

2.3.1 添加loki数据源

  登入grafana,点击【设置】按钮,进入【Configuration】页面;点击右侧的【add data source】添加loki数据源

2.3.2 配置数据源url 

  点击loki数据源,配置url地址(grafana服务所在服务器的IP地址),随后点击【save&test】

2.3.3 选择日志查看选项   

点击Explore,在Explore界面选择【job】,下一步可以选择需要查看的应用日志,如下显示:

2.3.4 查看日志示例:

选择HSJ_cwy,再点击右上角【Run query】,即可查看HSJ_cwy应用的日志信息,如下:

3.  导入loki日志查看仪表板(便于查看日志)

   点击grafana左侧菜单栏【+】-【import】,进入导入dashboard页面

  导入“下载的仪表板”和“创建的数据源”,点击【import】按钮,导入成功

loki仪表板链接:https://pan.baidu.com/s/19Jm1_k029wZj1iDP-MtDGg   提取码:de09


END

 

标签:__,promtail,Loki,job,loki,日志,grafana
From: https://www.cnblogs.com/silgen/p/16916044.html

相关文章

  • 安装grafana-zabbix
    安装grafana-zabbix#联网安装方式grafana-clipluginsinstallalexanderzobnin-zabbix-appservicegrafana-serverrestart#最新4.0.1版本需要在配置文件里增加以下配......
  • Grafana中的zabbix插件界面配置
    Grafana中的zabbix插件安装步骤step1把下载的grafana-zabbix插件压缩包,解压到对应的目录下。step2确定自己已经打开grafana-server服务后,打开http://localhost:3000......
  • CentOS7安装Grafana9最新版
    1.下载安装1.1下载Grafana官网有安装及配置说明,以下内容均根据官网的说明进行安装与配置。RedHat,CentOS,RHEL,andFedora(64Bit)SHA256:d0ffb3dbbbd88ccf0fbaf......
  • Grafana9最新版新新特性
    Grafana9于6月在GrafanaCONline2022上发布,其中最大的亮点之一是引入了新的GrafanaLoki和普罗米修斯查询生成器。官网描述的新特性比较详细。VisualPrometheus查......
  • Prometheus和Grafana监控Nacos
    Nacos0.8.0版本完善了监控系统,支持通过暴露metrics数据接入第三方监控系统监控Nacos运行状态,目前支持prometheus、elasticsearch和influxdb,下面结合prometheus和grafana......
  • 通过docker部署grafana和mysql
    阅读本文需要一定的Linux,Docker与MySQL知识,例如:会启动容器,进入容器;会创建表,会使用INSERT语句,会使用SELECT语句...1.简介2.网络设置-2.1docker网络......
  • grafana连接influxdb1.8报错“error connection influxDB influxQL”
    influxdb配置没问题,grafana配置也没问题报错原因:influxdb的数据库中没有数据,连接会报这个错,当有数据时再测试连接就会正常了......
  • ASP .NET Core App.Metrics+InfluxDB+Grafana性能监控
    Grafana介绍及部署请参考这篇博客InfluxDB官网GitHubInfluxDB介绍InfluxDB是用Go语言编写的一个开源分布式时序、事件和指标数据库,无需外部依赖InfluxDB在DB-Engi......
  • ASP .NET Core 集成 Loki 记录日志
    简介GrafanaLoki是一个水平可扩展,高可用性,多租户的日志聚合系统,由Grafana团队设计和开发,基于Apatch2.0开源。其有三部分组成:Loki是主服务器,负责存储日志和处理查询......
  • docker+jmeter+grafana+influxdb搭建性能监控平台
    说明:JMeter引入BackendListener将在压测过程中实时发送统计指标数据发送到Influxdb数据库,Grafana(开源的WEB可视化看板)数据源连接到Influxdb,创建可视化看板,并实时获取......