Este contenido no está disponible en el idioma seleccionado.
Chapter 2. Troubleshooting problems by using log files
Use log files to troubleshoot and monitor the system. Log files contain messages about the system, kernel, services, and applications, recorded efficiently using the built-in syslog protocol.
2.1. Services that handle syslog messages Copiar enlaceEnlace copiado en el portapapeles!
Identify the system services, such as rsyslogd and journald, that handle syslog messages. These services are crucial for capturing, processing, and storing all security-relevant system events.
The following services handle syslog messages:
- The
systemd-journalddaemon Collects messages from the following sources and forwards them to Rsyslog for further processing:
- Kernel
- Early stages of the boot process
- Standard and error output of daemons as they start and run
- Syslog
- The
rsyslogservice -
Sorts syslog messages by type and priority and writes them to the files in the
/var/logdirectory. The/var/logdirectory persistently stores the log messages.
2.2. Subdirectories that store syslog messages Copiar enlaceEnlace copiado en el portapapeles!
Locate where system logging services store recorded syslog messages. Most log files are kept in the /var/log/ directory, often organized logically into subdirectories based on the application.
The following subdirectories under the /var/log directory store syslog messages:
- /var/log/messages
- all syslog messages except the following
- /var/log/secure
- security and authentication-related messages and errors
- /var/log/maillog
- mail server-related messages and errors
- /var/log/cron
- log files related to periodically executed tasks
- /var/log/boot.log
- log files related to system startup
2.3. Commands for viewing logs Copiar enlaceEnlace copiado en el portapapeles!
You can view and manage log files by using the Journal, which is a component of systemd. It addresses problems connected with traditional logging, is closely integrated with the rest of the system, and supports various logging technologies and access management for the log files.
You can use the journalctl command to view messages in the system journal, for example:
journalctl -b | grep kvm May 15 11:31:41 localhost.localdomain kernel: kvm-clock: Using msrs 4b564d01 and 4b564d00 May 15 11:31:41 localhost.localdomain kernel: kvm-clock: cpu 0, msr 76401001, primary cpu clock
$ journalctl -b | grep kvm
May 15 11:31:41 localhost.localdomain kernel: kvm-clock: Using msrs 4b564d01 and 4b564d00
May 15 11:31:41 localhost.localdomain kernel: kvm-clock: cpu 0, msr 76401001, primary cpu clock
2.3.1. Viewing system information Copiar enlaceEnlace copiado en el portapapeles!
journalctl- Shows all collected journal entries.
journalctl FILEPATH-
Shows logs related to a specific file. For example, the
journalctl /dev/sdacommand displays logs related to the/dev/sdafile system. journalctl -b- Shows logs for the current boot.
journalctl -k -b -1- Shows kernel logs for the current boot.
2.3.2. Viewing information about specific services Copiar enlaceEnlace copiado en el portapapeles!
journalctl -b _SYSTEMD_UNIT=<name.service>-
Filters log to show entries matching the
systemdservice. journalctl -b _SYSTEMD_UNIT=<name.service> _PID=<number>-
Combines matches. For example, this command shows logs for
systemd-unitsthat match<name.service>and the PID<number>. journalctl -b _SYSTEMD_UNIT=<name.service> _PID=<number> + _SYSTEMD_UNIT=<name2.service>-
The plus sign (+) separator combines two expressions in a logical OR. For example, this command shows all messages from the
<name.service>service process with thePIDplus all messages from the<name2.service>service (from any of its processes). journalctl -b _SYSTEMD_UNIT=<name.service> _SYSTEMD_UNIT=<name2.service>-
This command shows all entries matching either expression, referring to the same field. Here, this command shows logs matching a systemd-unit
<name.service>or a systemd-unit<name2.service>.