Logrotate 管理 Nginx日誌

在/etc/logrotate.d/目錄下創建一個配置文件”nginx”,內容如下:

#vim /etc/logrotate.d/nginx/usr/local/nginx/logs/*.log {daily
rotate 5
missingok
dateext
compress
notifempty
sharedscripts
postrotate    [ -e /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid` endscript}

註釋:
/usr/local/nginx/logs/*.log:需要輪詢日誌路徑
daily:每天輪詢
rotate 5:保留最多5次滾動的日誌
missingok:如果日誌丟失,不報錯繼續滾動下一個日誌
dateext:使用日期作爲命名格式
compress:通過gzip壓縮轉儲以後的日誌
notifempty:當日志爲空時不進行滾動

sharedscripts:

/var/run/nginx.pid: nginx pid位置,請查看nginx.conf
postrotate/endscript:在截斷轉儲以後需要執行的命令

立即截斷可執行下面

/usr/sbin/logrotate -f /etc/logrotate.d/nginx

注:
由於logratate已經加到cron.daily(/etc/cron.daily/logrotate),不再需要加到計劃任務中


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章