filebeat.idle_timeout: 2s
filebeat.name: filebeat-shiper
filebeat.spool_zie: 50000
filebeat.inputs: # 从这里开始定义每个日志的路径、类型、收集方式等信息
- type: log # 指定收集的类型为 log
paths:
- /usr/local/nginx/logs/access.log # 设置 access.log 的路径
fields: # 设置一个 fields,用于标记这个日志
type: access-log # 为 fields 设置一个关键字 type,值为 access-log
enabled: true
backoff: 1s
backoff_factor: 2
close_inactive: 1h
encoding: plain
harvester_buffer_size: 262144
max_backoff: 10s
max_bytes: 10485760
scan_frequency: 10s
tail_lines: true
- type: log
paths:
- /usr/local/nginx/logs/error.log # 设置 error.log 的路径
fields: # 设置一个 fields,用于标记这个日志
type: error-log # 为 fields 设置一个关键字 type,值为 error-log
enabled: true
backoff: 1s
backoff_factor: 2
close_inactive: 1h
encoding: plain
harvester_buffer_size: 262144
max_backoff: 10s
max_bytes: 10485760
scan_frequency: 10s
tail_lines: true
- type: log
paths:
- /usr/local/nginx/logs/blacklist.log # 设置 blacklist.log 的路径
fields: # 设置一个 fields,用于标记这个日志
type: blacklist-log # 为 fields 设置一个关键字 type,值为 blacklist-log
enabled: true
backoff: 1s
backoff_factor: 2
close_inactive: 1h
encoding: plain
harvester_buffer_size: 262144
max_backoff: 10s
max_bytes: 10485760
scan_frequency: 10s
tail_lines: true
output.elasticsearch:
workers: 4
bulk_max_size: 8192
hosts: # 设置 elastic 的地址
- 10.16.12.206:30187
- 10.16.12.207:30187
- 10.16.12.208:30187
- 10.16.13.214:30187
- 10.16.13.215:30187
index: web-nginx-%{[fields.type]}-%{+yyyy.MM.dd} # 设置索引名称,后面引用的 fields.type 变量。此处的配置应该可以省略(不符合下面创建索引条件的日志,会使用该索引,后续会测试是否是这样)
indices: # 使用 indices 代表要创建多个索引
- index: web-nginx-access-log-%{+yyyy.MM.dd} # 设置 access.log 日志的索引,注意索引前面的 web-nginx 要与setup.template.pattern 的配置相匹配
when.equals: # 设置创建索引的条件:当 fields.type 的值等于 access-log 时才生效
fields.type: access-log
- index: web-nginx-error-log-%{+yyyy.MM.dd}
when.equals:
fields.type: error-log
- index: web-nginx-blacklist-log-%{+yyyy.MM.dd}
when.equals:
fields.type: blacklist-log
processors:
- drop_fields:
fields:
- agent.ephemeral_id
- agent.hostname
- agent.id
- agent.type
- agent.version
- ecs.version
- input.type
- log.offset
- version
- decode_json_fields:
fields:
- message
max_depth: 1
overwrite_keys: true
setup.ilm.enabled: false # 如果要创建多个索引,需要将此项设置为 false
setup.template.name: web-nginx-log # 设置模板的名称
setup.template.pattern: web-nginx-* # 设置模板的匹配方式,上面索引的前缀要和这里保持一致
setup.template.overwrite: true
setup.template.enabled: true
filebeat多个日志输出多条索引案例
本文详细描述了Filebeat的配置,包括输入日志路径、类型设定,以及与Elasticsearch的输出连接,展示了如何设置索引策略、处理器和模板,以高效地监控和管理Nginx日志。
摘要由CSDN通过智能技术生成