Linux logrotate偏移延迟

Linux logrotate偏移延迟

我的服务器每天的日志文件大小非常大,大约 1GB。我想在午夜进行每日日志轮换。问题是每个轮换文件在午夜后丢失前 17-25 分钟的数据,而同一个文件包含第二天 17-25 分钟的数据。

我的问题是如何正确地对每天进行日志轮换,并且当天的数据必须从午夜到午夜。

服务器有几个服务,每个服务每天有 100MB-1.5GB 的文件,如 apache2、lighttpd、ftp 等。

少 /var/log/lighttpd/access.log.1

np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abc.xml HTTP/1.1" 2422 200 "domainexample/1.3 CFNetwork/596.2.3 Darwin/12.2.0 (x86_64) (iMac9%2C1)" "-"
np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abc.xml HTTP/1.1" 2422 200 "domainexample/1.3 CFNetwork/596.2.3 Darwin/12.2.0 (x86_64) (iMac12%2C1)" "-"
np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abr.xml HTTP/1.1" 0 304 "hhh%20Radio%20Umee/616 CFNetwork/548.1.4 Darwin/11.0.0" "-"
np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abr.xml HTTP/1.1" 2433 200 "NobexRadio" "-"
np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abr.xml HTTP/1.1" 2433 200 "domainexample/1.3 CFNetwork/520.4.3 Darwin/11.4.0 (x86_64) (iMac11%2C2)" "-"

尾部 /var/log/lighttpd/access.log.1

np.domainexample.co.uk 11.22.33.44 - [17/Oct/2012:00:21:56 +0100] "GET /nowplaying/aim_abr.xml HTTP/1.1" 2121 200 "domainexample/1.3 CFNetwork/520.5.1 Darwin/11.4.2 (x86_64) (iMac12%2C2)" "-"
exam.as5623.net 11.22.33.44 - [17/Oct/2012:00:21:56 +0100] "GET /oconnell/20121012170055.mp3 HTTP/1.1" 78118 206 "AppleCoreMedia/1.0.0.10A403 (iPod; U; CPU OS 6_0 like Mac OS X; en_gb)" "-"
exam.as5623.net 11.22.33.44 - [17/Oct/2012:00:21:56 +0100] "GET /oconnell/20121001174703.mp3 HTTP/1.1" 78120 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_us)" "-"
exam.as5623.net 11.22.33.44 - [17/Oct/2012:00:21:56 +0100] "GET /frankskinner/20120905121827.mp3 HTTP/1.1" 78117 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_gb)" "-"
np.domainexample.co.uk 11.22.33.44 - [17/Oct/2012:00:21:56 +0100] "GET /nowplaying/aim_ab8.xml HTTP/1.1" 0 304 "hhh%2080s/616 CFNetwork/609 Darwin/13.0.0" "-"

bzless /var/log/lighttpd/access.log.2.bz2

exam.as5623.net 11.22.33.44 - [15/Oct/2012:00:17:03 +0100] "GET /dave_gorman/20121014130335.mp3 HTTP/1.1" 78117 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_us)" "-"
np.domainexample.co.uk 11.22.33.44 - [15/Oct/2012:00:17:03 +0100] "GET /nowplaying/aim_ab8.xml HTTP/1.1" 2190 200 "hhh/1 CFNetwork/520.4.3 Darwin/11.4.0 (x86_64) (iMac12%2C1)" "-"
exam.as5623.net 11.22.33.44 - [15/Oct/2012:00:17:03 +0100] "GET /frankskinner/20121013132200.mp3 HTTP/1.1" 284941 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_gb)" "-"
exam.as5623.net 11.22.33.44 - [15/Oct/2012:00:17:03 +0100] "GET /dave_gorman/20121014130335.mp3 HTTP/1.1" 78117 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_us)" "-"
exam.as5623.net 11.22.33.44 - [15/Oct/2012:00:17:03 +0100] "GET /dave_gorman/20121014130335.mp3 HTTP/1.1" 78117 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_us)" "-"

bztail /var/log/lighttpd/access.log.2.bz2

np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abr.xml HTTP/1.1" 2433 200 "hhh/1.3 CFNetwork/454.12.4 Darwin/10.8.0 (i386) (MacBookPro5%2C5)" "-"
exam.as5623.net 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /dave_gorman/20121014130335.mp3 HTTP/1.1" 41486 206 "AppleCoreMedia/1.0.0.10A403 (iPod; U; CPU OS 6_0 like Mac OS X; en_gb)" "-"
exam.as5623.net 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /frankskinner/20121013132200.mp3 HTTP/1.1" 78377 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_gb)" "-"
np.domainexample.co.uk 11.22.33.44 - [16/Oct/2012:00:18:20 +0100] "GET /nowplaying/aim_abc.xml HTTP/1.1" 0 304 "Classic%20Rock/616 CFNetwork/609 Darwin/13.0.0" "-"

bzless /var/log/lighttpd/access.log.3.bz2

np.domainexample.co.uk 11.22.33.44 - [14/Oct/2012:00:19:03 +0100] "GET /nowplaying/aim_ab0.xml HTTP/1.1" 0 304 "hhh%2080s/616 CFNetwork/609 Darwin/13.0.0" "-"
exam.as5623.net 11.22.33.44 - [14/Oct/2012:00:19:03 +0100] "GET /oconnell/20120920182425.mp3 HTTP/1.1" 78118 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_us)" "-"
np.domainexample.co.uk 11.22.33.44 - [14/Oct/2012:00:19:03 +0100] "GET /nowplaying/aim_ab0.xml HTTP/1.1" 0 304 "hhh%2080s/616 CFNetwork/548.1.4 Darwin/11.0.0" "-"
np.domainexample.co.uk 11.22.33.44 - [14/Oct/2012:00:19:03 +0100] "GET /nowplaying/aim_abc.xml HTTP/1.1" 0 304 "hhh%20Radio%20Umee/616 CFNetwork/609 Darwin/13.0.0" "-"
np.domainexample.co.uk 11.22.33.44 - [14/Oct/2012:00:19:03 +0100] "GET /nowplaying/aim_ab9.xml HTTP/1.1" 0 304 "hhh%20Radio%20Umee/616 CFNetwork/548.1.4 Darwin/11.0.0" "-"

bztail /var/log/lighttpd/access.log.3.bz2

np.domainexample.co.uk 11.22.33.44 - [15/Oct/2012:00:17:02 +0100] "GET /nowplaying/ab7.xml HTTP/1.1" 1295 200 "PHP/5.2.6" "-"
np.domainexample.co.uk 11.22.33.44 - [15/Oct/2012:00:17:02 +0100] "GET /tracks/7869.xml HTTP/1.1" 1998 200 "PHP/5.2.6" "-"
exam.as5623.net 11.22.33.44 - [15/Oct/2012:00:17:02 +0100] "GET /frankskinner/20121013132200.mp3 HTTP/1.1" 230649 206 "AppleCoreMedia/1.0.0.10A403 (iPhone; U; CPU OS 6_0 like Mac OS X; en_gb)" "-"
exam.as5623.11.22.33.44 - [15/Oct/2012:00:17:02 +0100] "GET /frankskinner/20121013132200.mp3 HTTP/1.1" 78377 206 "AppleCoreMedia/1.0.0.10A403 (iPad; U; CPU OS 6_0 like Mac OS X; en_us)" "-"
np.domainexample.co.uk 11.22.33.44 - [15/Oct/2012:00:17:02 +0100] "GET /nowplaying/abx.xml HTTP/1.1" 314 200 "PHP/5.2.6" "-"

猫/etc/logrotate.d/lighttpd

/var/log/lighttpd/*.log {
    daily
   missingok
   rotate 999
   compresscmd /bin/bzip2
   compressext .bz2
   compress
   delaycompress
   notifempty
   copytruncate
   sharedscripts
   postrotate
      if [ -f /var/run/lighttpd.pid ]; then \
        if [ -x /usr/sbin/invoke-rc.d ]; then \
           invoke-rc.d lighttpd force-reload > /dev/null; \
        else \
           /etc/init.d/lighttpd force-reload > /dev/null; \
        fi; \
      fi;
   endscript
}

ls /etc/logrotate.d/

apache2
apt
aptitude
dpkg
lighttpd
ocsinventory-agent
ppp
rsyslog.disabled
syslog-ng
vsftpd

干杯,

答案1

您真的需要从午夜到午夜而不需要前一天/后一天的任何日志记录吗?

然后,您需要对日志文件进行后期处理,将旧日志剪切并粘贴到正确的边框。

如果您可以更好地安排日志轮换的运行时间,那么您总是会在轮换所有日志文件和同时访问您的服务器的用户之间处于竞争状态,因此对于完美的一日日志文件,您需要进行后期处理......

相关内容