以下是Filebeat在CentOS中的典型使用案例,涵盖安装、配置及验证全流程:
安装Filebeat
sudo yum install epel-release
sudo yum install filebeat
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.6.2-x86_64.rpm
sudo rpm -ivh filebeat-8.6.2-x86_64.rpm
配置日志采集
编辑配置文件 /etc/filebeat/filebeat.yml
,指定日志路径和输出目标:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
output.elasticsearch:
hosts: ["localhost:9200"]
index: "nginx-logs-%{+yyyy.MM.dd}"
paths
:指定要采集的日志文件路径,支持通配符(如/var/log/*.log
)。output.elasticsearch
:配置Elasticsearch地址,可添加认证信息(如用户名、密码)。sudo filebeat modules enable nginx
/etc/filebeat/modules.d/nginx.yml
,指定Nginx日志路径:- module: nginx
access:
var.paths: ["/var/log/nginx/access.log"]
error:
var.paths: ["/var/log/nginx/error.log"]
sudo filebeat setup
sudo systemctl restart filebeat
filebeat.yml
中添加Kibana地址:setup.kibana:
host: "localhost:5601"
http://localhost:5601
。nginx-logs-*
索引,可查看Nginx访问和错误日志的可视化图表。filebeat.yml
中配置 processors
:processors:
- drop_fields:
fields: ["user_password", "credit_card"]
output.elasticsearch:
hosts: ["localhost:9200"]
output.logstash:
hosts: ["localhost:5044"]
sudo systemctl status filebeat
sudo journalctl -u filebeat -f
http.enabled: true
)。sudo chown -R filebeat:filebeat /var/log/nginx
设置)。通过以上步骤,可在CentOS上快速部署Filebeat,实现日志的集中采集、处理与可视化分析。