下面以 CentOS 7 / 8 为例,给你一份从安装到基本配置 Filebeat 的完整流程,适用于把日志发送到 Elasticsearch 或 Logstash。
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo tee /etc/yum.repos.d/elastic.repo <<EOF
[elastic-8.x]
name=Elastic 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
如果你用的是 7.x,把
8.x改成7.x
sudo yum install filebeat -y
查看版本:
filebeat version
配置文件路径:
/etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/messages
- /var/log/secure
output.elasticsearch:
hosts: ["localhost:9200"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
output.logstash:
hosts: ["localhost:5044"]
filebeat.inputs:
- type: log
enabled: true
paths:
- /data/app/logs/*.log
json.keys_under_root: true
json.add_error_key: true
filebeat test config
测试输出是否可达:
filebeat test output
sudo systemctl enable filebeat
sudo systemctl start filebeat
查看状态:
systemctl status filebeat
journalctl -u filebeat -f
或:
tail -f /var/log/filebeat/filebeat
| 目录 | 说明 |
|---|---|
/etc/filebeat/ |
配置文件 |
/var/lib/filebeat/ |
记录采集位置 |
/var/log/filebeat/ |
运行日志 |
enabled: truefilebeat 日志hosts 配置sudo systemctl stop filebeat
sudo yum remove filebeat -y
sudo rm -rf /etc/filebeat /var/lib/filebeat /var/log/filebeat
如果你愿意,可以告诉我:
我可以给你一份完全定制的 Filebeat 配置。