在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),確保網絡連通性及權限配置正確。