再见笨重的ELK!这套轻量级日志收集方案要火

再见笨重的ELK!这套轻量级日志收集方案要火

首页模拟经营Idle Port更新时间:2024-06-30

转 载:macrozheng

原文链接:https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==&mid=2247492338&idx=1&sn=9d14264c1196299cfc889d08e1c51f62

之前一直使用的日志收集方案是ELK,动辄占用几个G的内存,有些配置不好的服务器有点顶不住!最近发现一套轻量级日志收集方案:Loki Promtail Grafana(简称LPG), 几百M内存就够了,而且界面也挺不错的,推荐给大家!

简介

LPG日志收集方案内存占用很少,经济且高效!它不像ELK日志系统那样为日志建立索引,而是为每个日志流设置一组标签。下面分别介绍下它的核心组件:

日志收集流程图

安装

实现这套日志收集方案需要安装Loki、Promtail、Grafana这些服务,直接使用 docker-compose 来安装非常方便。

version: "3" services: # 日志存储和解析 loki: image: grafana/loki container_name: lpg-loki volumes: - /mydata/loki/:/etc/loki/ # 修改loki默认配置文件路径 command: -config.file=/etc/loki/loki.yml ports: - 3100:3100 # 日志收集器 promtail: image: grafana/promtail container_name: lpg-promtail volumes: # 将需要收集的日志所在目录挂载到promtail容器中 - /mydata/app/mall-tiny-loki/logs/:/var/log/ - /mydata/promtail:/etc/promtail/ # 修改promtail默认配置文件路径 command: -config.file=/etc/promtail/promtail.yml # 日志可视化 grafana: image: grafana/grafana container_name: lpg-grafana ports: - 3000:3000

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: 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: /loki/boltdb-shipper-active cache_location: /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: /loki/chunks compactor: working_directory: /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: /loki/rules rule_path: /loki/rules-temp alertmanager_url: http://localhost:9093 ring: kvstore: store: inmemory enable_api: true

server: http_listen_port: 9080 grpc_listen_port: 0 positions: filename: /tmp/positions.yaml clients: - url: http://loki:3100/loki/api/v1/push scrape_configs: - job_name: system static_configs: - targets: - localhost labels: job: varlogs __path__: /var/log/*log

docker-compose up -d

[root@local-linux lpg]# docker ps |grep lpg 64761b407423 grafana/loki "/usr/bin/loki -conf…" 3 minutes ago Up 3 minutes 0.0.0.0:3100->3100/tcp lpg-loki 67f0f0912971 grafana/grafana "/run.sh" 3 minutes ago Up 3 minutes 0.0.0.0:3000->3000/tcp lpg-grafana f2d78eb188d1 grafana/promtail "/usr/bin/promtail -…" 3 minutes ago Up 3 minutes lpg-promtail 使用

接下来我们将使用LPG日志收集系统来收集SpringBoot应用的日志,SpringBoot应用基本不用做特殊配置。

spring: application: name: mall-tiny-loki logging: path: /var/logs level: com.macro.mall.tiny: debug

docker run -p 8088:8088 --name mall-tiny-loki \ -v /etc/localtime:/etc/localtime \ -v /mydata/app/mall-tiny-loki/logs:/var/logs \ -e TZ="Asia/Shanghai" \ -d mall-tiny/mall-tiny-loki:1.0-SNAPSHOT

总结

本文主要介绍了LPG日志系统的搭建及使用它收集SpringBoot应用的日志,LPG日志收集方案确实非常轻量级,性能也不错!不过如果你有对日志进行全文搜索的需求的话,还是得使用ELK系统。

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved