Home How ToCentralize Server Logs with Rsyslog on Ubuntu

Centralize Server Logs with Rsyslog on Ubuntu

by Knowledge Base Linux
Centralize Server Logs with Rsyslog on — Centralize Server Logs with Rsyslog on Ubuntu

When you manage more than a couple of Linux servers, SSH-ing into each machine to read logs stops being a strategy and becomes a liability. Important events get missed, incident timelines are impossible to reconstruct, and a compromised server’s local logs cannot be trusted anyway. Rsyslog — the default syslog daemon on Ubuntu — solves this by forwarding log messages from every machine to a single central log server over the network. This guide shows you how to centralize server logs with rsyslog on Ubuntu 24.04: a complete, step-by-step build of a central log server plus client configuration, optional TLS encryption, and log rotation, so every server in your fleet reports to one searchable location.

Prerequisites – Centralize Server Logs with Rsyslog on

  • Two (or more) Ubuntu 24.04 servers: one will be the central log server, the others are clients.
  • Root or sudo access on all machines.
  • Network connectivity between clients and the server on TCP/UDP port 514 (or TCP 6514 if you use TLS).
  • Hostnames or IPs: in this guide the log server is 192.168.1.10 — replace it with your own.

Step 1: Install Rsyslog on Server and Clients – Centralize Server Logs with Rsyslog on

Rsyslog ships pre-installed on Ubuntu 24.04, but verify it is present and up to date on every machine:

sudo apt update
sudo apt install -y rsyslog
sudo systemctl enable --now rsyslog
rsyslogd -v

The rsyslogd -v output confirms the running version and available modules. You need the same major version on server and clients to avoid configuration incompatibilities.

Step 2: Configure the Central Rsyslog Server

On the log server, enable the TCP and UDP reception modules and define where incoming logs are stored. Create /etc/rsyslog.d/10-server.conf:

sudo nano /etc/rsyslog.d/10-server.conf
# Load TCP and UDP listener modules
module(load="imtcp")
module(load="imudp")

# Listen on the standard syslog port
input(type="imtcp" port="514")
input(type="imudp" port="514")

# Store logs per host and per program for easy browsing
template(name="RemoteLogPath" type="string"
         string="/var/log/remote/%HOSTNAME%/%PROGRAMNAME%.log")

# Apply the template to everything received over the network
if ($fromhost-ip != '127.0.0.1') then {
    action(type="omfile" dynaFile="RemoteLogPath")
    & stop
}

This rsyslog configuration writes each client’s logs under /var/log/remote/<hostname>/, split by program name. The & stop prevents remote messages from also landing in the server’s own local log files. Create the directory and set ownership:

sudo mkdir -p /var/log/remote
sudo chown syslog:adm /var/log/remote
sudo chmod 755 /var/log/remote

Rsyslog log aggregation hub collecting logs from Linux servers

Step 3: Open the Firewall on the Log Server

Allow syslog traffic through UFW (or your firewall of choice):

sudo ufw allow 514/tcp
sudo ufw allow 514/udp
sudo ufw status numbered

If your servers sit in different networks, restrict the rule to your client subnet instead of opening it to the world — for example sudo ufw allow from 192.168.1.0/24 to any port 514 proto tcp.

Step 4: Configure Rsyslog Clients to Forward Logs

On each client, create /etc/rsyslog.d/10-forward.conf that sends everything to the central server:

sudo nano /etc/rsyslog.d/10-forward.conf
# Forward all logs to the central rsyslog server over TCP
# @@ = TCP, @ = UDP
*.* action(type="omfwd"
           target="192.168.1.10"
           port="514"
           protocol="tcp"
           action.resumeRetryCount="-1"
           queue.type="LinkedList"
           queue.filename="fwdq"
           queue.saveOnShutdown="on")

The queue settings matter: queue.type="LinkedList" with queue.saveOnShutdown="on" gives you a disk-assisted queue, so log messages are buffered to disk if the central server is temporarily unreachable instead of being lost. action.resumeRetryCount="-1" means retry forever. TCP is preferred over UDP here because it guarantees delivery and preserves message order.

Step 5: Restart Rsyslog and Verify Log Flow

Restart rsyslog on the server first, then on the clients:

sudo systemctl restart rsyslog
sudo systemctl status rsyslog --no-pager

Generate a test message on a client and check that it arrives on the server:

# On the client:
logger -t kblinux-test "rsyslog forwarding test from $(hostname)"

# On the server (a few seconds later):
ls /var/log/remote/
cat /var/log/remote/CLIENT-HOSTNAME/kblinux-test.log

You can also watch traffic on the wire to confirm messages are flowing:

sudo tcpdump -i any -n port 514 -A -c 5

If nothing arrives, check sudo journalctl -u rsyslog -f on both ends — rsyslog logs its own errors there.

Step 6 (Optional but Recommended): Encrypt Rsyslog Traffic with TLS

Plaintext syslog exposes potentially sensitive log data on the network. Rsyslog supports TLS via the gtls network stream driver. First install it everywhere:

sudo apt install -y rsyslog-gnutls

Generate a CA and certificates (do this once, on the log server):

sudo mkdir -p /etc/rsyslog.d/tls && cd /etc/rsyslog.d/tls
sudo certtool --generate-privkey --outfile ca-key.pem
sudo certtool --generate-self-signed --load-privkey ca-key.pem \
  --outfile ca.pem --template <<'EOF'
cn = "rsyslog CA"
ca
cert_signing_key
EOF
sudo certtool --generate-privkey --outfile server-key.pem
sudo certtool --generate-certificate --load-privkey server-key.pem \
  --load-ca-certificate ca.pem --load-ca-privkey ca-key.pem \
  --outfile server-cert.pem --template <<'EOF'
cn = "192.168.1.10"
tls_www_server
encryption_key
signing_key
EOF

Then switch the server to TLS. Replace the imtcp input in /etc/rsyslog.d/10-server.conf with:

module(load="imtcp"
       StreamDriver.Name="gtls"
       StreamDriver.Mode="1"
       StreamDriver.AuthMode="anon")
input(type="imtcp" port="6514")

And add the global TLS settings at the top of the file:

global(
  DefaultNetstreamDriverCAFile="/etc/rsyslog.d/tls/ca.pem"
  DefaultNetstreamDriverCertFile="/etc/rsyslog.d/tls/server-cert.pem"
  DefaultNetstreamDriverKeyFile="/etc/rsyslog.d/tls/server-key.pem"
)

On each client, copy ca.pem over securely, then change the forwarding action to use TLS:

*.* action(type="omfwd"
           target="192.168.1.10"
           port="6514"
           protocol="tcp"
           StreamDriver="gtls"
           StreamDriverMode="1"
           StreamDriverAuthMode="x509/name"
           StreamDriverPermittedPeers="192.168.1.10")

Open port 6514 on the server firewall, restart rsyslog on both sides, and repeat the logger test from Step 5. For the full parameter reference, see the official rsyslog documentation.

Step 7: Rotate the Centralized Logs

A central server accumulates logs fast. Without rotation you will fill the disk — set up log rotation with logrotate on Linux for the remote log tree by creating /etc/logrotate.d/rsyslog-remote:

/var/log/remote/*/*.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate 2> /dev/null || true
    endscript
}

Test the configuration with a dry run before trusting it:

sudo logrotate -d /etc/logrotate.d/rsyslog-remote 2>&1 | head -30

If you later want dashboards and full-text search over these logs, consider layering a modern stack on top — see our guide to centralized logging with Loki and Promtail for the next step up.

Troubleshooting Common Rsyslog Problems

Logs never arrive at the server

Work through the chain in order: is rsyslog running on both ends (systemctl status rsyslog)? Is the server listening (ss -tlnp | grep 514)? Does the firewall allow the port? Can the client reach the server (nc -zv 192.168.1.10 514)? Nine times out of ten it is the firewall.

“Permission denied” writing to /var/log/remote

The directory must be owned by the syslog user. Re-run the chown syslog:adm command from Step 2, and check for AppArmor denials in dmesg.

TLS handshake failures

Certificate name mismatches are the usual cause: the server certificate’s CN must match the StreamDriverPermittedPeers value on the client, and both sides must trust the same CA file. Check journalctl -u rsyslog for gtls error details.

Messages arrive out of order or duplicated

UDP forwarding does not guarantee order — switch the client action to TCP (@@ / protocol="tcp") as shown in Step 4. Duplicates usually mean the message matched both the forwarding rule and a local file rule; add & stop or & ~ after the forwarding action on clients that should not keep local copies.

Disk fills up on the log server

Verify logrotate is actually running (systemctl status logrotate.timer) and that the postrotate script path matches your rsyslog version — on some releases it lives at /usr/lib/rsyslog/rsyslog-rotate, on others under /usr/sbin.

Conclusion

Centralizing logs with rsyslog turns a scattered fleet into a single, trustworthy source of truth. With the server, client forwarding, disk-assisted queues, TLS encryption, and log rotation from this guide, you have a robust rsyslog setup that survives network blips, protects sensitive log data in transit, and will not fill your disk overnight. Start with the two-machine setup, verify the flow with logger, then roll the client configuration out to the rest of your servers with Ansible or your configuration management tool of choice — every new machine becomes one config file away from full visibility.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.