目录

nginx logrotate日志回滚

目录

logrotate配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
vi /etc/logrotate.d/nginx
/var/log/nginx/*.log {
    rotate 7
    size 5k
    dateext
    dateformat -%Y-%m-%d-%s
    missingok
#    compress
    sharedscripts
    postrotate
        test -r /run/nginx.pid && kill -USR1 `cat /run/nginx.pid`
    endscript
}

日志回滚命令

1
2
logrotate -v -f /etc/logrotate.d/nginx

定时任务

1
2
crontab -e
*/5 * * * * /usr/sbin/logrotate -v -f /etc/logrotate.d/nginx