我们使用logrotate,它每天运行...现在我们遇到了一些情况,日志(log)显著增加(读:gigbaytes),并导致服务器死机.所以现在我们想设置日志(log)的最大文件大小....

我能把这个加到日志(log)里吗.形态?

50米

然后它会应用于所有日志(log)文件吗?还是需要按日志(log)设置?

或者其他建议?

(顺便说一句,我知道如果你想得到通知,日志(log)会像上面描述的那样增长,我们想要做的并不理想——但这总比因为没有可用空间而无法登录要好)

谢谢,肖恩

推荐答案

它指定触发旋转的log file的大小.例如,一旦文件大小为50MB或更大,size 50M将触发日志(log)旋转.您可以使用后缀M表示兆字节,k表示千字节,G表示千兆字节.如果没有使用后缀,则表示字节.你可以在最后判断这个例子.有三个指令可供 Select :sizemaxsizeminsize.根据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.logk时,它们就会被旋转,而旧日志(log)文件在经过5次旋转后会被邮寄(未压缩)到www@my.org,而不是被删除.sharedscripts意味着postrotate脚本将只运行一次(在旧日志(log)被压缩之后),而不是针对每个旋转的日志(log)运行一次.请注意,本节开头第一个文件名周围的双引号允许logrotate使用名称中的空格来旋转日志(log).正常的shell引用规则适用,支持,\个字符.

Linux相关问答推荐

Git - 打印以不同编码混合的文件

ShellScript,有更好的方法来查找具有特定名称和日期的文件吗?

在 Linux 中屏蔽文件中的位 - 按位运算

如何使 awk 输出更具可读性?

awk 打印除最后一列以外的所有内容 + 最后一列

命令应在终端关闭后继续运行

如何重新安装最新的 cmake 版本?

在不调试的情况下查找哪个汇编指令导致了非法指令错误

在 Python 上模拟鼠标点击

如何在第一个错误时停止 xargs?

如何从 Linux 中的用户空间访问物理地址?

Mac OS X 中的 ldconfig 等效项?

在 bash 中将输出作为 cp 的参数传递

用于提取 IP 地址的 Linux bash 脚本

在 Linux / Mono 上运行 ServiceStack 的最佳方式是什么?

ngrok 如何在防火墙后工作?

在 shell 脚本的 for 循环中迭代行而不是单词

svn over HTTP 代理

内联 if shell 脚本

将 BlueZ Stack 用作外设(广告商)