下面以 CentOS 7/8 为例,说明 Filebeat 对接 Elasticsearch(ES) 的完整步骤,适用于常见场景(Filebeat → ES,不使用 Logstash)。
假设:
http://es-node:9200)# 导入 Elastic GPG Key
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 创建 yum 源
sudo tee /etc/yum.repos.d/elastic.repo <<EOF
[elastic-8.x]
name=Elastic repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
如果是 ES 7.x,把
8.x改成7.x
sudo yum install filebeat -y
编辑:
vim /etc/filebeat/filebeat.yml
最小可用配置示例:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["http://192.168.1.10:9200"]
username: "elastic"
password: "your_password"
setup.kibana:
host: "http://192.168.1.10:5601"
✅ 说明:
paths:要采集的日志路径hosts:ES 地址username/passwordsetup.kibana 可选(用于自动创建索引模板)output.elasticsearch:
hosts: ["https://192.168.1.10:9200"]
ssl.verification_mode: none
或:
ssl.certificate_authorities: ["/etc/filebeat/ca.crt"]
filebeat setup
作用:
⚠️ 只运行一次即可
systemctl enable filebeat
systemctl start filebeat
systemctl status filebeat
curl -u elastic:password http://192.168.1.10:9200/_cat/indices?v
你会看到类似:
filebeat-8.11.0-2026.01.21-000001
curl -u elastic:password http://192.168.1.10:9200/filebeat-*/_search?pretty
或在 Kibana → Discover 中查看。
journalctl -u filebeat -f
或:
filebeat test config
filebeat test output
enabled: truels -l /var/log/*.log
paths:
- /var/log/nginx/*.log
- /var/log/app/*.log
fields:
env: prod
fields_under_root: true
日志文件
↓
Filebeat (CentOS)
↓
Elasticsearch
↓
Kibana
如果你需要:
可以直接告诉我,我可以给你对应配置示例 ✅