以下是CentOS中Filebeat的監控策略及配置要點:
安裝Filebeat
通過官方倉庫或手動下載安裝包安裝,如:
sudo yum install filebeat -y # CentOS 7/8
sudo rpm -ivh filebeat-*.rpm # 手動安裝
配置監控目標
編輯/etc/filebeat/filebeat.yml,指定日志路徑、文件類型及過濾規則:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
- /var/log/messages
ignore_older: 72h # 忽略超過72小時的日志
- type: log
paths:
- /var/log/nginx/access.log
- /var/log/nginx/error.log
exclude_files: ['\.gz$'] # 排除壓縮文件
設置輸出目標
將日志發送至Elasticsearch或Logstash:
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{yyyy.MM.dd}" # 按日期動態生成索引
output.logstash:
hosts: ["localhost:5044"]
啟用高級功能
filebeat.modules:
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log"]
processors提取字段或過濾內容,如使用dissect解析日志格式。優化性能與可靠性
filebeat.yml中設置logging.level(如info/debug),控制日志詳細程度。logging.files參數設置日志文件大小、保留天數等。filebeat.autodiscover自動識別日志源。啟動與驗證
sudo systemctl start filebeat
sudo systemctl enable filebeat
# 驗證配置是否正確
sudo filebeat -e -c /etc/filebeat/filebeat.yml -d "publish"
# 查看日志輸出
sudo tail -f /var/log/filebeat/filebeat.log
可視化與告警
關鍵配置文件路徑:
/etc/filebeat/filebeat.yml/var/log/filebeat/filebeat.log參考來源: