砍材农夫砍材农夫
  • 微信记账小程序
  • java
  • redis
  • mysql
  • 场景类
  • 框架类
  • vuepress搭建
  • hexo搭建
  • 云图
  • llm wiki

    • 基于karpathy
    • gradle
  • 常用工具

    • git
    • gradle
    • Zadig
    • it-tools
    • 开源推荐
    • curl
  • 大前端

    • 环境配置
    • 微信生态
    • 正则
    • 全栈技能
  • java圈

    • java基础
    • jdk体系
    • jvm
    • spring框架
    • 分库分表
    • zookeeper
  • python技能

    • python编程
    • python数据
  • 算法

    • 算法
  • 网关

    • spring_cloud_gateway
    • openresty
  • 高可用

    • 秒杀
    • 分布式
    • 缓存一致
  • MQ

    • MQ
    • rabbitMQ
    • rocketMQ
    • kafka
  • 其它

    • 设计模式
    • 领域驱动(ddd)
  • 关系型数据库

    • mysql5.0
    • mysql8.0
  • 非关系型数据库

    • redis
    • mongoDB
  • 分布式/其他

    • ShardingSphere
    • 区块链
  • 向量数据库

    • M3E
    • OPEN AI
  • Jmeter
  • fiddler
  • wireshark
  • AI入门
  • AI大模型
  • AI插件
  • AI集成框架
  • 相关算法
  • AI训练师
  • 量化交易
  • AIoT
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 相关运营
  • devops
  • 元宇宙
  • 区块链
  • 物联网
  • webrtc
  • web3.0
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 中考
  • 投资
  • 保险
  • 思
  • 微信记账小程序
  • java
  • redis
  • mysql
  • 场景类
  • 框架类
  • vuepress搭建
  • hexo搭建
  • 云图
  • llm wiki

    • 基于karpathy
    • gradle
  • 常用工具

    • git
    • gradle
    • Zadig
    • it-tools
    • 开源推荐
    • curl
  • 大前端

    • 环境配置
    • 微信生态
    • 正则
    • 全栈技能
  • java圈

    • java基础
    • jdk体系
    • jvm
    • spring框架
    • 分库分表
    • zookeeper
  • python技能

    • python编程
    • python数据
  • 算法

    • 算法
  • 网关

    • spring_cloud_gateway
    • openresty
  • 高可用

    • 秒杀
    • 分布式
    • 缓存一致
  • MQ

    • MQ
    • rabbitMQ
    • rocketMQ
    • kafka
  • 其它

    • 设计模式
    • 领域驱动(ddd)
  • 关系型数据库

    • mysql5.0
    • mysql8.0
  • 非关系型数据库

    • redis
    • mongoDB
  • 分布式/其他

    • ShardingSphere
    • 区块链
  • 向量数据库

    • M3E
    • OPEN AI
  • Jmeter
  • fiddler
  • wireshark
  • AI入门
  • AI大模型
  • AI插件
  • AI集成框架
  • 相关算法
  • AI训练师
  • 量化交易
  • AIoT
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 相关运营
  • devops
  • 元宇宙
  • 区块链
  • 物联网
  • webrtc
  • web3.0
  • gitee
  • github
  • infoq
  • osc
  • 砍材工具
  • 关于
  • 中考
  • 投资
  • 保险
  • 思
  • nginx

    • nginx日常

      • 概念
      • 常用命令
      • nginx安装和部署
    • nginx实战

      • 基本配置拆解
      • 配置https证书
      • nginx负载配置
  • linuxs

    • 基础

      • 常用命令
      • grep
      • 防火墙
      • 基础常用命令
      • linux基础常用命令2
      • 配置应用自动启动
      • 自动同步北京时间
      • 防火墙操作
      • ifconfig无ip
      • Rocky-8无网络和局域网无法访问
    • 高级

      • 常用命令
      • vm虚拟机磁盘扩容
      • jdk安装
      • centos7 不显示IP
      • linux分析问题常用命令
      • linux任务管理
      • 权限控制
      • 记录用户操作日志
      • 日常分析问题命令介绍
      • 网络配置
      • cached过高问题
      • 找回删除文件
      • cpu负载突然升高
      • 磁盘爆满查找大文件
      • CentOS7系统配置国内yum源和epel源
    • vi

    • curl

  • docker

    • 基础
      • 安装和配置

        • window相关安装和配置
        • window基础简单操作
        • linux安装
      • 相关命令

        • 相关概念
        • 相关命令
        • docker镜像相关命令
      • 安装实例

        • 安装elasticsearch
        • docker其他常见快速部署
        • docker搭建Jenkins
        • docker搭建mysql
        • docker备份mysql
        • docker更改mysql配置
        • docker搭建nexus
      • 其他

        • 镜像的迁移和备份
        • 构建私有仓库
        • 网络
        • 常见错误集
        • docker部署hdfs
        • docker容器时间和本地时间不一致
        • docker批量操作
    • 日常运维案例

      • docker实例内文件下载
    • docker-file

      • dockerfile入门
      • dockerfile案例(springboot)
    • docker-compose

      • docker-compose意义
  • k8s

    • 首页
      • window相关安装和配置
      • window基础简单操作
  • haproxy

    • haproxy部署实战

      • haproxy部署介绍
      • haproxy部署实战
      • haproxy案例分析
  • jenkins

    • jenkins实战

      • 发布sheel脚本
      • 版本升级或重装备份问题
      • 多模块关联关闭
      • 环境搭建
      • 获取远程git项目|分支选择
      • 权限管理
      • 项目获取远程java项目并发布
      • 获取web项目并发布
      • 集成maven获取远程项目
      • 进行视图细粒度权限管理
  • prometheus

    • 首页
      • window相关安装和配置
      • window基础简单操作
  • gitlab

    • 首页
      • window相关安装和配置
      • window基础简单操作
  • maven

    • 首页
      • window相关安装和配置
      • window基础简单操作
  • elk

    • openobserve

      • docker部署openobserve
      • 采集器fluent
      • openobserve日常管理使用
  • 运维|devops|openobserve+Fluent Bit (日志采集和打标)
    • Fluent Bit和Fluentd区别
    • Fluent Bit 拆解说明
    • 最新配置示例
    • demo示例
    • 多应用指定tag用于快速检索
    • 避免重复采集
    • 数据格式化-抽离检索关键字
      • Parser(解析器)
      • 示例
      • 实战如下
      • parsers.conf
      • 检测parsers.conf是否正确加载
      • conf文件
      • 验证结果
    • 调整采用过滤方式(将parser调整为FILTER)
      • 验证结果

运维|devops|openobserve+Fluent Bit (日志采集和打标)

Fluent Bit和Fluentd区别

特性Fluent BitFluentd
定位轻量级的数据采集与转发器(Agent)统一日志层,强大的数据聚合与路由器(Aggregator)
开发语言C 语言C 和 Ruby
资源占用极低,初始内存约 450KB较高,初始内存约 40-60MB
性能高性能,处理速度可比Fluentd快 10到40倍高性能
插件生态内置 超过100种 插件拥有 超过1000种 外部插件
适用场景资源受限环境(边缘设备、嵌入式)、容器/K8s中心化日志服务器、复杂数据处理管道
OpenTelemetry原生支持 OTLP 数据的接收和发送需要通过插件支持

Fluent Bit 拆解说明

  • [SERVICE] (服务段落)

定义 Fluent Bit 服务本身的全局行为

  • [INPUT] (输入段落)

定义数据源,比如从哪里读取日志(如 tail 插件监控文件,cpu 插件采集指标),Name 和 Tag 是常见配置项

  • [FILTER] (过滤段落)

(可选) 在数据发送前对其进行修改或增强,Name 和 Match/Match_Regex 是必填项

  • [OUTPUT] (输出段落)

定义数据的目的地,比如发送到 OpenObserve、标准输出或文件

最新配置示例

[SERVICE]
    # 服务段落:全局配置
    Flush         1     # 刷新间隔,单位秒[reference:21]
    Daemon        off   # 是否以后台进程运行[reference:22]
    Log_Level     info  # 日志级别[reference:23]

[INPUT]
    # 输入段落:数据来源
    Name          cpu   # 使用 cpu 输入插件[reference:24]
    Tag           my_cpu # 给数据打上标签,用于路由[reference:25]

[OUTPUT]
    # 输出段落:数据目的地
    Name          stdout # 输出到标准输出(控制台)[reference:26]
    Match         my_cpu # 匹配具有相同 Tag 的数据[reference:27]

demo示例

[SERVICE]
    Flush       5
    Log_Level   info

[INPUT]
    Name          tail
    Path          /data/log/api-gateway.log
    Tag           gateway
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On

[OUTPUT]
    Name             http
    Match            gateway
    Host             192.168.0.20
    Port             5080
    URI              /api/default/default/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

img

多应用指定tag用于快速检索

[SERVICE]
    Flush       1
    Log_Level   info

[INPUT]
    Name          tail
    Path          /data/log/api-gateway.log
    Tag           gateway
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On

[INPUT]
    Name          tail
    Path          /data/log/core.log
    Tag           core
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On

[OUTPUT]
    Name             http
    Match            gateway
    Host             192.168.0.20
    Port             5080
    URI              /api/default/gateway/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

[OUTPUT]
    Name             http
    Match            core
    Host             192.168.0.20
    Port             5080
    URI              /api/default/core/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

img

避免重复采集

Fluent Bit用SQLite数据库来记录每个日志文件的读取位置(偏移量)

  • 无DB

重启后从尾部读取,不会重复发送旧数据,但可能出现极短时间窗口内的重复(例如在 Fluent Bit 发送过程中突然崩溃,部分数据已发送但未标记完成,重启后从尾部开始,那些未标记的数据可能因文件偏移未更新而丢失,但不会重复)

  • 启用DB后

彻底避免重复,且能保证“断点续传”

[SERVICE]
    Flush       1
    Log_Level   info

[INPUT]
    Name          tail
    Path          /data/log/api-gateway.log
    Tag           gateway
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On
    DB            /data/log/tail_gateway.db

[INPUT]
    Name          tail
    Path          /data/log/core.log
    Tag           core
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On
    DB            /data/log/tail_core.db

[OUTPUT]
    Name             http
    Match            gateway
    Host             192.168.0.20
    Port             5080
    URI              /api/default/gateway/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

[OUTPUT]
    Name             http
    Match            core
    Host             192.168.0.20
    Port             5080
    URI              /api/default/core/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

数据格式化-抽离检索关键字

Parser(解析器)

  • 输入一条非结构化的日志文本
192.168.2.20 - - [28/Jul/2006:10:27:10 -0300] "GET /cgi-bin/try/ HTTP/1.0" 200 3395
  • 输出一个结构化的 JSON 对象
{"host": "192.168.2.20", "user": "-", "method": "GET", ...}

示例

  • 在 [SERVICE] 部分加载解析器配置文件
[SERVICE]
    Flush        1
    Log_Level    info
    # 加载刚才定义的解析器配置文件
    Parsers_File /etc/fluent-bit/parsers.conf
  • 在 [INPUT] 中指定使用哪个解析器
[INPUT]
    Name          tail
    Path          /data/test/log/api-gateway.log
    Tag           gateway
    # 指定使用名为 springboot-parser 的解析器
    Parser        springboot-parser
    # ... 其他配置

实战如下

  • 样例日志
2026-07-13 17:20:52.096 [scheduling-1] [1273acbc-49ff-4b4a-992f-8ee290d1a7ad] INFO  com.test.scheduler.HangerAGoRoundJob - 开始执行任务:无人复飞监控
2026-07-13 17:20:52.099 [scheduling-1] [1273acbc-49ff-4b4a-992f-8ee290d1a7ad] INFO  com.test.scheduler.HangerAGoRoundJob - 设备数量: 0
2026-07-13 17:20:52.100 [scheduling-1] [1273acbc-49ff-4b4a-992f-8ee290d1a7ad] INFO  com.test.common.util.TraceIdUtil - 日志 清理...
2026-07-13 17:20:52.100 [scheduling-1] [08bcfba5-b648-4426-9628-615e2a4e1443] INFO  com.test.scheduler.HangerAShutDownJob - 开始执行任务:无人机 先关机 后 充电
2026-07-13 17:20:52.103 [scheduling-1] [08bcfba5-b648-4426-9628-615e2a4e1443] INFO  com.test.scheduler.HangerAShutDownJob - 待处理设备:0
2026-07-13 17:20:52.105 [scheduling-1] [08bcfba5-b648-4426-9628-615e2a4e1443] INFO  com.test.common.util.TraceIdUtil - 日志 清理...

parsers.conf

[PARSER]
    Name        app-parser
    Format      regex
    Regex       ^ (?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}) \s+ \[(?<thread>[^\]]*)\] \s+ \[(?<traceId>[^\]]*)\] \s+ (?<level>[^\s]+) \s+ (?<class>[^\s]+) \s+ - \s+ (?<message>.*)$
    Time_Key    time
    Time_Format %Y-%m-%d %H:%M:%S.%L

检测parsers.conf是否正确加载

/opt/fluent-bit/bin/fluent-bit  -c /data/log/fluent-bit.conf -vv

conf文件

[SERVICE]
    Flush        1
    Log_Level    info
    Parsers_File /data/log/parsers.conf

[INPUT]
    Name          tail
    Path          /data/log/api-gateway.log
    Tag           gateway
    Parser        app-parser
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On
    DB            /data/log/tail_gateway.db

[INPUT]
    Name          tail
    Path          /data/log/core.log
    Tag           core
    Parser        app-parser
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On
    DB            /data/log/tail_core.db

[OUTPUT]
    Name             http
    Match            gateway
    Host             192.168.0.20
    Port             5080
    URI              /api/default/gateway/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

[OUTPUT]
    Name             http
    Match            core
    Host             192.168.0.20
    Port             5080
    URI              /api/default/core/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

验证结果

img

调整采用过滤方式(将parser调整为FILTER)

  • 完整的 fluent-bit.conf
[SERVICE]
    Flush        1
    Log_Level    info
    Parsers_File /data/log/parsers.conf

[INPUT]
    Name          tail
    Path          /data/log/api-gateway.log
    Tag           gateway
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On
    DB            /data/log/tail_gateway.db

[INPUT]
    Name          tail
    Path          /data/log/core.log
    Tag           core
    Refresh_Interval 10
    Mem_Buf_Limit 50MB
    Skip_Long_Lines On
    DB            /data/log/tail_core.db

[FILTER]
    Name     parser
    Match    gateway
    Key_Name log
    Parser   app-parser
    Reserve_Data On

[FILTER]
    Name     parser
    Match    core
    Key_Name log
    Parser   app-parser
    Reserve_Data On

[OUTPUT]
    Name   stdout
    Match  *
    Format json_lines

[OUTPUT]
    Name             http
    Match            gateway
    Host             192.168.0.20
    Port             5080
    URI              /api/default/gateway/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

[OUTPUT]
    Name             http
    Match            core
    Host             192.168.0.20
    Port             5080
    URI              /api/default/core/_json
    Format           json
    json_date_key    timestamp
    json_date_format iso8601
    HTTP_User        admin@example.com
    HTTP_Passwd      YourP@ssw0rd#123
    tls              off
    compress         gzip
    net.connect_timeout 10s
    net.io_timeout     10s
    retry_limit        5

验证结果

img

最近更新: 2026/7/14 09:24
Contributors: kcnf
Prev
docker部署openobserve
Next
openobserve日常管理使用