Configure Linux system logging with rsyslog and journald for centralized log management

Intermediate 25 min Apr 03, 2026 64 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Set up comprehensive Linux logging infrastructure using rsyslog for traditional syslog handling and journald for systemd service logs. Configure remote logging, log rotation, filtering rules, and troubleshoot common logging performance issues.

Prerequisites

  • Root or sudo access
  • Basic understanding of Linux system administration
  • Network connectivity for remote logging setup

What this solves

Modern Linux systems use both rsyslog and journald for logging, which can create confusion and fragmented log management. This tutorial shows you how to configure both systems to work together effectively, set up centralized logging for multiple servers, implement proper log retention policies, and optimize logging performance for production environments.

Understanding Linux logging architecture

Linux logging involves two primary systems that serve different purposes. The journald service, part of systemd, captures all system and service logs in binary format with structured metadata. The rsyslog daemon handles traditional syslog messages in text format and provides powerful filtering, formatting, and forwarding capabilities.

By default, journald forwards messages to rsyslog, which then writes them to files in /var/log. This dual approach gives you the benefits of structured logging from journald and the flexibility of traditional syslog processing from rsyslog. Understanding this relationship is crucial for effective log management.

Step-by-step configuration

Update system packages

Start by updating your package manager and installing the required logging components.

sudo apt update && sudo apt upgrade -y
sudo apt install -y rsyslog rsyslog-relp logrotate
sudo dnf update -y
sudo dnf install -y rsyslog rsyslog-relp logrotate

Configure journald persistent storage

By default, journald stores logs in memory only. Configure persistent storage to retain logs across reboots.

[Journal]
Storage=persistent
Compress=yes
Seal=yes
SplitMode=uid
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=10000
SystemMaxUse=4G
SystemKeepFree=1G
SystemMaxFileSize=128M
SystemMaxFiles=100
MaxRetentionSec=2month
MaxFileSec=1month
ForwardToSyslog=yes
ForwardToKMsg=no
ForwardToConsole=no
ForwardToWall=yes

Create journald storage directory

Create the persistent storage directory with correct permissions for journald.

sudo mkdir -p /var/log/journal
sudo chown root:systemd-journal /var/log/journal
sudo chmod 2755 /var/log/journal

Configure rsyslog main configuration

Set up the main rsyslog configuration with modern features and security settings.

# Global configuration
$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog   # provides kernel logging support
$ModLoad imjournal # provides access to the systemd journal
$ModLoad immark  # provides --MARK-- message capability

High precision timestamps

$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat $template HighPrecision,"%timegenerated:::date-rfc3339% %HOSTNAME% %syslogtag%%msg%\n" $ActionFileDefaultTemplate HighPrecision

Work directory

$WorkDirectory /var/spool/rsyslog

Include all config files in /etc/rsyslog.d/

$IncludeConfig /etc/rsyslog.d/*.conf

Turn off message reception via local log socket

$OmitLocalLogging on

File syncing capability is disabled by default

$ActionFileEnableSync on

Set the default permissions for all log files

$FileOwner syslog $FileGroup adm $FileCreateMode 0640 $DirCreateMode 0755 $Umask 0022 $PrivDropToUser syslog $PrivDropToGroup syslog

Standard log files

.;auth,authpriv.none -/var/log/syslog auth,authpriv.* /var/log/auth.log .;auth,authpriv.none -/var/log/syslog cron.* /var/log/cron.log daemon.* -/var/log/daemon.log kern.* -/var/log/kern.log lpr.* -/var/log/lpr.log mail.* -/var/log/mail.log user.* -/var/log/user.log

Configure remote logging client

Set up rsyslog to send logs to a central log server using reliable RELP protocol.

# Load RELP output module
$ModLoad omrelp

Configure remote logging with RELP

Replace log-server.example.com with your log server

$template RemoteHost,"/var/log/remote/%HOSTNAME%/%PROGRAMNAME%.log"

Send all logs to remote server

. :omrelp:log-server.example.com:2514

Also log locally (comment out if you only want remote logging)

& ~

Configure remote logging server

Set up a server to receive logs from multiple clients using RELP for reliability.

# Load RELP input module
$ModLoad imrelp

RELP listener

$InputRELPServerRun 2514 $InputRELPServerBindRuleset remote

Template for remote log files

$template RemoteLogs,"/var/log/remote/%HOSTNAME%/%PROGRAMNAME%.log"

Ruleset for remote logs

$RuleSet remote $template RemoteFormat,"%timegenerated:::date-rfc3339% %HOSTNAME% %syslogtag%%msg%\n" . ?RemoteLogs;RemoteFormat & stop

Use default ruleset for local logs

$RuleSet RSYSLOG_DefaultRuleset

Create log filtering rules

Configure advanced filtering to separate logs by priority, facility, and custom criteria.

# High priority alerts to separate file
.err;.crit;.alert;.emerg     /var/log/error.log

Application-specific filtering

:programname, isequal, "nginx" /var/log/nginx/access.log & stop :programname, isequal, "postfix" /var/log/mail.log & stop

Filter by message content

:msg, contains, "Failed password" /var/log/failed-logins.log :msg, contains, "authentication failure" /var/log/failed-logins.log

Rate limiting for noisy applications

:programname, isequal, "kernel" and $msg contains "audit" { action(type="omfile" file="/var/log/audit.log" action.execonlyonceeveryinterval="60") stop }

Discard debug messages from specific applications

:programname, isequal, "systemd" and :syslogseverity, isequal, "7" stop

Configure log rotation policies

Set up logrotate with custom policies for different log types and retention requirements.

/var/log/syslog
/var/log/mail.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/daemon.log
/var/log/cron.log
/var/log/lpr.log
{
    daily
    rotate 30
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

/var/log/error.log
{
    daily
    rotate 90
    missingok
    notifempty
    compress
    delaycompress
    create 0640 syslog adm
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

/var/log/remote//.log
{
    daily
    rotate 7
    missingok
    notifempty
    compress
    delaycompress
    create 0640 syslog adm
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

Create custom journald retention policy

Configure journald cleanup service for automated log maintenance.

[Unit]
Description=Clean up old journal files

[Service]
Type=oneshot
ExecStart=/usr/bin/journalctl --vacuum-time=30d
ExecStart=/usr/bin/journalctl --vacuum-size=2G

Create journald cleanup timer

Set up automated cleanup to run weekly and keep journals within size limits.

[Unit]
Description=Weekly journal cleanup
Requires=journald-cleanup.service

[Timer]
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target

Configure firewall for remote logging

Open the required port for RELP remote logging server.

sudo ufw allow 2514/tcp comment "RELP logging"
sudo ufw reload
sudo firewall-cmd --add-port=2514/tcp --permanent
sudo firewall-cmd --reload

Enable and restart services

Apply all configurations by restarting the logging services and enabling the cleanup timer.

sudo systemctl restart systemd-journald
sudo systemctl restart rsyslog
sudo systemctl enable --now journald-cleanup.timer
sudo systemctl status rsyslog
sudo systemctl status systemd-journald

Verify your setup

Test the logging configuration to ensure both journald and rsyslog are working correctly.

# Check journald status and recent logs
sudo journalctl --verify
journalctl -n 20 --no-pager

Test rsyslog configuration

sudo rsyslogd -N1

Check log file permissions

ls -la /var/log/syslog /var/log/auth.log

Test log generation

logger -p user.notice "Test message from logger command" tail -f /var/log/syslog

Check remote logging (if configured)

sudo ss -tlnp | grep :2514

Verify log rotation configuration

sudo logrotate -d /etc/logrotate.d/rsyslog-custom

Performance optimization

For high-volume logging environments, optimize both journald and rsyslog performance. Configure journald to use appropriate rate limiting and rsyslog to handle high throughput efficiently.

Monitor disk I/O and memory usage during peak logging periods. Consider using asynchronous file writes in rsyslog and adjusting journal file sizes based on your log volume. System performance tuning can help optimize overall logging performance.

Note: High-frequency logging can impact system performance. Use rate limiting and filtering to reduce unnecessary log volume while maintaining essential information.

Integration with monitoring systems

Connect your centralized logging to monitoring and alerting systems for comprehensive observability. Export logs to time-series databases or integrate with log analysis platforms for advanced searching and alerting capabilities.

Consider implementing structured logging formats like JSON for better parsing and analysis. This integration works well with Prometheus and Grafana monitoring or Loki log aggregation systems.

Common issues

SymptomCauseFix
Logs not appearing in filesrsyslog configuration errorRun sudo rsyslogd -N1 to check config syntax
Journal files growing too largeIncorrect SystemMaxUse settingAdjust SystemMaxUse and run sudo journalctl --vacuum-size=2G
Remote logging not workingFirewall blocking RELP portCheck firewall rules and network connectivity on port 2514
Permission denied errorsIncorrect log directory permissionsRun sudo chown syslog:adm /var/log/filename and chmod 640
High disk I/O from loggingExcessive log volume or sync issuesEnable async writes with $ActionFileEnableSync off and implement filtering
Journal corruption after crashUnclean shutdownRun sudo journalctl --verify and --rotate to fix corruption
Logrotate not workingMissing postrotate scriptEnsure /usr/lib/rsyslog/rsyslog-rotate exists and is executable
Missing logs from containersDocker logging driver misconfigurationConfigure Docker to use journald driver or forward to rsyslog

Next steps

Automated install script

Run this to automate the entire setup

#rsyslog #journald #centralized logging #log management #systemd

Need help?

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.

Talk to an engineer