使用 Filebeat 监控 Linux 日志
一 安装与准备
二 最小可用配置与启动
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
ignore_older: 72h
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
sudo systemctl start filebeat
sudo systemctl enable filebeat
sudo systemctl status filebeat
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.logstash:
hosts: ["192.0.2.10:5044"]
input { beats { port => 5044 } }
output { stdout { codec => rubydebug } }
三 常用输入与处理器配置
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/messages
- /var/log/secure
fields:
log_source: system
fields_under_root: true
tags: ["os", "centos"]
- type: log
enabled: true
paths:
- /var/log/nginx/*.log
fields:
log_source: nginx
fields_under_root: true
tags: ["web", "nginx"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/app/*.log
include_lines: ['^ERR', '^WARN']
exclude_lines: ['^DEBUG']
multiline.pattern: '^\d{4}-\d{2}-\d{2}'
multiline.negate: true
multiline.match: after
- type: log
enabled: true
paths:
- /var/log/app/json.log
json.keys_under_root: true
json.add_error_key: true
- type: log
enabled: true
paths:
- /var/log/stream.log
tail_files: true
四 输出到不同后端与索引管理
output.redis:
hosts: ["127.0.0.1:6379"]
key: "filebeat"
db: 1
datatype: list
output.redis:
hosts: ["127.0.0.1:6379"]
key: "default_list"
keys:
- key: "error_list"
when.contains:
message: "error"
- key: "debug_list"
when.contains:
message: "DEBUG"
- key: "%{[fields.list]}"
output.kafka:
hosts: ["kafka1:9092","kafka2:9092"]
topic: "%{[fields.log_topic]}"
required_acks: 1
compression: gzip
setup.ilm.enabled: false
setup.template.name: "myapp"
setup.template.pattern: "myapp-*"
output.elasticsearch:
hosts: ["localhost:9200"]
index: "myapp-%{+yyyy.MM.dd}"
output.elasticsearch:
hosts: ["localhost:9200"]
indices:
- index: "ops-systemlog-%{+yyyy.MM.dd}"
when.equals:
fields.source: "ops-systemlog"
- index: "ops-operationlog-%{+yyyy.MM.dd}"
when.equals:
fields.source: "ops-operationlog"
五 运维与排错要点
filebeat modules enable system nginx
filebeat setup --modules system,nginx