我使用logrotate旋转nginx访问日志文件,配置如下:
/var/www/logs/*.log {
daily
missingok
dateext
dateformat _%Y-%m-%d
dateyesterday
rotate 90
compress
delaycompress
compressext
notifempty
create 0640 www-data www-data
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
例如,当cron运行该脚本时,文件中从早上0点到5点之间的所有日志都将被旋转。我想要一份日志文件,从午夜到晚上11点59分。
有机会配置这个吗?
发布于 2018-07-20 09:18:39
若要在晚上11时59分旋转日志,请将/etc/crontab文件配置为:
59 23 * * * <path_to_logrotate_command> -f <path_to_logrotate_schedule_file>
E.g. 59 23 * * * /usr/sbin/logrotate -f /home/foo/logrotate/rotate_nginx
发布于 2020-06-16 01:11:47
实际上,最好将cron.daily
的日程更改为如下所示:
$ grep daily /etc/crontab
59 23 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
记住,这对/etc/cron.daily
中的每个脚本都是有效的
$ ls /etc/cron.daily -l
total 48
-rwxr-xr-x 1 root root 376 nov 20 2017 apport
-rwxr-xr-x 1 root root 1478 abr 20 2018 apt-compat
-rwxr-xr-x 1 root root 355 dic 29 2017 bsdmainutils
-rwxr-xr-x 1 root root 1176 nov 2 2017 dpkg
-rwxr-xr-x 1 root root 372 ago 21 2017 logrotate
-rwxr-xr-x 1 root root 1065 abr 7 2018 man-db
-rwxr-xr-x 1 root root 539 jun 26 2018 mdadm
-rwxr-xr-x 1 root root 538 mar 1 2018 mlocate
-rwxr-xr-x 1 root root 249 ene 25 2018 passwd
-rwxr-xr-x 1 root root 3477 feb 21 2018 popularity-contest
-rwxr-xr-x 1 root root 246 mar 21 2018 ubuntu-advantage-tools
-rwxr-xr-x 1 root root 214 jun 27 2018 update-notifier-common
但是,如果您需要一个特定的时间表,仅对于日志旋转规则,选择的答案将是一个选项。
https://stackoverflow.com/questions/51261915
复制相似问题