在CentOS系统上使用Filebeat进行日志分析,通常涉及以下几个步骤:
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.10.0-x86_64.rpm
sudo yum localinstall -y filebeat-7.10.0-x86_64.rpm
/etc/filebeat/filebeat.yml
文件,添加或修改以下内容:filebeat.inputs:
- type: log
paths:
- /var/log/*.log
fields:
type: "systemlog"
log_topic: "systemlog"
fields_under_root: true
exclude_lines: [ "DBG" ]
exclude_files: [ ".gz" ]
output.elasticsearch:
hosts:
- "elasticsearch-host:9200"
index: "system-logs-%{yyyy.MM.dd}"
在这个配置中,paths
指定了要收集的日志文件路径,fields
定义了日志的类型和字段,output.elasticsearch
指定了Elasticsearch的地址和索引名称。
sudo systemctl start filebeat
sudo systemctl enable filebeat
sudo systemctl status filebeat
http://your-kibana-host:5601
在Kibana中,你可以创建索引模式并添加Filebeat生成的索引,然后使用Discover功能来查看和分析日志数据。
dissect
处理器来解析JSON格式的日志:filebeat.inputs:
- type: log
paths:
- /var/log/your-application/*.log
processors:
- dissect:
tokenizer: " %{timestamp} %{level} %{message} "
field: "message"
output.elasticsearch:
hosts:
- "elasticsearch-host:9200"
index: "your-application-logs-%{yyyy.MM.dd}"
通过以上步骤,你就可以使用Filebeat在CentOS系统上收集和分析日志数据了。Filebeat的轻量级和高效特性使其成为日志管理的理想选择。