Nginx-Logrotate日志分割
1、logrotate工作原理
logrotate是基于crond服务(定时任务)来运行的
2、nginx一天备份一次的配置
cat >/etc/logrotate.d/nginx <<'EOF' /var/log/nginx/*.log { daily missingok rotate 52 compress delaycompress notifempty create 640 nginx adm sharedscripts postrotate if [ -f /var/run/nginx.pid ]; then kill -USR1 `cat /var/run/nginx.pid` fi endscript } EOF
3、查看效果
]# ll /var/log/nginx/
-rw-r----- 1 www adm 0 May 3 10:29 access.log
-rw-r----- 1 www adm 4023 Apr 29 00:15 access.log-20230429.gz
-rw-r----- 1 www adm 9857 Apr 30 13:33 access.log-20230430.gz
-rw-r----- 1 www adm 902 May 1 14:51 access.log-20230501.gz
-rw-r----- 1 www adm 2333 May 2 11:11 access.log-20230502.gz
-rw-r----- 1 www adm 255301 May 3 00:29 access.log-20230503
-rw-r----- 1 www adm 65 May 3 14:35 error.log
-rw-r----- 1 www adm 24211 Apr 29 00:01 error.log-20230429.gz
-rw-r----- 1 www adm 9469 Apr 30 13:28 error.log-20230430.gz
-rw-r----- 1 www adm 266 Apr 30 16:45 error.log-20230501.gz
-rw-r----- 1 www adm 799 May 2 00:22 error.log-20230502.gz
-rw-r----- 1 www adm 41498 May 3 00:22 error.log-20230503