Analyzing and Storing Logs: Log File Type of Messages Stored
Analyzing and Storing Logs: Log File Type of Messages Stored
The rsyslog service uses the facility and priority of log messages to determine how to handle
them. This is configured by rules in the /etc/rsyslog.conf file and any file in the
/etc/rsyslog.d directory that has a file name extension of .conf. Software packages can easily
add rules by installing an appropriate file in the /etc/rsyslog.d directory.
For example, the following line would record messages sent to the authpriv facility at any
priority to the file /var/log/secure:
authpriv.* /var/log/secure
The logger command can send messages to the rsyslog service. By default, it sends the
message to the user facility with the notice priority (user.notice) unless specified
otherwise with the -p option. It is useful to test any change to the rsyslog service
configuration.
To send a message to the rsyslog service that gets recorded in the /var/log/boot.log log
file, execute the following logger command:
Configure rsyslog on servera to log all messages with the debug priority, or higher, for any
service into the new /var/log/messages-debug log file by adding the rsyslog configuration file
/etc/rsyslog.d/debug.conf.
sudo -i
Create the /etc/rsyslog.d/debug.conf file with the necessary entries to redirect all log
messages having the debug priority to /var/log/messages-debug. You may use the vim
/etc/rsyslog.d/debug.conf command to create the file with the following content.
*.debug /var/log/messages-debug
The wildcard (*) in the facility or priority fields of the configuration line indicates any facility
or priority.
Use the logger command with the -p option to generate a log message with the user
facility and the debug priority.
Use the tail command to view the last ten log messages from the /var/log/messages-
debug file and confirm that you see the Debug Message Test message among the other log
messages.
The systemd-journald service stores logging data in a structured, indexed binary file called the
journal. This data includes extra information about the log event. For example, for syslog events this
includes the facility and the priority of the original message.
In Red Hat Enterprise Linux 8, the /run/log directory stores the system journal by default. The
contents of the /run/log directory get cleared after a reboot.
To retrieve log messages from the journal, use the journalctl command
journalctl
The journalctl command highlights important log messages: messages at notice or warning
priority are in bold text while messages at the error priority or higher are in red text.
journalctl -f command outputs the last 10 lines of the system journal and continues to output new
journal entries as they get written to the journal. To exit the journalctl -f process, use the Ctrl+C key
combination.
journalctl -f
Run the following journalctl command to list journal entries at the err priority or higher:
Run the following journalctl command to list all journal entries from today's records.
Run the following journalctl command to list all journal entries ranging from 2019-02-10
20:30:00 to 2019-02-13 12:00:00.
Use the _PID=1 match with the journalctl command to display only log events originating from the
systemd process running with the process identifier of 1 on servera. To quit journalctl, press q.
Use the _UID=81 match with the journalctl command to display all log events originating
from a system service started with the user identifier of 81 on servera. To quit journalctl
press q.
Display all log events recorded in the past 10 minutes from the current time on servera.
Use the --since option and the _SYSTEMD_UNIT="sshd.service" match with the
journalctl command to display all the log events originating from the sshd service recorded
since 09:00:00 this morning on servera. To quit journalctl press q.
[student@servera ~]$ journalctl --since 9:00:00
_SYSTEMD_UNIT="sshd.service"
By default, the system journals are kept in the /run/log/journal directory, which means
the journals are cleared when the system reboots. You can change the configuration settings
of the systemd-journald service in the /etc/systemd/journald.conf file to make the
journals persist across reboot.
The following journalctl command retrieves the entries limited to the first system boot:
he following journalctl command retrieves the entries limited to the second system boot. The
following argument is meaningful only if the system has been rebooted for more than twice:
The following journalctl command retrieves the entries limited to the current system boot:
The -b option can be accompanied by a negative number indicating how many prior system boots
the output should include
Use the ls command to list the /var/log/journal directory contents. Use sudo to elevate
the student user privileges. Use student as the password if asked.
Since the /var/log/journal directory does not exist, systemd-journald service is not
preserving its journals.
...output omitted...
[Journal]
Storage=persistent
...output omitted...
The timedatectl command shows an overview of the current time-related system settings,
including current time, time zone, and NTP synchronization settings of the system.
timedatectl list-timezones
The timedatectl set-ntp command enables or disables NTP synchronization for automatic time
adjustment.
...output omitted...
server classroom.example.com iburst
...output omitted...
The preceding line in the /etc/chrony.conf configuration file includes the iburst option to
speed up initial time synchronization.
Pretend that the serverb system has been relocated to Jamaica and you must update the time
zone appropriately
1. Use the timedatectl command to view available time zones and determine the
appropriate time zone for Jamaica.
2. [student@serverb ~]$ timedatectl list-timezones | grep Jamaica
America/Jamaica
3. Use the timedatectl command to set the time zone of the serverb system to
America/Jamaica.
4. [student@serverb ~]$ sudo timedatectl set-timezone America/Jamaica
[sudo] password for student: student
5. Use the timedatectl command to verify that the time zone is successfully set to
America/Jamaica.
6. [student@serverb ~]$ timedatectl
7. Local time: Tue 2019-02-19 11:12:46 EST
8. Universal time: Tue 2019-02-19 16:12:46 UTC
9. RTC time: Tue 2019-02-19 16:12:45
10. Time zone: America/Jamaica (EST, -0500)
11. System clock synchronized: yes
12. NTP service: active
RTC in local TZ: no
authpriv.alert /var/log/auth-errors
Restart the rsyslog service so that the changes in the configuration file take effect.
Use the logger command to write a new log message to the /var/log/auth-errors file.
Apply the -p authpriv.alert option to generate a log message relevant to authentication
and security issues.
Use the tail command to confirm that the /var/log/auth-errors file contains the log
entry with the Logging test authpriv.alert message.