在 CentOS 上用 Filebeat 监控日志,通常分为 安装 → 配置 → 启动 → 验证 几个步骤。下面给你一个实用版教程,以监控本地日志文件并发送到 Elasticsearch / Logstash为例。
sudo yum install -y https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.13.4-x86_64.rpm
版本号可自行替换,例如 7.17.x
安装完成后:
filebeat version
路径:
/etc/filebeat/filebeat.yml
例如监控:
/var/log/nginx/access.log/var/log/messagesfilebeat.inputs:
- type: filestream
id: nginx-access
paths:
- /var/log/nginx/access.log
- type: log
enabled: true
paths:
- /var/log/messages
⚠️ Filebeat 7.15+ 推荐使用
filestream
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: "elastic"
password: "your_password"
output.logstash:
hosts: ["localhost:5044"]
filebeat test config
filebeat test output
systemctl enable filebeat
systemctl start filebeat
systemctl status filebeat
journalctl -u filebeat -f
multiline.pattern: '^\['
multiline.negate: true
multiline.match: after
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
ls -l /var/log/nginx/access.log
getenforce
setenforce 0 # 临时关闭
filebeat.inputs:
- type: filestream
id: syslog
paths:
- /var/log/messages
output.elasticsearch:
hosts: ["http://localhost:9200"]
如果你愿意,我可以:
你现在是想监控 什么日志?