以下是节省Ubuntu syslog存储空间的方法:
/etc/logrotate.d/rsyslog
,设置日志文件大小(如size 100M
)和保留数量(如rotate 5
),启用压缩(compress
)。/var/log/syslog {
size 100M
rotate 5
compress
delaycompress
missingok
notifempty
create 640 root adm
}
journalctl
清理systemd日志:sudo journalctl --vacuum-size=500M
(限制总大小为500MB)或--vacuum-time=7d
(保留7天日志)。sudo truncate -s 0 /var/log/syslog
(清空当前日志)。/etc/rsyslog.conf
,将日志级别从info
调整为warning
,减少非关键日志记录。sudo systemctl disable rsyslog
),或通过rsyslog
配置过滤特定日志源。注意:修改配置前建议备份原文件,重启服务后验证日志是否正常轮转。