在 CentOS 上让 Filebeat 连接 Elasticsearch(ES),通常有以下几种方式。下面以 Filebeat 直接连 ES(最常见、最简单)为例说明。
9200sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[filebeat]
name=Elasticsearch repository for Filebeat
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
sudo yum install filebeat -y
编辑配置文件:
sudo vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["http://192.168.1.100:9200"]
output.elasticsearch:
hosts: ["https://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
ssl.verification_mode: none
output.elasticsearch:
hosts: ["https://es.example.com:9200"]
username: "filebeat_writer"
password: "xxx"
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
systemctl status filebeat
journalctl -u filebeat -f
curl http://192.168.1.100:9200/_cat/indices?v
你应该能看到类似:
filebeat-8.x.x-2026.03.11
9200 是否开放localhostnetwork.host: 0.0.0.0
discovery.type: single-node
timedatectl
output.logstash:
hosts: ["192.168.1.101:5044"]
Filebeat → Elasticsearch → Kibana
或
Filebeat → Logstash → Elasticsearch
如果你愿意,可以告诉我:
我可以给你 完全贴合你环境的配置。