下面给你一个在 CentOS 上配置 Filebeat 的完整示例,从安装到常见使用场景(采集日志 → 发送到 Elasticsearch / Logstash)。
# 导入 Elastic GPG 密钥
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 下载并安装 Filebeat(以 8.x 为例)
sudo yum install -y https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.12.2-x86_64.rpm
版本号可根据需要调整
安装完成后:
filebeat version
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/nginx/access.log
fields:
log_type: system
output.elasticsearch:
hosts: ["http://127.0.0.1:9200"]
username: "elastic"
password: "your_password"
如果 Elasticsearch 没开启安全,可去掉
username/password
output.logstash:
hosts: ["127.0.0.1:5044"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
fields:
service: nginx
sudo systemctl start filebeat
sudo systemctl enable filebeat
查看状态:
systemctl status filebeat
filebeat setup --index-management -E output.logstash.enabled=false -E output.elasticsearch.hosts=["localhost:9200"]
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
enabled: truefilebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
如果你愿意,可以告诉我:
我可以给你一份完全贴合你环境的配置。