首页 > 其他分享 >工作总结之loki篇

工作总结之loki篇

时间:2022-12-24 18:25:59浏览次数:55  
标签:总结 promtail chunk grafana 工作 loki 日志 store

目录

复盘loki的安装与项目的调通

前言

为什么要装这个呢,完全是因为他相比于其他主流的日志框架,占用内存少,其他的比如:ELK、Graylog动辄几个G,完全吃不消,还想要能够多人同时看到日志,所以选择了只占几百M内存的loki。
然后这些框架,其实都是开源的,区别就是功能的问题,笔者只需要看日志,因此,loki就行了。

架构分析

loki相当于一个库,promtail是一个日志收集器,grafana是一个可视化界面

安装

这次安装有了之前Jenkins的经验,在安装之前找了大量的资料,以防后面出现很多意料之外的问题。
参考教程:
https://zhuanlan.zhihu.com/p/391302537
https://juejin.cn/post/7008424451704356872
笔者是使用docker-compose的方法,基本上照着第一篇文章走,不会有太大的问题。
笔者的配置文件如下:
docker-compose.yml

version: '3.3'

services:
  # 日志存储和解析
  loki:
    image: grafana/loki
    container_name: lpg-loki
    privileged: true
    volumes:
      - /usr/local/lpg/loki/:/etc/loki/
    # 修改loki默认配置文件路径
    command: -config.file=/etc/loki/loki.yml
    ports:
      - 3100:3100

  # 日志收集器
  promtail:
    image: grafana/promtail
    container_name: lpg-promtail
    privileged: true
    volumes:
      # 将需要收集的日志所在目录挂载到promtail容器中
      - /mydata/app/logs/admin/:/var/log/admin/
      - /mydata/app/logs/business/:/var/log/business/
      - /usr/local/lpg/promtail:/etc/promtail/
    # 修改promtail默认配置文件路径
    command: -config.file=/etc/promtail/promtail.yml

  # 日志可视化
  grafana:
      image: grafana/grafana
      container_name: lpg-grafana
      privileged: true
      ports:
        - 3001:3000

loki.yml

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
  wal:
    enabled: true
    dir: /loki/wal

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

promtail.yml

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

遇到的问题归总

  • "error running loki" err="mkdir wal: permission denied
    原因:默认情况下,docker自己内部创建wal目录的时候失败
    解决方法:在配置文件中增加创建/loki/wal目录的配置。这个解决方法还是fq在github上找到的,所以啊,小众的日志框架的缺陷就是前人的经验较少,要么用特殊方法,要么自己摸索
    https://github.com/grafana/loki/issues/2018
    https://github.com/grafana/loki/issues/4704
  • docker将项目日志挂载到宿主机失败(项目启动创建日志文件的时候,会报Permission denied,权限不够)
    原因:根据报错信息的提示,应该是权限不够,有可能根Jenkins的用户配置不是root有关
    解决方法:两种,1.改Linux的配置,但是需要重启机器,不推荐,2.docker启动项目时,增加以特权方式启动的配置
    https://www.cncsto.com/article/558
    https://so.muouseo.com/qa/8m52rm4dq0wr.html
  • 在界面配置loki的时候,填写ip+端口不起作用
    解决方法:填写loki的域名去连接,这也是自己试出来的

结语

基本上就这些了,一定要注意promtail的目录挂载。笔者的项目是结合了logback输出的日志使用的,虽然最后这个日志框架配置好,可以正常使用了,但是因为logback的分级日志的原因,一个日志文件暂时不能看到所有控制台的输出,然后上级又不允许我降低日志文件的等级(这样,一个文件可以尽可能的多记录包括debug、info、error等信息),理由是,正式环境和测试环境不允许这样配置,呵呵。

标签:总结,promtail,chunk,grafana,工作,loki,日志,store
From: https://www.cnblogs.com/xxg98/p/17003148.html

相关文章

  • CS3331软件工程课程总结
     经过软件工程课程的一整个学期的学习,我基本掌握了进行软件工程实践的基本理论知识,在传统方法学中,我学到了如何进行可行性研究、需求分析、对软件进行形式化说明、总体设......
  • "你帮我助"软件开发Final-总结
    在这个开发过程中,我不仅学会了很多Python的实用编程知识,也利用了《软件工程》这门课的内容使我的开发过程思路更加清晰,明确的分为4个类:登录、注册、管理用户、普通用户......
  • 《wireshark网络分析的艺术》总结
    《wireshark网络分析的艺术》《linux为什么卡住了?》现象:ssh登陆某些linux服务器时,输完用户名会卡住10秒抓包分析:发现linux服务器会向dns服务器进行进行反向解析(进行2......
  • 我的2022年个人总结
    前言去年8月份到今年年初,可以算是这几年来过得最愉快、最充实的一段时间,在去年年底所写的个人总结博客开篇中,也很容易看出自己当时的良好状态:去年上半年,由于上家公司的......
  • Java 做项目能用到 List 的场景,这篇总结全了
    本文为掘金社区首发签约文章,14天内禁止转载,14天后未获授权禁止转载,侵权必究!List代表有顺序的一组元素,顺序代表遍历元素时是有顺序的,先放进List的元素会先被遍历到,这......
  • 软工学期加分总结
    开学实验测试2022-9-02需求分析小测前52022-9-20极限测试前152022-10-4民航测试前102022-10-18旅游测试第72022-10-25河北科技厅测试第三......
  • 分布式开源工作流引擎有什么特点?
    在竞争越来越激烈的社会中,拥有提质增效的办公软件,可以为企业带来更可观的市场价值。分布式开源工作流引擎在企业数字化发展进程中深受欢迎,在帮助企业提升办公效率上发挥了......
  • 一个微软工作的工程师对面试者的忠告
    Oy.IworkedatMicrosoftforabout8years(1yearofthatwascomingbackasacontractorafterleavingapermanentposition).DuringthattimeIwentthro......
  • 实习总结(第四天)
    1、ResponseEntityResponseEntity可以作为controller的返回值,比如对于一个处理下载二进制文件的接口。ResponseEntity继承了HttpEntity类,HttpEntity代表一个http请求或者......
  • Kubernetes控制器的工作原理
    Kubernetes的核心就是控制理论,Kubernetes控制器中实现的控制回路是一种闭环反馈控制系统,该类型的控制系统基于反馈回路将目标系统的当前状态与预定义的期望状态相比较,二者......