nginx日誌切割

發現nginx的日誌沒有正常的切割

cat logrotate.d/nginx

/home/log/nginx1.0.11/*.log{
    daily
    rotate 30
    copytruncate
    missingok
    notifempty
    compress
}

參照http://wiki.nginx.org/LogRotation

$ mv access.log access.log.0
$ kill -USR1 `cat master.nginx.pid`
$ sleep 1
$ gzip access.log.0    # do something with access.log.0

nginx 提供了USR1信號 可重新打開日誌

逐修改cat logrotate.d/nginx爲

 
/home/log/nginx1.0.11/*.log{
    daily        #每日
    rotate 30    #保留30天的
    copytruncate   #用於還在打開中的日誌文件,把當前日誌備份並截斷 
    missingok     #找不到log文件也繼續
    notifempty    #如果文件爲空不轉儲
    compress     #壓縮
    dateext     #用日期做歸檔日誌的擴展名
postrotate      #post腳本開始
    if [ -f /var/run/nginx.pid ]; then
        kill -USR1 `cat /var/run/nginx.pid`
    fi
endscript          #post腳本結束
}

執行

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

查看日誌歸檔正常

############################nginx信號#############################################

TERM, INT

Quick shutdown

快速關閉

QUIT

Graceful shutdown

從容關閉

HUP

Configuration reload Start the new worker  processes with a new configuration

Gracefully shutdown the old worker  processe

重載配置

用新的配置開始新的工作進程

從容關閉舊的工作進程

USR1

Reopen the log files

重新打開日誌文件

USR2

Upgrade Executable on the fly

平滑升級可執行程序。

WINCH

Gracefully shutdown the worker processes

從容關閉工作進程


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