systemd-journald 服务收集到的日志默认保存在 /run/log 目录中,重启系统会丢掉以前的日志信息。 我们可以通过两种方式让 systemd-journald 服务把所有的日志都保存到文件中,这样重新启动后就不会丢掉以前的日志。
修改配置文件 /etc/systemd/journald.conf,把 Storage=auto 改为 Storage=persistent,并取消注释,然后重启日志服务 systemd-journald.service。
$ sudo systemctl restart systemd-journald.service
日志默认路径:/var/log/journal
$ sudo journalctl --disk-usage
journalctl --since "2022-07-25 18:20:00"
journalctl -f
journalctl --vacuum-size=1G
journalctl --vacuum-time=30d
journalctl --verify
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-0000000000248071-0005e13a544505c3.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-0000000000264efe-0005e192c5ae3241.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-0000000000281da0-0005e1ed4a4beb02.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-000000000029e1a5-0005e24d4ceda9da.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-00000000002ba357-0005e2aebcba08b8.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-00000000002d63db-0005e310f588fa35.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-00000000002f253c-0005e3739d2e28da.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-000000000030d904-0005e3ddc558a1ed.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system@703a195f73d54f21a4a62c6c7185d81f-000000000032800e-0005e44db7e6e44b.journal
PASS: /var/log/journal/ee3d65d2ec764918b227155a874f2cd9/system.journal