Logrotate实现nginx日志切割
logrotate 简单用法
# 直接运行所有 logrotat的方法, 这将运行主logrotate文件,其中包括其他 logrotate 配置
logrotate -f /etc/logrotate.conf
# 以详细+强制模式运行它。
logrotate -vf /etc/logrotate.conf
# 如果要强制运行单个特定目录或守护程序的日志文件,它们将独立运行。(使用nginx作为例子)
logrotate -df /etc/logrotate.d/nginx
logrotate -f /etc/logrotate.d/nginx
-v:显示进程
-f:强制运行Nginx 日志切割
$ cat /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 0640 www-data www-data
dateext
dateformat -%Y-%m-%d-%s
sharedscripts
postrotate
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
endscript
}Last updated