在 CentOS 上把 Filebeat 对接 Elasticsearch(ES),通常有两种方式:
下面以 CentOS 7/8 + Filebeat 直接对接 ES 为例说明。
假设:
http://192.168.1.100:9200# 以 8.x 为例
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
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
vi /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
output.elasticsearch:
hosts: ["http://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
setup.ilm.enabled: false
setup.template.enabled: true
⚠️ 如果是 ES 8.x + 安全开启,需要配置
username/password如果是 ES 没开安全(测试环境),可以去掉 username/password
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 http://192.168.1.100:9200/_cat/indices?v
应该能看到类似:
filebeat-8.x.x-2026.xx.xx
filebeat-*0.0.0.0firewall-cmd --add-port=9200/tcpFilebeat 和 ES 大版本必须一致
@timestamp 是采集时间processors 解析日志时间filebeat.modules(系统/nginx/redis 等)如果你告诉我:
我可以直接给你 一份可用的 filebeat.yml 配置。