Linux日志清理(Centos)
原因
磁盘占用90%,利用df -hl & du -sh命令找到
/var/log/messages
/var/log/journal
占用过多,分析日志查看原因
大量:
Jun 20 03:40:31 iZbp14vt99zpj8dde2fdlmZ crond[208986]: No configuration file found at /root/.esmtprc or /etc/esmtprc
解决
1.查看当前日志占用空间大小
journalctl --disk-usage
[root@blog journal]# journalctl --disk-usage
Archived and active journals take up 3.9G in the file system.
2.指定日志文件保存日期
# 保存最近一周:journalctl --vacuum-time=1w
# 保存最近一年:journalctl --vacuum-time=1years
[root@blog journal]# journalctl --vacuum-time=1w
Vacuuming done, freed 0B of archived journals from /var/log/journal/20210318142909815972522070876808.
3.指定日志文件最大空间
# 只保留500MB的日志:journalctl --vacuum-size=500M
# 只保留1GB的日志:journalctl --vacuum-size=1G
[root@blog journal]# journalctl --vacuum-size=500M
Vacuuming done, freed 3.5G of archived journals from /var/log/journal/20210318142909815972522070876808.