我们使用logrotate,它每天运行...现在我们遇到了一些情况,日志(log)显著增加(读:gigbaytes),并导致服务器死机.所以现在我们想设置日志(log)的最大文件大小....
我能把这个加到日志(log)里吗.形态?
50米
然后它会应用于所有日志(log)文件吗?还是需要按日志(log)设置?
或者其他建议?
(顺便说一句,我知道如果你想得到通知,日志(log)会像上面描述的那样增长,我们想要做的并不理想——但这总比因为没有可用空间而无法登录要好)
谢谢,肖恩
我们使用logrotate,它每天运行...现在我们遇到了一些情况,日志(log)显著增加(读:gigbaytes),并导致服务器死机.所以现在我们想设置日志(log)的最大文件大小....
我能把这个加到日志(log)里吗.形态?
50米
然后它会应用于所有日志(log)文件吗?还是需要按日志(log)设置?
或者其他建议?
(顺便说一句,我知道如果你想得到通知,日志(log)会像上面描述的那样增长,我们想要做的并不理想——但这总比因为没有可用空间而无法登录要好)
谢谢,肖恩
它指定触发旋转的log file的大小.例如,一旦文件大小为50MB或更大,size 50M
将触发日志(log)旋转.您可以使用后缀M
表示兆字节,k
表示千字节,G
表示千兆字节.如果没有使用后缀,则表示字节.你可以在最后判断这个例子.有三个指令可供 Select :size
、maxsize
和minsize
.根据manpage:
minsize size
Log files are rotated when they grow bigger than size bytes,
but not before the additionally specified time interval (daily,
weekly, monthly, or yearly). The related size option is simi-
lar 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 minsize is used, both the
size and timestamp of a log file are considered.
size size
Log files are rotated only if they grow bigger then size bytes.
If size is followed by k, the size is assumed to be in kilo-
bytes. If the M is used, the size is in megabytes, and if G is
used, the size is in gigabytes. So size 100, size 100k, size
100M and size 100G are all valid.
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.
下面是一个例子:
"/var/log/httpd/access.log" /var/log/httpd/error.log {
rotate 5
mail www@my.org
size 100k
sharedscripts
postrotate
/usr/bin/killall -HUP httpd
endscript
}
下面是对文件/var/log/httpd/access.log
和/var/log/httpd/error.log
的解释.当日志(log)文件的大小超过/var/log/httpd/access.log
k时,它们就会被旋转,而旧日志(log)文件在经过5次旋转后会被邮寄(未压缩)到www@my.org
,而不是被删除.sharedscripts
意味着postrotate
脚本将只运行一次(在旧日志(log)被压缩之后),而不是针对每个旋转的日志(log)运行一次.请注意,本节开头第一个文件名周围的双引号允许logrotate使用名称中的空格来旋转日志(log).正常的shell引用规则适用,支持,
和\
个字符.