[loki]轻量级日志聚合系统loki快速入门
前言
- 简述:loki是由grafana开源的日志聚合系统,相较于ELK、EFK更轻量。
- loki特性:
- 不对日志进行全文索引。通过存储压缩非结构化日志和仅索引元数据,Loki 操作起来会更简单,更省成本。
- 通过使用与 Prometheus 相同的标签记录流对日志进行索引和分组,这使得日志的扩展和操作效率更高,能对接 alertmanager;
- 特别适合储存 Kubernetes Pod 日志;诸如 Pod 标签之类的元数据会被自动删除和编入索引;
- Grafana原生支持
- 版本:
- 系统:centos7
- loki:2.6.1
- promtail:2.6.1
- grafana: 8.3.3
本文以loki监控nginx日志为例。nginx日志所在目录为 /home/admin/apps/nginx/logs/
安装loki
docker方式
PS: 未经测试
docker pull grafana/loki
wget https://raw.githubusercontent.com/grafana/loki/v2.6.1/cmd/loki/loki-local-config.yaml -O loki-config.yaml
docker run --name loki -d -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.6.1 -config.file=/mnt/config/loki-config.yaml
二进制方式
- 官方GitHub仓库的Release页下载压缩包并解压
- 编辑loki-config.yaml
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
ingester:
wal:
enabled: true
dir: /home/apps/loki/wal
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed
max_chunk_age: 1h # All chunks will be flushed when they hit this age, default is 1h
chunk_target_size: 1048576 # Loki will attempt to build chunks up to 1.5MB, flushing first if chunk_idle_period or max_chunk_age is reached first
chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m)
max_transfer_retries: 0 # Chunk transfers disabled
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
storage_config:
boltdb_shipper:
active_index_directory: /home/apps/loki/boltdb-shipper-active
cache_location: /home/apps/loki/boltdb-shipper-cache
cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space
shared_store: filesystem
filesystem:
directory: /home/apps/loki/chunks
compactor:
working_directory: /home/apps/loki/boltdb-shipper-compactor
shared_store: filesystem
limits_config:
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
ruler:
storage:
type: local
local:
directory: /home/apps/loki/rules
rule_path: /home/apps/loki/rules-temp
alertmanager_url: http://localhost:9093
ring:
kvstore:
store: inmemory
enable_api: true
- 启动
./loki -config.file=loki-config.yaml > /dev/null 2>&1 &
安装promtail
docker方式
PS: 未经测试
wget https://raw.githubusercontent.com/grafana/loki/v2.6.1/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
docker run --name promtail -d -v $(pwd):/mnt/config -v /var/log:/var/log --link loki grafana/promtail:2.6.1 -config.file=/mnt/config/promtail-config.yaml
二进制方式
- 官方GitHub仓库Release页下载压缩包并解压
- 编辑promtail-config.yaml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://192.168.2.249:3100/loki/api/v1/push
scrape_configs:
- job_name: nginx
static_configs:
- targets:
- 192.168.2.249
labels:
job: varlogs
__path__: /home/admin/apps/nginx/logs/*log
- 启动
nohup ./promtail -config.file=promtail-config.yaml > /dev/null 2>&1 &
安装grafana
- 创建容器并运行
docker pull 'grafana/grafana:latest'
docker run --name grafana -p 3000:3000 -d 'grafana/grafana:latest'
- 浏览器访问ip:3000,账密默认为:admin/admin
- 配置loki数据源

参考
- 微信公众号 - 高效运维 - 轻量级日志Loki全攻略,再也不会整懵了
- 知乎 - 平凡人笔记 - 轻量级日志系统Loki原理简介和使用
- 稀土掘金 - ik - Loki+Promtail+Grafana我们不是LSP
[loki]轻量级日志聚合系统loki快速入门的更多相关文章
- 安装 loki 轻量级日志监控系统
文章转载自:https://www.cnblogs.com/flypig666/archive/2004/01/13/14151801.html 从本文中学习到的是docker-compose相关命令 ...
- 搭建Loki、Promtail、Grafana轻量级日志系统(centos7)
搭建Loki.Promtail.Grafana轻量级日志系统(centos7)--简称PLG 需求 公司项目采用微服务的架构,服务很多,每个服务都有自己的日志,分别存放在不同的服务器上.当查找日志时需 ...
- 10分钟学会使用 Loki 日志聚合系统
Loki 是一个由Grafana Labs 开发的开源日志聚合系统,旨在为云原生架构提供高效的日志处理解决方案. Loki 通过使用类似 Prometheus 的标签索引机制来存储和查询日志数据,这使 ...
- Centos部署Loki日志聚合系统
关于一些日志聚合由来及原理科普见我的另外一篇 <编程入门之日志聚合系统> https://www.cnblogs.com/uncleguo/p/15948763.html Loki日志聚合 ...
- 轻量级日志收集方案Loki
先看看结果有多轻量吧 官方文档:https://grafana.com/docs/loki/latest/ 简介 Grafana Loki 是一个日志聚合工具,它是功能齐全的日志堆栈的核心. Loki ...
- 使用 Loki 进行日志报警(一)
转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247492352&idx=1&sn=9c0cc7927b ...
- Grafana 系列文章(九):开源云原生日志解决方案 Loki 简介
简介 Grafana Labs 简介 Grafana 是用于时序数据的事实上的仪表盘解决方案.它支持近百个数据源. Grafana Labs 想从一个仪表盘解决方案转变成一个可观察性 (observa ...
- 【xAsset框架】HFS 轻量级HTTP Server快速入门指南
一.引子 最近马三有幸参与开发了一个简易轻量的Unity资源管理框架 xAsset ,xasset 提供了一种使用资源路径的简单的方式来加载资源,简化了Unity项目资源打包,更新,加载,和回收的作业 ...
- ELK快速入门(四)filebeat替代logstash收集日志
ELK快速入门四-filebeat替代logstash收集日志 filebeat简介 Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到log ...
- ELK快速入门(二)通过logstash收集日志
ELK快速入门二-通过logstash收集日志 说明 这里的环境接着上面的ELK快速入门-基本部署文章继续下面的操作. 收集多个日志文件 1)logstash配置文件编写 [root@linux-el ...
随机推荐
- mysql-高级功能(触发器、存储过程、视图、事务)
目录 触发器-created trigger 1.触发器分为六种情况 2.语法结构 3.创建触发器 4.查询/删除触发器 存储过程-created procedure 1.创建存储过程 2.使用存储过 ...
- Lattics:一款简单易用、好看强大的「类脑式」知识管理工具,笔记应用与写作软件二合一
如何选择一款适合自己的知识管理工具? 随着数字化时代的到来,越来越多的人意识到知识管理的重要性.笔记软件和写作软件作为一种常用的知识管理工具,一直以来备受关注.从最早的印象笔记.有道云.为知笔记.幕布 ...
- python库Munch的使用记录
开头 日常操作字典发现发现并不是很便利,特别是需要用很多 get('xxx','-') 的使用,就觉得很烦,偶然看到Kuls大佬公众号发布的一篇技术文有对 python munch库的使用, 使得字典 ...
- 2021-04-04:给定一个非负数组arr,和一个正数m。 返回arr的所有子序列中累加和%m之后的最大值。
2021-04-04:给定一个非负数组arr,和一个正数m. 返回arr的所有子序列中累加和%m之后的最大值. 福大大 答案2021-04-04: 自然智慧即可. 1.递归,累加和. 2.动态规划,累 ...
- Java 网络编程 —— 非阻塞式编程
线程阻塞概述 在生活中,最常见的阻塞现象是公路上汽车的堵塞.汽车在公路上快速行驶,如果前方交通受阻,就只好停下来等待,等到公路顺畅,才能恢复行驶. 线程在运行中也会因为某些原因而阻塞.所有处于阻塞状态 ...
- ChatGPT 推出 iOS 应用,支持语音输入,使用体验如何?
最近,OpenAI 宣布推出官方 iOS 应用,允许用户随时随地访问其高人气 AI 聊天机器人,此举也打破了近几个月内苹果 App Store 上充斥似是而非的山寨服务的窘境. 该应用程序是 Chat ...
- Python竖版大屏 | 用pyecharts开发可视化的奇妙探索!
你好!我是@马哥python说,一枚10年程序猿,正在试错用pyecharts开发可视化大屏的非常规排版. 以下,我用8种ThemeType展示的同一个可视化数据大屏. 1.SHINE主题 2.LI ...
- Scalpel:解构API复杂参数Fuzz的「手术刀」
Scalpel简介 Scalpel是一款自动化Web/API漏洞Fuzz引擎,该工具采用被动扫描的方式,通过流量中解析Web/API参数结构,对参数编码进行自动识别与解码,并基于树结构灵活控制注入位点 ...
- 记一次BootCDN被黑产挂马导致站点跳转博彩网站的问题
近期发现公司某些站点出现偶尔跳转博彩网站的现象,经过排查发现该现象为供应链投毒攻击,BootCDN上的静态资源无一例外均被污染, 当外站引入BootCDN的静态资源时,如果请求携带的Referer头为 ...
- selenium-wire简介
一.简介 以下来自chatGPT回答: selenium-wire是一个基于selenium的Python库,它扩展了selenium的功能,使得我们可以在自动化测试中直接访问和修改浏览器的网络请求和 ...