linux 是否可以限制消息大小

linux 是否可以限制消息大小

我现在使用的是centos 7,我发现/var/log/messages太大了。是否可以限制消息的大小?这是消息大小:

[root@k8smasterone log]# duc ls -Fg /var/log
  1.1G messages-20221125             [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]
  1.1G messages-20221126             [++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++      ]
619.5M messages                      [+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++                                                                   ]
389.0M pods/                         [+++++++++++++++++++++++++++++++++++++++++++++++                                                                                               ]
 86.9M sa/                           [++++++++++                                                                                                                                    ]
 60.0M journal/                      [+++++++                                                                                                                                       ]
 35.4M audit/                        [++++                                                                                                                                          ]
 31.5M calico/                       [+++                                                                                                                                           ]
  1.2M dnf.librepo.log-20221030      [                                                                                                                                              ]
  1.2M dnf.librepo.log-20221113      [                                                                                                                                              ]
  1.2M dnf.librepo.log-20221120      [                                                                                                                                              ]
  1.2M dnf.librepo.log-20221106      [                                                                                                                                              ]
  1.2M dnf.librepo.log               [

答案1

logrotate,至少在 opensuse 上,将使用某些规则轮换、压缩和删除旧日志文件。您可以配置重命名和压缩之前原始日志文件的大小、使用何种压缩以及在丢弃之前保留多少旧的压缩日志文件。

答案2

除了旋转日志之外,实际查看日志内部并找出它为何如此大可能会有所帮助。假设轮换工作正常,可能有一个损坏的服务需要禁用、修复或需要关闭其调试消息。

或者,可以添加系统日志规则以将违规噪音制造者过滤到其自己的文件中,或完全删除其部分或全部内容。如果将其移动到自己的日志文件中,您还可以为其设置更快的日志轮换计划。这么大的东西可能会压缩得很好。

相关内容