linux服务器日志清理小记
摘自:https://www.cnblogs.com/rusking/p/12450625.html
1. 查看/var/log
du -hm --max-depth=1 /var/log | sort -n
# du -hm --max-depth=1 /var/log | sort -n
1 /var/log/anaconda
1 /var/log/chrony
1 /var/log/multi-nic-util
1 /var/log/ntpstats
1 /var/log/php-fpm
1 /var/log/rhsm
1 /var/log/tuned
18 /var/log/sa
40 /var/log/audit
60 /var/log/httpd
121 /var/log/journal
868 /var/log
2. 查看日志占用存储
journalctl --disk-usage
# journalctl --disk-usage
Archived and active journals take up 120.0M on disk.
3. journalctl 命令自动维护文件大小
1)只保留近一周的日志
journalctl --vacuum-time=1w
2)只保留500MB的日志
journalctl --vacuum-size=500M
4. 删除/var/
# cd /var/log/httpd/
# echo ''>access_log
# echo ''>error_log
并且手动删除该目录下其它备份的日志文件。
5. 设置定时任务自动清理journal日志文件(每周日执行下面的命令,保保留500M的日志)
# crontab -l
6 /usr/bin/journalctl --vacuum-size=500M