温馨提示×

Debian上Filebeat配置文件详解

小樊
93
2025-02-14 20:41:01
栏目: 智能运维
Debian服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Debian上配置Filebeat主要涉及编辑/etc/filebeat/filebeat.yml文件。以下是一个基本的配置文件示例及其详解:

filebeat.inputs:
- type: log
  paths:
    - /var/log/*.log
  exclude_files: ['*.gz']
  fields:
    app_id: my_app
  fields_under_root: true

output.elasticsearch:
  hosts: ["localhost:9200"]
  index: "filebeat-%{+YYYY.MM.dd}"
  document_type: my_custom_type

配置详解

  • filebeat.inputs

    • type: 指定输入类型,这里使用的是log,表示从日志文件中读取数据。
    • paths: 指定要监控的日志文件路径,可以使用通配符。
    • exclude_files: 排除某些文件类型,例如这里的.gz文件。
    • fields: 向输出的每条日志添加额外的信息,例如app_id
    • fields_under_root: 设置为true时,新增的fields会成为顶级目录,而不是放在fields目录下。
  • output.elasticsearch

    • hosts: 指定Elasticsearch的地址和端口。
    • index: 指定Elasticsearch中的索引名称,可以使用动态模板。
    • document_type: 指定输出到Elasticsearch时的文档类型。

其他重要配置项

  • global.config_dir

    • 定义Filebeat配置文件目录,可以在此目录下放置其他配置文件,这些文件中的全局配置会被忽略。
  • harvester.buffer_size

    • 每个harvester监控文件时使用的buffer大小。
  • harvester.max_bytes

    • 日志文件中增加一行算一个日志事件,max_bytes限制在一次日志事件中最多上传的字节数,多出的字节会被丢弃。
  • multiline.pattern

    • 定义多行匹配的模式,适用于日志中每一条日志占据多行的情况。
  • multiline.negate

    • 是否需要对pattern条件取反。
  • multiline.match

    • 定义多行内容被添加到模式匹配行之后还是之前。
  • multiline.max_lines

    • 合并的最多行数,超过定义行数后的行会被丢弃。
  • multiline.timeout

    • 多行匹配超时时间,超过超时时间后的当前多行匹配事件将停止并发送。
  • multiline.tail_files

    • 设置为true时,Filebeat从文件尾开始监控文件新增内容。
  • close_renamed

    • 当文件被重命名或被轮询时关闭重命名的文件处理。
  • close_removed

    • 如果文件不存在,立即关闭文件处理。
  • ignore_older

    • 指定Filebeat忽略指定时间段以外修改的日志内容。
  • close_older

    • 如果一个文件在某个时间段内没有发生过更新,则关闭监控的文件handle。
  • force_close_files

    • Filebeat会在没有到达close_older之前一直保持文件的handle。
  • scan_frequency

    • Filebeat以多快的频率去prospector指定的目录下面检测文件更新。
  • document_type

    • 设定Elasticsearch输出时的document的type字段。

以上就是Debian上Filebeat配置文件的基本详解,根据实际需求,您可能还需要进行更多的配置。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Linux Filebeat配置文件详解

0