Registros y diarioctl
systemd-journald es el servicio de registro del sistema en Ubuntu 26.04. Recopila y gestiona todos los registros del kernel, los servicios y las aplicaciones. journalctl es la herramienta de línea de comandos para consultar y analizar estos registros.
Conceptos básicos de Journalctl
Ver registros
# View all logs
journalctl
# View the latest logs (tail)
journalctl -e
# Follow new logs in real time (similar to tail -f)
journalctl -f
# View the most recent N entries
journalctl -n 50
# Output without paging
journalctl --no-pager
# Reverse order (newest first)
journalctl -rFormatos de salida
# Short format (default)
journalctl -o short
# Verbose format (shows all fields)
journalctl -o verbose
# JSON format
journalctl -o json
# JSON format (one entry per line, convenient for scripting)
journalctl -o json-lines
# Message content only
journalctl -o catFiltrado de registros
Filtrar por Servicio
# View logs for a specific service
journalctl -u nginx.service
# View logs for multiple services
journalctl -u nginx.service -u php-fpm.service
# Follow a specific service's logs in real time
journalctl -u myapp.service -fFiltrar por tiempo
# View logs from the current boot
journalctl -b
# View logs from the previous boot
journalctl -b -1
# List all boot records
journalctl --list-boots
# Specify a time range
journalctl --since "2026-03-24 10:00:00"
journalctl --since "2026-03-24 10:00:00" --until "2026-03-24 12:00:00"
# Use relative time
journalctl --since "1 hour ago"
journalctl --since "30 min ago"
journalctl --since today
journalctl --since yesterday --until todayFiltrar por prioridad
Los niveles de prioridad de registro varían de 0 (el más grave) a 7 (el más detallado):
| Nivel | Nombre | Descripción |
|---|---|---|
| 0 | emerger | El sistema es inutilizable |
| 1 | alerta | Se requiere acción inmediata |
| 2 | crítico | error crítico |
| 3 | errar | error |
| 4 | advertencia | Advertencia |
| 5 | aviso | Normal pero significativo |
| 6 | información | Informativo |
| 7 | depurar | Depurar |
# Show only errors and above
journalctl -p err
# Show only warnings
journalctl -p warning
# Show a range of priorities
journalctl -p warning..errFiltrar por otros criterios
# By process PID
journalctl _PID=1234
# By user ID
journalctl _UID=1000
# By executable path
journalctl _EXE=/usr/bin/python3
# Combine conditions
journalctl _SYSTEMD_UNIT=nginx.service -p err --since today
# Kernel logs
journalctl -k
journalctl --dmesgBúsqueda de contenido de registro
# Filter with grep
journalctl -u nginx.service | grep "error"
# Use journalctl's built-in matching
journalctl -g "failed|error|timeout"Configuración de almacenamiento de registros
Archivo de configuración
El archivo de configuración diario se encuentra en /etc/systemd/journald.conf:
sudo nano /etc/systemd/journald.confOpciones de configuración comunes:
[Journal]
# Log storage mode: persistent (to disk), volatile (memory only), auto (default)
Storage=persistent
# Maximum disk space for logs
SystemMaxUse=500M
# Maximum size of a single log file
SystemMaxFileSize=50M
# Maximum retention time
MaxRetentionSec=1month
# Maximum memory usage for logs
RuntimeMaxUse=100M
# Log compression
Compress=yes
# Forward to syslog
ForwardToSyslog=yes
# Rate limiting: max 10000 entries per service per 30 seconds
RateLimitIntervalSec=30s
RateLimitBurst=10000Aplicar cambios de configuración:
sudo systemctl restart systemd-journaldGarantizar la persistencia del registro
De forma predeterminada, si el directorio /var/log/journal/ no existe, los registros solo se guardan en la memoria. Para habilitar la persistencia:
# Create the persistent log directory
sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
# Or set it in the configuration file
# Storage=persistent
# Restart the service
sudo systemctl restart systemd-journaldRotación y limpieza de registros
Limpieza manual
# Clean by time: keep only the last 7 days of logs
sudo journalctl --vacuum-time=7d
# Clean by size: keep only 500MB of logs
sudo journalctl --vacuum-size=500M
# Clean by file count: keep only the 5 most recent log files
sudo journalctl --vacuum-files=5
# View current disk usage by logs
journalctl --disk-usageVerificar la integridad del registro
# Check log file consistency
journalctl --verifyRelación con syslog
systemd-journald puede funcionar junto con syslog tradicional (como rsyslog):
# Check if rsyslog is installed
dpkg -l rsyslog
# rsyslog log files are located under /var/log/
ls /var/log/syslog
ls /var/log/auth.log
ls /var/log/kern.logArchivos de registro tradicionales
| Archivo | Descripción |
|---|---|
/var/log/syslog | Registro general del sistema |
/var/log/auth.log | Registro de autenticación |
/var/log/kern.log | Registro del núcleo |
/var/log/dpkg.log | Registro de instalación del paquete |
/var/log/apt/history.log | Historial de operaciones de APT |
/var/log/boot.log | Registro de arranque |
Configurando rsyslog
# Main configuration file
sudo nano /etc/rsyslog.conf
# Custom rules go in this directory
ls /etc/rsyslog.d/Ejemplo de regla rsyslog (escriba los registros de nginx en un archivo separado):
# /etc/rsyslog.d/nginx.conf
if $programname == 'nginx' then /var/log/nginx/syslog.log
& stoprotación de registros logrotate
logrotate gestiona la rotación de archivos de registro tradicionales:
# Main configuration file
cat /etc/logrotate.conf
# Application configurations directory
ls /etc/logrotate.d/Ejemplo de configuración personalizada de logrotate:
sudo nano /etc/logrotate.d/myapp/var/log/myapp/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 myapp myapp
sharedscripts
postrotate
systemctl reload myapp.service > /dev/null 2>&1 || true
endscript
}# Test logrotate manually
sudo logrotate -d /etc/logrotate.d/myapp # dry-run
sudo logrotate -f /etc/logrotate.d/myapp # force executionConsejos prácticos
Monitorear fallas de inicio del servicio
# Create a script to monitor failed services
journalctl -p err -u "*.service" --since "5 min ago" --no-pager -o catExportar registros
# Export as a text file
journalctl -u nginx.service --since today > /tmp/nginx-today.log
# Export in binary format (readable by journalctl)
journalctl -u nginx.service -o export > /tmp/nginx.exportVer registros relacionados con E/S de disco
journalctl -k | grep -i "i/o\|error\|disk\|sda"Análisis del proceso de arranque
# View logs from the boot process
journalctl -b --no-pager | head -100