Journald : Basic Usage
2025/01/04 |
This is Basic Usage of Journald that is the Log Management Service Daemon. |
|
[1] | By default, Journald is running and almost all logging data on the System are collected by Journald. Therefore, if [Journald (systemd-journald.service, systemd-journald.socket, systemd-journald-dev-log.socket)] would be down, collecting of almost all logging data will also stop. |
[root@dlp ~]# systemctl status systemd-journald.service ● systemd-journald.service - Journal Service Loaded: loaded (/usr/lib/systemd/system/systemd-journald.service; static) Active: active (running) since Sat 2025-01-04 10:20:36 JST; 10min ago Invocation: 16df889cd2f143089383e4a702696b11 TriggeredBy: ● systemd-journald.socket ○ systemd-journald-audit.socket ● systemd-journald-dev-log.socket Docs: man:systemd-journald.service(8) man:journald.conf(5) Main PID: 708 (systemd-journal) Status: "Processing requests..." Tasks: 1 (limit: 23143) FD Store: 12 (limit: 4224) Memory: 1.7M (peak: 6M) CPU: 39ms CGroup: /system.slice/systemd-journald.service +-- 708 /usr/lib/systemd/systemd-journald |
[2] | The default settings for journald can be viewed in [/usr/lib/systemd/journald.conf]. By default, all settings are commented, but the values listed are the default values. If you want to override the default values, create [/etc/systemd/journald.conf] and set the values. |
[root@dlp ~]# cat /usr/lib/systemd/journald.conf [Journal] #Storage=auto #Compress=yes #Seal=yes #SplitMode=uid #SyncIntervalSec=5m #RateLimitIntervalSec=30s #RateLimitBurst=10000 #SystemMaxUse= #SystemKeepFree= #SystemMaxFileSize= #SystemMaxFiles=100 #RuntimeMaxUse= #RuntimeKeepFree= #RuntimeMaxFileSize= #RuntimeMaxFiles=100 #MaxRetentionSec= #MaxFileSec=1month #ForwardToSyslog=no #ForwardToKMsg=no #ForwardToConsole=no #ForwardToWall=yes #TTYPath=/dev/console #MaxLevelStore=debug #MaxLevelSyslog=debug #MaxLevelKMsg=notice #MaxLevelConsole=info #MaxLevelWall=emerg #LineMax=48K #ReadKMsg=yes Audit= |
[3] | The place of stored logging data is set on [Storage=***] of [/usr/lib/systemd/journald.conf]. |
# parameters of [Storage=***] # # volatile : stored only in memory : under the [/run/log/journal] # persistent : stored on disk : under the [/var/log/journal] # but if impossible to write on disk like early boot, fallback to memory # auto : stored on disk if [/var/log/journal] exists # if not exists, stored in memory # none : not stored all data # but forwarding to other targets like Syslog daemon if they are configured # # * storing in memory is not persistent, when system restarted, logging data are cleared # on default settings of CentOS Stream 9, it's set [auto] and also # [/var/log/journal] does not exist, so logging data are stored in [/run/log/journal]
[root@dlp ~]#
grep Storage /usr/lib/systemd/journald.conf #Storage=auto
[root@dlp ~]#
[root@dlp ~]# ll -d /var/log/journal ls: cannot access '/var/log/journal': No such file or directory ll /run/log/journal total 0 drwxr-s---+ 2 root systemd-journal 60 Jan 4 10:20 13e0d866d1054d54a96f6690117098a8 # [/run/log] on CentOS Stream is [tmpfs] filesystem # [tmpfs] is on memory # for [tmpfs] partition size, it's set as half of physical memory size if not set manually # the size is not kept always on memory but it's used dynamically as needed df -h /run/log Filesystem Size Used Avail Use% Mounted on tmpfs 731M 8.6M 722M 2% /run # if you'd like to change stored place to disk, create the [/var/log/journal] directory [root@dlp ~]# mkdir /var/log/journal [root@dlp ~]# systemctl restart systemd-journald.service \
systemd-journald.socket \ systemd-journal-flush.service
[root@dlp ~]#
[root@dlp ~]# ll /run/log/journal total 0 ll /var/log/journal total 0 drwxr-xr-x. 2 root root 28 Jan 4 10:48 13e0d866d1054d54a96f6690117098a8 # * Note # on default settings of CentOS Stream, Rsyslog which is the syslog daemon is also running and # it stores logging data received from Journald in [/var/log] directory # so logging data are stored on disk even if not change storage setting of Journald # Rsyslog imports logging data from Journald with Rsyslog [imjournal] module, so # [ForwardToSyslog=***] parameters on Journald does not influence to sending data to Rsyslog |
[4] | To show stored logging data by Journald, it's possible with [journalctl] command. |
# show all data without any option : results are send to [less] command # if not send to [less], add [--no-pager] option # if use pager and would like to display all content of a line, send to [more] command [root@dlp ~]# journalctl Jan 04 10:20:34 localhost kernel: Linux version 6.12.0-35.el10.x86_64 (mockbuil> Jan 04 10:20:34 localhost kernel: Command line: BOOT_IMAGE=(hd0,gpt2)/vmlinuz-6> Jan 04 10:20:34 localhost kernel: BIOS-provided physical RAM map> ..... ..... # [-u UNIT] : show logs of a specific UNIT [root@dlp ~]# journalctl -u sshd.service Jan 04 10:20:38 dlp.srv.world systemd[1]: Starting sshd.service - OpenSSH serve> Jan 04 10:20:38 dlp.srv.world (sshd)[938]: sshd.service: Referenced but unset e> Jan 04 10:20:38 dlp.srv.world sshd[938]: Server listening on 0.0.0.0 port 22. Jan 04 10:20:38 dlp.srv.world systemd[1]: Started sshd.service - OpenSSH server> Jan 04 10:20:38 dlp.srv.world sshd[938]: Server listening on :: port 22. ..... .....[root@dlp ~]# journalctl -u systemd-tmpfiles-clean.timer Jan 04 10:20:37 dlp.srv.world systemd[1]: Started systemd-tmpfiles-clean.timer > ..... ..... # [-k] : show logs of kernel message [root@dlp ~]# journalctl -k Jan 04 10:20:34 localhost kernel: Linux version 6.12.0-35.el10.x86_64 (mockbuil> Jan 04 10:20:34 localhost kernel: Command line: BOOT_IMAGE=(hd0,gpt2)/vmlinuz-6> Jan 04 10:20:34 localhost kernel: BIOS-provided physical RAM map: ..... ..... # [-p Priority] : show logs of a specific priority [root@dlp ~]# journalctl -p err Jan 04 10:20:38 dlp.srv.world kernel: Warning: Unmaintained driver is detected:> ..... ..... # [-g PATTERN] : show logs that include specific word [PATTERN] in [MESSAGE] field [root@dlp ~]# journalctl -g "sealert" Jan 04 10:55:11 dlp.srv.world setroubleshoot[1998]: SELinux is preventing /usr/> ..... ..... # [-S DATE] : show logs Since DATE # [-U DATE] : show logs Until DATE [root@dlp ~]# journalctl -S "2025-01-01 00:00:00" -U "2025-01-04 23:59:59" Jan 04 10:20:34 localhost kernel: Linux version 6.12.0-35.el10.x86_64 (mockbuil> Jan 04 10:20:34 localhost kernel: Command line: BOOT_IMAGE=(hd0,gpt2)/vmlinuz-6> Jan 04 10:20:34 localhost kernel: BIOS-provided physical RAM map: ..... ..... # show help [root@dlp ~]# journalctl --help journalctl [OPTIONS...] [MATCHES...] Query the journal. Options: --system Show the system journal --user Show the user journal for the current user ..... ..... |
|