支持多种日志源的方式 在 Ubuntu 上,Filebeat 可以同时采集多种日志源。做法是在配置文件 /etc/filebeat/filebeat.yml 的 filebeat.inputs 数组中定义多个输入项(每个项可设置不同的 type 与参数);同一实例可并行启用 log、syslog、tcp、udp、container/journald 等多种输入类型。若需面向容器与宿主机混合环境,常见组合是:容器日志用 container,系统日志用 journald,业务文件日志用 log。
快速配置示例
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/syslog
- /var/log/auth.log
fields:
log_type: system
fields_under_root: true
- type: log
enabled: true
paths:
- /var/log/nginx/*.access.log
fields:
log_type: nginx_access
fields_under_root: true
processors:
- dissect:
tokenizer: '%{client_ip} - %{ident} [%{timestamp}] "%{method} %{request} HTTP/%{http_version}" %{status} %{body_bytes_sent} "%{referrer}" "%{user_agent}"'
field: "message"
target_prefix: "http"
output.elasticsearch:
hosts: ["http://es-host:9200"]
indices:
- index: "filebeat-system-%{+yyyy.MM.dd}"
when.equals:
log_type: "system"
- index: "filebeat-nginx-%{+yyyy.MM.dd}"
when.equals:
log_type: "nginx_access"
要点:
同时采集文件与网络端口
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/app/*.log
fields:
source: app_file
- type: tcp
host: "0.0.0.0:9000"
fields:
source: app_tcp
processors:
- decode_json_fields:
fields: ["message"]
target: ""
overwrite_keys: true
output.elasticsearch:
hosts: ["http://es-host:9200"]
index: "filebeat-mixed-%{+yyyy.MM.dd}"
说明:
注意事项