下面给你一个 CentOS 上 Filebeat 对接 Elasticsearch(ES) 的常用配置示例,适用于 Filebeat 直接写 ES(不走 Logstash)。
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
enabled=1
EOF
sudo yum install filebeat -y
如果是 ES 7.x,把
8.x改成7.x
配置文件路径:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
# ===================== Elasticsearch Output =====================
output.elasticsearch:
hosts: ["http://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
# 可选:索引命名
setup.template.name: "filebeat"
setup.template.pattern: "filebeat-*"
如果 ES 开了 TLS:
output.elasticsearch:
hosts: ["https://192.168.1.100:9200"]
username: "elastic"
password: "your_password"
ssl.verification_mode: "none" # 测试可用,生产建议配置证书
filebeat setup --index-management -E output.elasticsearch.hosts=["192.168.1.100:9200"]
或者一次性:
filebeat setup
systemctl enable filebeat
systemctl start filebeat
查看状态:
systemctl status filebeat
curl -u elastic:your_password http://192.168.1.100:9200/_cat/indices?v | grep filebeat
或在 Kibana:
Stack Management → Index Management → filebeat-*
时间不同步
yum install ntpdate -y
ntpdate pool.ntp.org
ES 版本不一致
权限问题
chmod 644 /var/log/messages
如果你需要:
可以告诉我你的 ES 版本 + 日志类型,我给你定制配置。