logrotate : connf 中提到的大小 2000M 仍然记录大小超过 2000M

logrotate : connf 中提到的大小 2000M 仍然记录大小超过 2000M

我的 /etc/logrotate.conf :

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.

我的日志要轮换 /etc/logrotate.d/apc_rtbinfo.conf

/mnt/log/frengo/apc_rtbinfo.log {
daily
missingok
notifempty
size 2000M
compress
delaycompress
sharedscripts
copytruncate
rotate 3
}

logrotate 的输出:

 logrotate -v /etc/logrotate.d/apc_rtbinfo.conf
reading config file /etc/logrotate.d/apc_rtbinfo.conf
reading config info for /mnt/log/frengo/apc_rtbinfo.log

Handling 1 logs

rotating pattern: /mnt/log/frengo/apc_rtbinfo.log  2097152000 bytes (3 rotations)
empty log files are not rotated, old logs are removed
considering log /mnt/log/frengo/apc_rtbinfo.log
  log does not need rotating

我的旋转日志大小:

# du -sh /mnt/log/frengo/apc_rtbinfo.log*
0       /mnt/log/frengo/apc_rtbinfo.log
4.7G    /mnt/log/frengo/apc_rtbinfo.log.1
80M     /mnt/log/frengo/apc_rtbinfo.log.2
0       /mnt/log/frengo/apc_rtbinfo.log-20151222
679M    /mnt/log/frengo/apc_rtbinfo.log-20151225.gz
681M    /mnt/log/frengo/apc_rtbinfo.log-20151226.gz
691M    /mnt/log/frengo/apc_rtbinfo.log-20151227.gz
0       /mnt/log/frengo/apc_rtbinfo.log-20151228
70M     /mnt/log/frengo/apc_rtbinfo.log.2.gz
80M     /mnt/log/frengo/apc_rtbinfo.log.3
80M     /mnt/log/frengo/apc_rtbinfo.log.4

日志旋转输出显示“日志不需要旋转”,但我提到了“大小 2000M”,即如果日志文件增长大于 2000M,则会旋转日志文件,那么为什么“/mnt/log/frengo/apc_rtbinfo.log.1”是 4.7 GB

答案1

考虑的是当前日志文件的大小 ( /mnt/log/frengo/apc_rtbinfo.log),该大小为 0。因此,无需旋转。

至于较旧的日志文件,logrotate不会持续监视文件,而是定期运行(每天,iirc)。如果在两次运行之间日志文件变得非常大,则直到下一次运行时它才会发现。

如果空间非常宝贵,只需gzip在大文件上运行:

gzip /mnt/log/frengo/apc_rtbinfo.log

它将被替换为一个更小的压缩文件。

您已同时使用sizedaily条件。然而,size基于时间的条件是相互排斥的。您应该使用以下maxsize条件:

maxsize size
      Log files are rotated when they grow bigger than size bytes even
      before the additionally specified time interval (daily,  weekly,
      monthly,  or yearly).  The related size option is similar except
      that it is mutually exclusive with the  time  interval  options,
      and  it  causes  log  files to be rotated without regard for the
      last rotation time.  When maxsize is used,  both  the  size  and
      timestamp of a log file are considered.

相关内容