在CentOS系統上,Filebeat的日志文件輪轉可以通過配置logrotate工具來實現。以下是配置Filebeat日志輪轉的步驟:
確保logrotate已安裝: 在CentOS 7和8上,logrotate通常已經預裝。如果沒有,可以使用以下命令安裝:
sudo yum install logrotate
創建或編輯logrotate配置文件:
Filebeat的日志輪轉配置文件通常位于/etc/logrotate.d/
目錄下。你可以創建一個新的配置文件,例如filebeat
,或者編輯現有的配置文件(如果有的話)。
使用文本編輯器打開或創建配置文件:
sudo vi /etc/logrotate.d/filebeat
添加以下內容到配置文件中:
/var/log/filebeat/filebeat
{
daily
rotate 7
compress
missingok
notifempty
create 640 root adm
sharedscripts
postrotate
if [ -f '/var/run/filebeat/filebeat.pid' ]; then
/usr/share/filebeat/filebeat -e -c /etc/filebeat/filebeat.yml -d '*'
fi
endscript
}
這里的配置表示:
保存并退出配置文件。
測試logrotate配置是否正確: 使用以下命令測試logrotate配置:
sudo logrotate -f /etc/logrotate.d/filebeat
如果沒有錯誤信息,說明配置正確。
現在,Filebeat的日志文件將根據配置進行輪轉。如果你希望logrotate定期自動執行,可以將其添加到cron任務中。