以下是在Ubuntu上使用Filebeat进行实时监控的步骤:
安装Filebeat
sudo apt update
sudo apt install filebeat
配置监控目标
编辑配置文件 /etc/filebeat/filebeat.yml,在 filebeat.inputs 中指定要监控的文件或目录,例如:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/syslog
- /var/log/nginx/*.log
可选配置:
ignore_older:忽略超过指定时间的旧文件(如 72h)。exclude_files:排除特定文件(如隐藏文件)。设置输出目标
配置将数据发送到Elasticsearch或Logstash,例如:
output.elasticsearch:
hosts: ["localhost:9200"]
或发送到Logstash:
output.logstash:
hosts: ["localhost:5044"]
启动并验证
sudo systemctl start filebeat
sudo systemctl enable filebeat
sudo systemctl status filebeat # 检查状态
sudo journalctl -u filebeat -f # 查看实时日志
可选:启用监控端点
在配置中添加以下内容,启用Filebeat的监控API(需配置认证):
management.endpoint: "http://localhost:9200"
management.enabled: true
通过访问 http://<服务器IP>:9200/_nodes/stats/filebeat 查看监控数据。
说明:确保后端服务(如Elasticsearch/Logstash)已运行,且Filebeat有权限访问日志文件。如需监控特定应用日志(如Java),需在路径中指定对应日志文件位置。