“journalctl”数据存储在哪里?

php*_*_qq 73 log systemd systemd-journald

当我发出时,journalctl我会得到所有系统服务的大量日志,但所有这些信息都存储在哪里?

mur*_*uru 53

来自man systemd-journald

FILES
       /etc/systemd/journald.conf
           Configure systemd-journald behavior. See journald.conf(5).

       /run/log/journal/machine-id/*.journal,
       /run/log/journal/machine-id/*.journal~,
       /var/log/journal/machine-id/*.journal,
       /var/log/journal/machine-id/*.journal~
           systemd-journald writes entries to files in
           /run/log/journal/machine-id/ or /var/log/journal/machine-id/ with
           the ".journal" suffix. If the daemon is stopped uncleanly, or if
           the files are found to be corrupted, they are renamed using the
           ".journal~" suffix, and systemd-journald starts writing to a new
           file.  /run is used when /var/log/journal is not available, or when
           Storage=volatile is set in the journald.conf(5) configuration file.
Run Code Online (Sandbox Code Playgroud)

正如man journalctl所说:

journalctl may be used to query the contents of the systemd(1) journal
as written by systemd-journald.service(8).
Run Code Online (Sandbox Code Playgroud)

这些日志由systemd-journald服务管理,因此更合适的术语是“journald日志”。

  • 好吧,日志可以安全删除,除非您以后需要它们的信息。 (6认同)

sol*_*iCe 19

但是请注意,默认情况下,Ubuntu 不使用持久日志文件。只有 volatile/run/log/journal/<machine-id>/*.journal[~]会保留到下次启动。每次重新启动都会丢失所有内容。

您可能会看到日志中保留的引导列表:

journalctl --list-boot
Run Code Online (Sandbox Code Playgroud)

日志仍然保存在一个文本文件中,/var/log除非您通过创建/var/log/journal目录激活了持久日志日志的使用。

  • 然而,journald 日志可以说*应该*默认是持久的。[bug #1618188] (https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1618188) 已打开以跟踪此更改的进度。检查那里的最新状态。 (5认同)

Dem*_*a ツ 9

简答

通常存储目录是/var/log/journal/run/log/journal,但它不一定存在于您的系统中。

如果您只想检查日志当前在磁盘上占用的空间量,只需键入:

$ journalctl --disk-usage
Run Code Online (Sandbox Code Playgroud)

长答案

存储目录取决于 journald 配置。

配置文件是:

/etc/systemd/journald.conf
/etc/systemd/journald.conf.d/*.conf
/run/systemd/journald.conf.d/*.conf
/usr/lib/systemd/journald.conf.d/*.conf
Run Code Online (Sandbox Code Playgroud)

Storage=”选项控制是否存储日志数据,以及在哪里。可能的值为“ volatile”、“ persistent”、“ auto”和“ none”。默认为“ auto”。

如果是“ volatile”,则日志日志数据将仅存储在内存中,即低于 /run/log/journal 层次结构(如果需要则创建)。

如果“ persistent”,数据将优先存储在磁盘上,即低于 /var/log/journal 层次结构(如果需要创建),并回退到 /run/log/journal(如果需要创建),在早期启动,如果磁盘不可写。

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

" none" 关闭所有存储,所有收到的日志数据都将被删除。