The understanding of the Logrotate operating mechanism is as follows:
1, scheduled execution by Cron, script location/etc/cron.daily/logrotate2, logrotate script default profile/etc/logrotate.conf3, cron execution logrotate time not found the exact time currently (Times this self-defined)
The test found that due to the rotation log date can only be the current date, so the Nginx log Rotation timer task time can only be set at 23:59 (due to cron timing time format No second, so the post 23:59 log can only be placed on the next date, this is not ideal, but can be reduced by scripting) Have a friend who knows the way to change this date take some time to tell me, thank you.
Nginx logrotate configuration file contents:
/usr/local/nginx/logs/*.log {notifempty Rotate 7 daily dateext DateFormat.%y-%m-%d sharedscripts Postrotate/bin /KILL-USR1 '/bin/cat/usr/local/nginx/logs/nginx.pid ' Endscript}
Common logrotate File Configuration item Description:
compress# compression dump log, compression type for gzipdelaycompress# with compress, the previous log file compression delay to the next cycle dump nodelaycompress# That is, the delaycompress option of the inverse, not the delay but the direct compression nocompress# does not compress the dump of the log copytruncate# truncation dump the log file that has been opened nocopytruncate# not truncate the log dump Create # Create new log file after dump nocreate# do not create new log file ifempty# even if log file is empty also dump, default configuration. notifempty# and Ifempty In contrast, that is, empty does not dump Olddir #将转存的日志文件放入指定的目录noolddir # in the log directory to be dumped (that is, the files and logs after the same directory) Prerotate/endscript # Dump the previous command to execute can be placed in the middle of these two keywords, these two keywords must be separate lines Postrotate/endscript #转储以后需要执行的命令可以放在这两个关键字中间, these two keywords must be separate rows sharedscripts# All log files are rolled up and then executed one time script daily# specifies that the period for dumping is weekly# per day for the specified rollover period of the week monthly# specify the period of the rollover for each month rotate# keep the number of copies of the dump file size# log file reaches the specified size when the dump
More configuration items to check man information
The script content of the Web-nginx log
#!/bin/sh#date 2016/03/28#author jerkfile=/usr/local/nginx/nginxcat <<EOF> $FILE/usr/local/nginx/logs/*. Log {Notifempty rotate 5 daily dateext DateFormat.%y-%m-%d sharedscripts postrotate/bin/kill-usr1 '/bin/cat/u Sr/local/nginx/logs/nginx.pid ' Endscript}eofsleep 58if [-F $FILE];then/usr/sbin/logrotate-f $FILEfirm-F $FILE
This article is from the "all over the years with a little bit" blog, please be sure to keep this source http://wangzz.blog.51cto.com/10856583/1766821
Logrotate via the web nginx log