相关疑难解决方法(0)

除非日志超过特定大小,否则如何根据间隔轮换日志?

从 logrotate 的手册页:

minsize size
日志文件在大于 size 字节时轮换,但不会在额外指定的时间间隔(每天、每周、每月或每年)之前轮换。相关的大小选项类似,只是它与时间间隔选项互斥,并且它会导致日志文件轮换而不考虑上次轮换时间。使用 minsize 时,会同时考虑日志文件的大小和时间戳。

size size
日志文件在增长到大于 size 字节时进行轮换。如果 size 后跟 k,则假定大小以千字节为单位。如果使用M,则大小以兆字节为单位,如果使用G,则大小以千兆字节为单位。所以大小 100、大小 100k、大小 100M 和大小 100Gare 都是有效的。

我将大小设置为5M,将间隔设置每周,认为日志将每周轮换一次,如果日志的大小超过 5M,则会发生额外的轮换。但是发生的情况是日志不会被轮换,除非它超过 5M,这似乎是minsize应该做的。

我是否错误地解释了手册?如果日志超过 5M,如何让日志每周轮换一次?

编辑:

我不确定以下信息是否相关,仅作为补充:

我正在使用 rsyslog 对消息、安全、cron、邮件日志、引导进行主要日志记录。以下是倒数第二个日志的轮换日期和文件大小,其中大小和间隔的设置如上所述:

filename  rotation date  file size
messages  20130129       5.3MB
secure    20130113       5.1kB
cron      20130113       3.6kB
maillog   20130113       1.1kB
Run Code Online (Sandbox Code Playgroud)

可以看出,只有消息被轮换。

编辑2:

我应该检查一下man logrotate。他们实际上使用maxsize选项升级了它。这应该是我正在寻找的:

maxsize size
当日志文件在额外指定的时间间隔(每天、每周、每月或每年)之前增长超过 size 字节时,它们会被轮换。相关的大小选项类似,只是它与时间间隔选项互斥,并且它会导致日志文件轮换而不考虑上次轮换时间。使用 maxsize 时,会同时考虑日志文件的大小和时间戳。

configuration logrotate

21
推荐指数
1
解决办法
2万
查看次数

Logrotate 不旋转

我已经为 logrotate 设置了新的 conf,但我无法让它工作。

这是我的 logrotate:

/home/deployer/abc/shared/log/*.log {
  daily
  missingok
  rotate 30
  compress
  delaycompress
  size 5M
  copytruncate
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

删除状态文件:

deployer@qapp01:~/abc/current/log$ cat /var/lib/logrotate/status 
logrotate state -- version 2
Run Code Online (Sandbox Code Playgroud)

使用调试模式运行 logrotate

deployer@qapp01:~/abc/current/log$ /usr/sbin/logrotate -d /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file apt
reading config file aptitude
reading config file dpkg
reading config file fail2ban
reading config file monit
reading config file mysql-server
reading config file newrelic-sysmond
reading config file nginx
reading config file ppp
reading config file abc …
Run Code Online (Sandbox Code Playgroud)

logrotate

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

logrotate ×2

configuration ×1