Centos / Linux设置logrotate为所有日志的最大文件大小 [英] Centos/Linux setting logrotate to maximum file size for all logs

查看:822
本文介绍了Centos / Linux设置logrotate为所有日志的最大文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用logrotate并每天运行一次...现在,在某些情况下,日志已显着增长(请参阅:gigbaytes)并杀死了我们的服务器。因此,现在我们想为日志设置最大文件大小...。

we use logrotate and it runs daily ... now we have had some situations where logs have grown significantly (read: gigbaytes) and killing our server. So now we would like to set a maximum filesize to the logs ....

我可以将其添加到logrotate.conf吗?

can I just add this to the logrotate.conf?


大小50M

size 50M

它将适用于所有日志文件吗?还是我需要基于每个日志进行设置?

and would it then apply to all log files? Or do I need to set this on a per log basis?

还是其他建议?

(ps 。我知道,如果您想收到通知,则日志会像描述的那样增长,而我们想要做的事情并不理想-但这总比无法登录好,因为没有可用空间了。

(ps. I understand that if you want to be notified is the log grows like described and what we want to do is not ideal - but it is better than not being able to logon anymore because there is no space available)

谢谢,肖恩

推荐答案

它指定日志文件的大小触发旋转。例如,一旦文件大小为50MB或更大,大小50M 就会触发日志轮换。您可以使用后缀 M 表示兆字节, k 表示千字节, G 表示千兆字节。如果不使用后缀,则将其表示为字节。您可以在最后检查示例。共有三个指令,分别是 size maxsize minsize 。根据联机帮助页

It specifies the size of the log file to trigger rotation. For example size 50M will trigger a log rotation once the file is 50MB or greater in size. You can use the suffix M for megabytes, k for kilobytes, and G for gigabytes. If no suffix is used, it will take it to mean bytes. You can check the example at the end. There are three directives available size, maxsize, and minsize. According to 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 和<$ c $的解释c> /var/log/httpd/error.log 。每当大小超过100k时,它们都会旋转一次,并且经过5次旋转后,旧日志文件会被邮寄(未压缩)到 www@my.org ,而不是被删除。 sharedscripts 表示 postrotate 脚本将只运行一次(压缩旧日志后),而不是一次对于每个旋转的日志。请注意,在本节开头,第一个文件名周围的双引号允许logrotate旋转名称中带有空格的日志。适用普通的shell引用规则,并支持 \ 个字符。

Here is an explanation for both files /var/log/httpd/access.log and /var/log/httpd/error.log. They are rotated whenever it grows over 100k in size, and the old logs files are mailed (uncompressed) to www@my.org after going through 5 rotations, rather than being removed. The sharedscripts means that the postrotate script will only be run once (after the old logs have been compressed), not once for each log which is rotated. Note that the double quotes around the first filename at the beginning of this section allows logrotate to rotate logs with spaces in the name. Normal shell quoting rules apply, with ,, and \ characters supported.

这篇关于Centos / Linux设置logrotate为所有日志的最大文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆