plg(Loki+Promtail+Grafana)监控nginx日志、messages日志监控平台
创始人
2024-05-30 01:37:30
0

登录官网:loki官网Like Prometheus, but for logs. Contribute to grafana/loki development by creating an account on GitHub.https://github.com/grafana/loki/releases/

loki安装

----root用户操作
###创建用户
useradd loki
passwd loki###创建安装目录
mkdir /opt/loki###授权
chown -R loki:loki /opt/loki
chmod -R 755 /opt/loki----loki用户操作
###下载二进制包
$ curl -O -L "https://github.com/grafana/loki/releases/download/v2.7.4/loki-linux-amd64.zip"###解压二进制包
$ unzip "loki-linux-amd64.zip"### make sure it is executable
$ chmod a+x "loki-linux-amd64"

###编写配置文件
$ vim loki-local-config.yml

更多配置请参考:https://grafana.com/docs/loki/latest/configuration/

auth_enabled: falseserver:http_listen_port: 3100grpc_listen_port: 9096ingester:lifecycler:address: 127.0.0.1ring:kvstore:store: inmemoryreplication_factor: 1final_sleep: 0schunk_idle_period: 10mchunk_retain_period: 30s
schema_config:configs:- from: 2020-05-15store: boltdbobject_store: filesystemschema: v11index:prefix: index_period: 168h
storage_config:boltdb:directory: /opt/loki/indexfilesystem:directory: /opt/loki/chunks  # 块存储路径limits_config:enforce_metric_name: falsereject_old_samples: true          # 是否拒绝老样本reject_old_samples_max_age: 168h  # 168小时之前的样本将会被删除ingestion_rate_mb: 200ingestion_burst_size_mb: 300per_stream_rate_limit: 1000MBmax_entries_limit_per_query: 10000
chunk_store_config:max_look_back_period: 168h        # 为避免查询超过保留期的数据,必须小于或等于下方的时间值
table_manager:retention_deletes_enabled: true   # 保留删除开启retention_period: 168h            # 超过168h的块数据将被删除ruler:storage:type: locallocal:directory: /opt/loki/rulesrule_path: /opt/loki/rules-tempalertmanager_url: http://192.168.0.1:9093    # alertmanager地址ring:kvstore:store: inmemoryenable_api: trueenable_alertmanager_v2: true

启动脚本

$ vim restart-loki.sh

#!/bin/bash
echo "stop loki"
ps -ef | grep loki-linux-amd64 | grep -v grep | awk '{print $2}'| xargs kill -9 echo "Begin start loki"
sleep 1
str=$"\n"
nohup ./loki-linux-amd64 --config.file=loki-local-config.yml &
sstr=$(echo -e $str)
echo $sstr

增加执行权限

chmod +x restart-loki.sh

在需要采集日志的主机上都安装Promtail

mkdir /opt/promtail
chown -R loki:loki /opt/promtail
chmod -R loki:loki /opt/promtail###下载
curl -O -L "https://github.com/grafana/loki/releases/download/v2.7.4/promtail-linux-amd64.zip"###解压
unzip loki-linux-amd64.zip # 解压###
mv promtail-linux-amd64 /usr/local/sbin/promtail # 挪到 $PATH下

编写配置文件,vim promtail-local-config.yml

server:http_listen_port: 9080grpc_listen_port: 0positions:filename: /opt/promtail/positions.yamlclients:- url: http://10.1.5.125:3100/loki/api/v1/push # 填写好Loki地址scrape_configs:
- job_name: messagelogstatic_configs:- targets:- localhostlabels:#job: messageloghost: namenode01__path__: /var/log/messages- job_name: agentlogstatic_configs:- targets:- localhostlabels:#job: agentloghost: namenode01__path__: /ssd/ssd0/agentlog/agent.log- job_name: datanodelogstatic_configs:- targets:- localhostlabels:
#      #job: datanodeloghost: namenode01__path__: /ssd/ssd0/datanodelog/*datanode*.log

Download Grafana | Grafana LabsOverview of how to download and install different versions of Grafana on different operating systems.https://grafana.com/grafana/download

###CentOS系统通过rpm方式安装wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.3-1.x86_64.rpmsudo yum install grafana-enterprise-9.4.3-1.x86_64.rpm -y[root@localhost grafana]# rpm -qa|grep grafana
grafana-enterprise-9.4.3-1.x86_64
[root@localhost grafana]# ###启动grafana,grafana会占用服务器3000端口
systemctl start grafana-server.servicesystemctl status grafana-server.service

导入nginx dashboard

Grafana Loki Dashboard for NGINX Service Mesh | Grafana LabsLoki v2+ showcase using JSON NGINX access logs.https://grafana.com/grafana/dashboards/12559-grafana-loki-dashboard-for-nginx-service-mesh/

参考:简易日志系统LPG生产环境实践指南 | 坑我已经帮你们踩好了

参考:PLG日志平台搭建: Promtail + Loki + Grafana 全步骤_promtail loki_dxccccccccccc的博客-CSDN博客

参考:Promtail + Loki + Grafana 构建日志监控告警系统(一)_promtail+loki_5D金豆豆的博客-CSDN博客

参考:

PLG日志平台搭建: Promtail + Loki + Grafana 全步骤_promtail loki_dxccccccccccc的博客-CSDN博客

参考:

搭建Loki、Promtail、Grafana轻量级日志系统(centos7)_loki promtail_成钰的博客-CSDN博客

参考:

轻量日志收集系统loki_loki日志收集_wyl9527的博客-CSDN博客

参考:

轻量级日志可视化平台Grafana Loki接入nginx访问日志-阿里云开发者社区

参考:

PLG 云原生日志系统在压测中的落地实践 · TesterHome

参考:

快速部署Grafana日志监控+Nginx封禁IP-阿里云开发者社区

参考:

使用使用grafana中文插件-阿里云开发者社区

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...