Filebeat在Ubuntu上的日志轮转策略
策略总览
策略一 使用 logrotate 轮转 Filebeat 自身日志
/var/log/filebeat/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 0640 root adm
sharedscripts
postrotate
systemctl reload filebeat >/dev/null 2>&1 || true
endscript
}
sudo logrotate -f /etc/logrotate.d/filebeat;logrotate 通常由 /etc/cron.daily/logrotate 每日定时执行。策略二 使用 Filebeat 内部文件输出轮转(output.file)
output.file:
path: "/var/log/filebeat"
filename: "filebeat.log"
rotate_every_kb: 104857600 # 100 MB
number_of_files: 10
rotate_on_startup: false
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat-internal
keepfiles: 7
permissions: 0640
策略三 由 rsyslog/journald 接管输出并轮转
[Service]
StandardOutput=journal+console
StandardError=journal+console
SyslogIdentifier=filebeat
选型与注意事项
logrotate -f 或 systemctl reload filebeat 验证。