在Ubuntu上进行Filebeat日志分析的步骤如下:
安装Filebeat
通过包管理器安装:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update && sudo apt-get install filebeat
配置日志采集
编辑配置文件 /etc/filebeat/filebeat.yml,指定日志路径和输出目标:
filebeat.inputs:
- type: log
enabled: true
paths: ["/var/log/*.log"] # 监控日志路径,支持通配符
output.elasticsearch:
hosts: ["localhost:9200"] # 输出到Elasticsearch
index: "filebeat-%{+yyyy.MM.dd}" # 索引格式
若需发送到Logstash,启用Logstash输出并配置端口:
output.logstash:
hosts: ["localhost:5044"]
启用模块(可选)
使用System模块简化系统日志采集:
sudo filebeat modules enable system
sudo filebeat setup # 初始化模块
启动服务并验证
sudo systemctl start filebeat
sudo systemctl enable filebeat
sudo tail -f /var/log/filebeat/filebeat # 查看服务日志
日志分析与可视化
curl -X GET "localhost:9200/_search")获取原始日志数据。http://localhost:5601。filebeat-*)。高级分析(可选)
filebeat.yml中使用processors解析日志,如grok提取字段、dissect按分隔符拆分。multiline选项合并跨行日志(如Java堆栈跟踪)。说明:需提前安装Elasticsearch和Kibana(若使用ELK Stack),确保网络连通性及权限配置正确。