下面分 常见场景 给你说明 Filebeat 如何连接 CentOS 上的 Elasticsearch(ES),从 最简单 到 生产推荐 的方式都有。
curl http://localhost:9200
返回类似:
{
"name" : "centos-node",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "8.11.0"
}
}
✅ 说明 ES 正常
sudo yum install -y filebeat
或手动下载:
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.11.0-x86_64.rpm
sudo rpm -ivh filebeat-8.11.0-x86_64.rpm
编辑配置文件:
sudo vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["http://localhost:9200"]
✅ 如果 ES 在 另一台机器:
output.elasticsearch:
hosts: ["http://192.168.1.10:9200"]
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
systemctl status filebeat
curl http://localhost:9200/_cat/indices?v
你应该能看到 filebeat-* 索引。
通常:
elasticelasticsearch-reset-passwordoutput.elasticsearch:
hosts: ["https://localhost:9200"]
username: "elastic"
password: "你的密码"
ssl:
enabled: true
verification_mode: none # 测试用,生产建议用证书
⚠️ 生产环境不要用 verification_mode: none
如果 Filebeat 在 另一台机器,需要修改:
sudo vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
http.port: 9200
然后重启 ES:
sudo systemctl restart elasticsearch
sudo firewall-cmd --add-port=9200/tcp --permanent
sudo firewall-cmd --reload
Filebeat → Logstash → Elasticsearch
output.logstash:
hosts: ["localhost:5044"]
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
curl -u elastic:密码 http://es_ip:9200
| 场景 | 配置重点 |
|---|---|
| 同机无认证 | http://localhost:9200 |
| 跨机器 | ES network.host: 0.0.0.0 |
| 有认证 | username/password |
| HTTPS | ssl.enabled: true |
| 防火墙 | 放行 9200 |
如果你愿意,可以直接告诉我:
我可以给你 完全可用的配置文件。