1. 首頁
  2. 管理

如何使用logrotate管理VPS日誌檔案

如何使用logrotate管理VPS日誌檔案

我們可以根據日誌檔案的大小,也可以根據其天數來轉儲,這個過程一般透過 crontab程式來執行。

logrotate 程式還可以用於壓縮日誌檔案,以及傳送日誌到指定的E-mail 。

logrotate 的配置檔案是 /etc/logrotate.conf 主要引數如下表:

下面的配置是deepvps使用的配置檔案,大家可以作為參考。

logrotate.conf

/home/www/logs/*.log {

daily

missingok

compress

delaycompress

dateext

create

notifempty

sharedscripts

postrotate

kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

endscript

}

引數 功能

daily——指定轉儲週期為每天

missingok——指的`是如果找不到這個log檔案,就忽略過去

compress——透過gzip 壓縮轉儲以後的日誌

delaycompress 和compress一起使用時,轉儲的日誌檔案到下一次轉儲時才壓縮

notifempty——如果是空檔案的話,不轉儲

postrotate/endscript——在轉儲以後需要執行的命令可以放入這個對,這兩個關鍵字必須單獨成行

crontab:

59 23 * * * root logrotatef /usr/local/nginx/conf/logrotate.conf