Linux 系统日志的保留时间,可以通过配置 rsyslog 或 syslog-ng 来控制。以下介绍两种常用方法:
方法一:使用 rsyslog
-
打开 rsyslog 配置文件: 使用文本编辑器打开 rsyslog 配置文件,通常位于 /etc/rsyslog.conf 或 /etc/rsyslog.d/50-default.conf。 使用 sudo 命令以 root 权限编辑:
sudo nano /etc/rsyslog.conf
-
配置日志轮转: 在配置文件中添加或修改相关指令来设置日志轮转策略。例如,要保留 7 天的日志: (注意:以下配置示例仅供参考,实际配置需要根据你的系统和需求进行调整)
# 每天轮转日志文件,保留 7 天 $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M $MaxFileSize 10M *.log { rotate 7 size 10M }
-
重启 rsyslog 服务: 保存配置文件后,重启 rsyslog 服务使配置生效:
sudo systemctl restart rsyslog
(注意:以上配置示例仅供参考,实际应用中需要根据具体日志文件和系统情况进行调整。 rotate 7 表示保留 7 个日志文件,size 10M 表示每个日志文件最大 10MB。 您可以根据需要修改这些值。 建议先备份原配置文件,再进行修改。)
由于篇幅限制,方法二(使用 syslog-ng)在此略去,但其原理类似,只是配置文件路径和语法有所不同。 您可以参考 syslog-ng 的官方文档进行配置。
以上就是如何设置Linux syslog日志保留期限的详细内容,更多请关注知识资源分享宝库其它相关文章!
版权声明
本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com
发表评论