设置
在内核 4.19.62 上使用 systemd 244 (244.5+)。
我想将总日志存储大小设置为 100MB。Journald 设置为易失性存储,因此日志结束,/run/log/journal/...
并且应该使用RuntimeMaxUse在/etc/systemd/journald.conf中设置存储配额,如下所示:
[Journal]
Storage=volatile
RuntimeMaxUse=100M
RuntimeMaxFileSize=2M
通过调整这些配置值,日志日志大小和配额确实会发生变化,并且 journalctl 中的启动消息也会显示变化。
在配置值更改之间,我停止 systemd-journald.service,删除所有system*
文件/run/log/journal/...
并重新启动服务。
注意:当Storage=persistent
和日志使用时/var/log/journal/
,等效的SystemMaxUse得到正确尊重。这似乎只是 volatile/RuntimeMaxUse 中的一个错误。
观察到的错误
Runtime MaxUse (100M) 被忽略。只要 Runtime MaxFileSize小于 32M ,日志配额就设置为64MB 。
如果 Runtime MaxFileSize设置为大于 32M,则日志配额设置为该值的两倍。
在这两种情况下,运行时MaxUse似乎都被忽略了。
这是 journald/systemd 配置处理中的错误吗?为什么 Runtime MaxUse被忽略,而使用 64M 或 double Runtime MaxFileSize作为日志配额?
我看到日志源中有几个地方可以将 max_use 设置为双倍 max_size:
- https://github.com/systemd/systemd/blob/v244/src/journal/journal-file.c#L3747
- https://github.com/systemd/systemd/blob/v244/src/journal/journal-file.c#L3772
错误示例
设置了64M 的配额(RuntimeMaxUse=100M
而RuntimeMaxFileSize=2M
不是我要求的 100M),如日志启动消息中所示:
systemd-journald[20312]: Runtime Journal (/run/log/journal/...) is 2.0M, max 64.0M, 62.0M free.
-- Runtime Journal (/run/log/journal/...) is currently using 2.0M.
-- Maximum allowed usage is set to 64.0M.
-- Leaving at least 1.5G free (of currently available 31.2G of disk space).
-- Enforced usage limit is thus 64.0M, of which 62.0M are still available.
使用RuntimeMaxUse=100M
and RuntimeMaxFileSize=31M
,仍然使用 64M:
systemd-journald[20989]: Runtime Journal (/run/log/journal/...) is 8.0M, max 64.0M, 56.0M free.
-- Runtime Journal (/run/log/journal/...) is currently using 8.0M.
-- Maximum allowed usage is set to 64.0M.
-- Leaving at least 1.5G free (of currently available 31.2G of disk space).
-- Enforced usage limit is thus 64.0M, of which 56.0M are still available.
使用RuntimeMaxUse=100M
and RuntimeMaxFileSize=33M
,配额最终为 66M:
systemd-journald[21557]: Runtime Journal (/run/log/journal/...) is 8.0M, max 66.0M, 58.0M free.
-- Runtime Journal (/run/log/journal/...) is currently using 8.0M.
-- Maximum allowed usage is set to 66.0M.
-- Leaving at least 1.5G free (of currently available 31.2G of disk space).
-- Enforced usage limit is thus 66.0M, of which 58.0M are still available.
使用RuntimeMaxUse=100M
并且RuntimeMaxFileSize=200M
我们突破了 100M 的限制,400M 似乎来自 200M 的 RuntimeMaxFileSize 的两倍:
systemd-journald[25271]: Runtime Journal (/run/log/journal/...) is 8.0M, max 400.0M, 392.0M free.
-- Runtime Journal (/run/log/journal/...) is currently using 8.0M.
-- Maximum allowed usage is set to 400.0M.
-- Leaving at least 1.5G free (of currently available 31.2G of disk space).
-- Enforced usage limit is thus 400.0M, of which 392.0M are still available.