systemd-journal-flush.service 因结果超时而失败 - 无法启动将日志刷新到持久存储

systemd-journal-flush.service 因结果超时而失败 - 无法启动将日志刷新到持久存储

我在我的 systemctl 日志中看到这一点,systemd-journal-flush.service 因超时错误而无法启动。不过服务器显然运行良好。操作系统是 CentOS 8。日志没有详细说明该错误。如果有人可以帮助我,我很感激。

#sudo systemctl start systemd-journal-flush.service
Job for systemd-journal-flush.service failed because a timeout was exceeded.


#systemctl status systemd-journal-flush.service
● systemd-journal-flush.service - Flush Journal to Persistent Storage
   Loaded: loaded (/usr/lib/systemd/system/systemd-journal-flush.service; static; vendor preset: disabled)
   Active: failed (Result: timeout) since Sat 2023-03-18 04:08:07 GMT; 3min 28s ago
     Docs: man:systemd-journald.service(8)
           man:journald.conf(5)
  Process: 13447 ExecStart=/usr/bin/journalctl --flush (code=killed, signal=TERM)
 Main PID: 13447 (code=killed, signal=TERM)

Mar 18 04:06:37 systemd[1]: Starting Flush Journal to Persistent Storage...
Mar 18 04:08:07 systemd[1]: systemd-journal-flush.service: start operation timed out. Terminating.
Mar 18 04:08:07 systemd[1]: systemd-journal-flush.service: Main process exited, code=killed, status=15/TERM
Mar 18 04:08:07 systemd[1]: systemd-journal-flush.service: Failed with result 'timeout'.
Mar 18 04:08:07 systemd[1]: Failed to start Flush Journal to Persistent Storage.


#journalctl -xe
Mar 18 04:06:37 systemd[1]: Starting Flush Journal to Persistent Storage...
-- Subject: Unit systemd-journal-flush.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit systemd-journal-flush.service has begun starting up.
Mar 18 04:06:37 systemd-journald[860]: Runtime journal (/run/log/journal/9b0915b205da456da00e935c8704118b) is 14.3M, max 38.3M, 23.9M free.
-- Subject: Disk space used by the journal
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Runtime journal (/run/log/journal/9b0915b205da456da00e935c8704118b) is currently using 14.3M.
-- Maximum allowed usage is set to 38.3M.
-- Leaving at least 57.5M free (of currently available 368.6M of disk space).
-- Enforced usage limit is thus 38.3M, of which 23.9M are still available.
--
-- The limits controlling how much disk space is used by the journal may
-- be configured with SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=,
-- RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize= settings in
-- /etc/systemd/journald.conf. See journald.conf(5) for details.
Mar 18 04:06:42 dbus-daemon[1068]: [system] Activating via systemd: service name='org.freedesktop.timedate1' unit='dbus-org.freedesktop.timedate1.service' requested by ':1.718' (uid=0 pid=10797 comm="cockpit-bridge --privileged " label="unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023")
Mar 18 04:06:42 systemd[1]: Starting System clock and RTC settings service...
-- Subject: Unit timedatex.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit timedatex.service has begun starting up.
Mar 18 04:06:42 dbus-daemon[1068]: [system] Successfully activated service 'org.freedesktop.timedate1'
Mar 18 04:06:42 systemd[1]: Started System clock and RTC settings service.
-- Subject: Unit timedatex.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit timedatex.service has finished starting up.
--
-- The start-up result is done.
Mar 18 04:08:07 systemd[1]: systemd-journal-flush.service: start operation timed out. Terminating.
Mar 18 04:08:07 systemd[1]: systemd-journal-flush.service: Main process exited, code=killed, status=15/TERM
Mar 18 04:08:07 systemd[1]: systemd-journal-flush.service: Failed with result 'timeout'.

答案1

守护journald进程不会刷新,/var/log/journal因为该目录不存在,并且/etc/systemd/journald.conf不会告诉它创建该目录。不幸的是,journalctl --flush等待刷新完成,但它永远不会完成。

对我有用的解决方案是这样的:

  1. sudoedit /etc/systemd/journald.conf
  2. 在该[Journal]行后面添加一行内容:Storage=persistent
  3. 重启。

如果您阅读手册页,您将看到与默认值journald.conf(5)有何不同的解释:persistentauto

“auto”与“persistent”类似,但/var/log/journal 如果需要,则不会创建目录,因此它的存在控制着日志数据的去向。

通过更改配置并重新启动,您可以使用journald正确的权限创建丢失的目录(显然,owner=root、group=systemd-journal、mode=02755,并且 ACL 授予r-x对组 adm 和组的显式访问权限)车轮)。当然,您可以自己创建它,而无需重新启动。

答案2

这是由一个错误引起的已修复于 systemd-239-75.el8

按照其他注释中的建议将行添加Storage=persistent到 /etc/systemd/journald.conf 切换到持久日志记录(它将日志写入磁盘而不是使用非持久环形缓冲区)。

相关内容