下面以 CentOS 7 / 8 为例,说明如何安装和配置 Filebeat(Elastic 官方日志采集器)。
# 导入 Elastic GPG key
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# 添加 yum 源(以 8.x 为例)
sudo cat > /etc/yum.repos.d/filebeat.repo <<EOF
[filebeat]
name=Elasticsearch repository for 8.x packages
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
如果是 CentOS 8,用
dnf install filebeat -y
配置文件路径:
/etc/filebeat/filebeat.yml
示例:采集 /var/log/*.log
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /var/log/*.log
老版本用
log类型,8.x 推荐filestream
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "your_password"
output.logstash:
hosts: ["localhost:5044"]
filebeat setup
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
systemctl status filebeat
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after
如果输出到远程 ES / Logstash:
firewall-cmd --add-port=9200/tcp --permanent
firewall-cmd --add-port=5044/tcp --permanent
firewall-cmd --reload
如果你告诉我:
我可以给你一份 可直接用的完整配置。