logrotate是一個日志檔案管理工具。用來把舊檔案輪轉、壓縮、删除,并且建立新的日志檔案。我們可以根據日志檔案的大小、天數等來轉儲,便于對日志檔案管理,一般都是通過cron計劃任務來完成的。
1. 配置執行個體
/var/log/messages {
rotate 5
weekly
postrotate
/sbin/killall -HUP syslogd
endscript
}
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 5
mail [email protected]
size 100k
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}
/var/log/news/* {
monthly
rotate 2
olddir /var/log/news/old
missingok
postrotate
kill -HUP ‘cat /var/run/inn.pid‘
endscript
nocompress
}
Usage: logrotate [OPTION...] <configfile>
-d, --debug 調試模式,輸出調試結果,并不執行。隐式-v參數
-f, --force 強制模式,對所有相關檔案進行rotate
-m, --mail=command 發送郵件 (instead of `/bin/mail')
-s, --state=statefile 狀态檔案,對于運作在不同使用者情況下有用
-v, --verbose 顯示debug資訊