Linux Journal 的日志太大

位于/var/log/journal文件夹下面的journal 日志太大,一般系统限制为4GB, 对于一些硬盘比较小的VM就不太友好了

这个是由systemd-journal引起的,我们需要clean it 和limit its growth

Clean Existing Logs

Check current disk usage:

journalctl --disk-usage

Delete logs older than a certain time (e.g., 7 days):

journalctl --vacuum-time=7d

Or limit total size (e.g., 500MB):

journalctl --vacuum-size=500M

Or keep only N logs (e.g., last 10 boots):

journalctl --vacuum-files=10

 

Prevent Logs from Growing Too Large

Edit the persistent journal configuration:

sudo nano /etc/systemd/journald.conf

Look for or add these lines:

SystemMaxUse=500M
SystemKeepFree=100M
SystemMaxFileSize=100M
SystemMaxFiles=10

Then restart systemd-journald:

sudo systemctl restart systemd-journald

 

(Optional) Disable Persistent Journaling

If you don’t need persistent logs across reboots:

sudo rm -rf /var/log/journal
sudo mkdir /run/log/journal
sudo systemctl restart systemd-journald

This means logs will be lost after reboot.

对于我个人来说,我喜欢做如下设置:

journalctl --vacuum-size=200M

然后在/etc/systemd/journald.conf 中设置

SystemMaxUse=200M

SystemMaxFileSize=100M

最后重启journald服务

systemcl restart systemd-journald

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.