Jak*_*ruk 6 linux bash logging systemd
我的日志有问题journalctl,它没有显示超过一小时的日志。
第一个日志条目大约是一小时前,而不是要求的 2 天前。
$ date -u
Wed May 13 08:59:21 UTC 2020
$ sudo journalctl --utc --since="2 days ago" -n 1 --no-pager -u datalake-profile-table-error-worker@1.service
-- Logs begin at Tue 2020-03-17 17:30:22 UTC, end at Wed 2020-05-13 09:00:10 UTC. --
May 13 08:11:03 <log content>
Run Code Online (Sandbox Code Playgroud)
服务已于 5 天前开通:
$ sudo systemctl status datalake-profile-table-error-worker@1.service
...
Active: active (running) since Thu 2020-05-07 15:45:47 CEST; 5 days ago
...
Run Code Online (Sandbox Code Playgroud)
jorunalctd.conf不过看起来并不可疑:
$ cat /etc/systemd/journald.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.
[Journal]
Storage=persistent
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitInterval=30s
#RateLimitBurst=1000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
Run Code Online (Sandbox Code Playgroud)
这是一种重复的模式,我看到了大约上一小时的日志。可能是什么原因?
编辑
不幸的是,正如 @Peleion 提到的,这不是寻呼机大小限制的问题。
附加限制--until不显示任何消息(并且不显示任何-- No entries --信息)。
$ sudo journalctl --utc --since="2 days ago" --until="yesterday" -n 1 --no-pager -u datalake-profile-table-error-worker@1.service # with additional `--until` filter no messages are shown
-- Logs begin at Tue 2020-03-17 17:30:22 UTC, end at Thu 2020-05-14 09:14:04 UTC. --
$ sudo journalctl --utc --since="2 days ago" --no-pager -u datalake-profile-table-error-worker@1.service | wc -l # logs more than 1k entities
17661
$ sudo journalctl -p err --utc --since="2 days ago" -n 1 --no-pager -u datalake-profile-table-error-worker@1.service # here we have explicit info that there're no entries
-- Logs begin at Tue 2020-03-17 17:30:22 UTC, end at Thu 2020-05-14 09:14:21 UTC. --
-- No entries --
Run Code Online (Sandbox Code Playgroud)
编辑2
我们最终将数据记录到单独的文件中,而不是使用日志。
丢失日志有很多神秘的问题。
期刊一直使用约2.5-3GB:
Archived and active journals take up 3.1G in the file system.
Run Code Online (Sandbox Code Playgroud)
负责运行worker的用户的文件大小在30到60MB之间:
/var/log/journal/<hash>/user-<user id>.journal
Run Code Online (Sandbox Code Playgroud)
Journalctl 分页器默认为最近的 1,000 个条目。不幸的是,一小时内的条目数量在当前的 Fedora 安装中很常见。日记条目仍然存在(达到最大日记文件存储空间),但您一次只能看到 1,000 个。
使用 --since 和 --until 一起指定特定的 1,000 个条目时间块,或使用 --user 指定特定用户或任何其他选项,将输出限制为具有更大时间片的 1,000 个缓冲区。
Archlinux 文档对选项有很好的介绍
编辑:您的日记似乎也没有刷新到持久存储中。RH/Centos/Fedora#Storage=auto在 /etc/systemd/journald.conf 中有默认设置。您可以尝试将其注释掉或将其设置为自动并重新启动 systemd。