在 CentOS 上使用 Filebeat 连接 Elasticsearch(ES),一般分为以下几个步骤:
sudo 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
若使用 ES 7.x,把
8.x改为7.x
编辑配置文件:
vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["http://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
如果是 无认证 ES:
output.elasticsearch:
hosts: ["http://192.168.1.100:9200"]
如果是 HTTPS + 证书:
output.elasticsearch:
hosts: ["https://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
ssl.certificate_authorities: ["/etc/filebeat/certs/ca.crt"]
filebeat setup --index-management -E output.elasticsearch.hosts=["192.168.1.100:9200"]
systemctl enable filebeat
systemctl start filebeat
查看状态:
systemctl status filebeat
journalctl -u filebeat -f
curl -u elastic:your_password http://192.168.1.100:9200/_cat/indices?v
应能看到类似:
filebeat-8.x.x-2026.xx.xx
9200firewall-cmd --add-port=9200/tcp --permanent
firewall-cmd --reload
ntpdate pool.ntp.org
如果你愿意,可以告诉我:
我可以给你一份可直接用的 filebeat.yml 示例。