当前位置: 首页 > 面试题库 >

Centos / Linux设置logrotate为所有日志的最大文件大小

谷出野
2023-03-14
问题内容

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

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

大小50M

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

或其他建议?

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

谢谢,肖恩


问题答案:

它指定要触发轮换的 日志文件 的大小。例如,size 50M一旦文件大小为50MB或更大,将触发日志轮换。您可以将后缀M用于兆字节,k千字节和G千兆字节。如果不使用后缀,则将其表示为字节。您可以在最后检查示例。有三个指令可用sizemaxsizeminsize。根据手册页:

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。每当大小超过100k时,它们都会旋转一次,并且www@my.org经过5次旋转后会将旧日志文件邮寄(未压缩)到,而不是将其删除。这sharedscripts意味着该postrotate脚本将只运行一次(在压缩旧日志之后),而不是为每个循环日志运行一次。请注意,在本节的开头,第一个文件名周围的双引号允许logrotate旋转名称中带有空格的日志。会使用普通的shell引用规则,并带有,\字符。



 类似资料:
  • 我正在配置服务器上的记录器,以便每天压缩日志。我还需要确保单个日志文件不会变得太大(比如每个文件10MB)。 这两种方法都不起作用,但首先我想解决文件大小的问题。 这是我的log4j。属性文件: 我们使用log4j1.2。17,现在我添加了同一版本的log4j额外功能。 当我测试日志记录时,它会创建任意大文件。我试着用maximumFileSize和MaxFileSize代替MaxFileSize

  • 我没有任何方法在接口中获取文件大小。那么,有什么方法可以限制webflux中上传文件的最大大小,而不是复制它呢?我知道有像这样的标题,但是看起来并不安全。

  • 我正在使用JHipster开发基于Spring Boot和AngularJS的应用程序。我的问题是如何设置上传文件的最大大小? 如果我试图上传到大文件,我会在控制台中获得以下信息: 和状态为500的服务器响应。 怎么设置?

  • 我希望你一切都好。 我正在用MySQL和AdminLTE3用纯PHP创建一个学习平台。 我到了为每个用户创建文件管理器的时候,遇到了以下问题。 我在文件夹中有以下结构: ,我要找的是每个文件夹每个用户的最大大小是2GB。 我正在使用MacOs BigSur进行开发,但在生产中它将在Ubuntu Server 18上! 我没有尝试设置,我正在尝试将每个用户文件夹的最大大小设置为2GB

  • 您可以使用基于浏览器的上传(不是多部分上传)中的内容长度范围字段来限制文件大小:http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html 你怎么能在多部分上传中限制它?我正在使用EvaporateJS。

  • 本文向大家介绍Linux中logrotate日志轮询操作总结,包括了Linux中logrotate日志轮询操作总结的使用技巧和注意事项,需要的朋友参考一下 前言 对于Linux系统安全来说,日志文件是极其重要的工具。不知为何,我发现很多运维同学的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相发明自己的轮子,这真是让人沮丧啊!就好比明明身边躺