CentOS Stream 8
Sponsored Link

Journald : Basic Usage
2021/06/30
 
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.socket - Journal Socket
   Loaded: loaded (/usr/lib/systemd/system/systemd-journald.socket; static; ven>
   Active: active (running) since Wed 2021-06-29 21:38:57 JST; 4min 57s ago
     Docs: man:systemd-journald.service(8)
           man:journald.conf(5)
   Listen: /run/systemd/journal/stdout (Stream)
           /run/systemd/journal/socket (Datagram)
    Tasks: 0 (limit: 23673)
   Memory: 0B
   CGroup: /system.slice/systemd-journald.socket
[2] It's possible to change settings of Journald on [/etc/systemd/journald.conf].
All options are commented out by default, however they are the default parameters of Journald on CentOS Stream 8.
[root@dlp ~]#
cat /etc/systemd/journald.conf

#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
[3] The place of stored logging data is set on [Storage=***] of [/etc/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 8, 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 /etc/systemd/journald.conf

#Storage=auto
[root@dlp ~]#
ll -d /var/log/journal

ls: cannot access '/var/log/journal': No such file or directory
[root@dlp ~]#
ll /run/log/journal

total 0
drwxr-s---+ 2 root systemd-journal 60 Jul  1 20:41 54f4bd7df8464337a3009215fdef55fb

# [/run/log] on CentOS Stream 8 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
[root@dlp ~]#
df -h /run/log

Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.9G  8.5M  1.9G   1% /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-journald-dev-log.socket
[root@dlp ~]#
ll /run/log/journal

ls: cannot access '/run/log/journal': No such file or directory
[root@dlp ~]#
ll /var/log/journal

total 0
drwxr-xr-x. 2 root root 28 Jul  1 23:42 54f4bd7df8464337a3009215fdef55fb

# * Note
# on default settings of CentOS Stream 8, 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

[root@dlp ~]#
journalctl

-- Logs begin at Thu 2021-07-01 23:57:55 JST, end at Thu 2021-07-02 14:30:31 JS>
Jul 01 23:57:55 localhost.localdomain kernel: Linux version 4.18.0-310.el8.x86_>
Jul 01 23:57:55 localhost.localdomain kernel: Command line: BOOT_IMAGE=(hd0,msd>
Jul 01 23:57:55 localhost.localdomain kernel: x86/fpu: Supporting XSAVE feature>
.....
.....

# [-u UNIT] : show logs of a specific UNIT

[root@dlp ~]#
journalctl -u sshd.service

-- Logs begin at Thu 2021-07-01 23:57:55 JST, end at Thu 2021-07-02 15:01:01 JS>
Jul 01 23:58:01 dlp.srv.world systemd[1]: Starting OpenSSH server daemon...
Jul 01 23:58:01 dlp.srv.world sshd[897]: Server listening on 0.0.0.0 port 22.
Jul 01 23:58:01 dlp.srv.world sshd[897]: Server listening on :: port 22.
.....
.....

[root@dlp ~]#
journalctl -u systemd-tmpfiles-clean.timer

-- Logs begin at Thu 2021-07-01 23:57:55 JST, end at Thu 2021-07-02 15:01:01 JS>
Jul 01 23:58:00 dlp.srv.world systemd[1]: Started Daily Cleanup of Temporary Di>
.....
.....

# [-k] : show logs of kernel message

[root@dlp ~]#
journalctl -k

-- Logs begin at Thu 2021-07-01 23:57:55 JST, end at Thu 2021-07-02 14:30:31 JS>
Jul 01 23:57:55 localhost.localdomain kernel: Linux version 4.18.0-310.el8.x86_>
Jul 01 23:57:55 localhost.localdomain kernel: Command line: BOOT_IMAGE=(hd0,msd>
Jul 01 23:57:55 localhost.localdomain kernel: x86/fpu: Supporting XSAVE feature>
.....
.....

# [-p Priority] : show logs of a specific priority

[root@dlp ~]#
journalctl -p err

-- Logs begin at Thu 2021-07-01 23:57:55 JST, end at Thu 2021-07-02 16:02:09 JS>
Jul 01 23:57:55 localhost.localdomain systemd-vconsole-setup[288]: /usr/bin/set>
Jul 01 23:57:56 localhost.localdomain kernel: pcieport 0000:00:01.6: Failed to >
Jul 01 23:57:58 localhost.localdomain systemd-vconsole-setup[656]: /usr/bin/set>
.....
.....

# [-g PATTERN] : show logs that include specific word [PATTERN] in [MESSAGE] field

[root@dlp ~]#
journalctl -g "sealert"

-- Logs begin at Thu 2021-07-01 23:57:55 JST, end at Thu 2021-07-02 17:01:01 JST. --
Jul 01 23:58:33 dlp.srv.world setroubleshoot[1473]: SELinux is preventing /usr/bin/login from getattr access on the filesystem /sys/fs/cgroup. For complete SELinux messages run: sealert -l 99d9d41e-aa3f-4856-9d81-6ca26aa6405c
.....
.....

# [-S DATE] : show logs Since DATE

# [-U DATE] : show logs Until DATE

[root@dlp ~]#
journalctl -S "2021-06-30 00:00:00" -U "2021-07-01 23:59:59"

-- Logs begin at Fri 2021-06-25 23:37:03 JST, end at Thu 2021-07-01 17:12:47 JST. --
Jun 30 00:00:16 dlp.srv.world systemd[1]: Starting update of the root trust anchor for DNSSEC validation in unbound...
Jun 30 00:00:17 dlp.srv.world systemd[1]: unbound-anchor.service: Succeeded.
Jun 30 00:00:17 dlp.srv.world systemd[1]: Started update of the root trust anchor for DNSSEC validation in unbound.
.....
.....

# show help

[root@dlp ~]#
journalctl --help --no-pager

journalctl [OPTIONS...] [MATCHES...]

Query the journal.

Options:
     --system                Show the system journal
     --user                  Show the user journal for the current user
.....
.....
Matched Content