Skip to content
masdzub.com
~/articles/rsyslog — one from the notebook

Centralized Logging on Debian with Rsyslog and a Remote Log Server

Configure rsyslog on Debian to forward logs to a remote server over TCP and TLS, with disk queues, rotation, and fixes for the errors that stop delivery.

masdzub@website:~$ cat ~/articles/set-up-centralized-logging-with-rsyslog-and-remote-log-server-on-debian.aspx.md
# 1 file · 14 min read · topic: rsyslog · status: published

Introduction

Centralized logging with rsyslog on Debian comes down to three pieces: a receiver listening on TCP 514, a forwarding action in a drop-in file on each client, and a template on the receiver that writes one directory per sending host. Everything else in this setup exists to stop messages from disappearing when the network drops, the disk fills, or the certificate expires.

The directives themselves are short. The failures are not. A client that quietly suspends its forwarding action for six hours looks identical to a client that is working until you check the server. Rate limiting inside journald silently discards bursts before rsyslog ever sees them. A hostname-based log path lets any machine on the network write into another machine’s directory. This article builds the pipeline end to end on Debian 12 with rsyslog 8.2302, then spends most of its length on the parts that break in production.

If you only need to keep logs on one machine, skip the forwarding and use journald. Rsyslog earns its place here because it can filter on facility and severity, write plain text files you can grep without a query language, and queue messages to disk when the receiver is unreachable. Those three properties matter more than throughput at most scales.

How rsyslog moves a message from sender to disk

Rsyslog reads configuration from /etc/rsyslog.conf and every *.conf file in /etc/rsyslog.d/, in lexical order. A file named 10-remote.conf loads before the distro’s 50-default.conf, and 60-remote.conf loads after it. That ordering decides which selector matches first, so pick names deliberately instead of copying whatever number a blog post used.

Each message enters through an input module. On a normal Debian box, imuxsock reads /dev/log, which on systemd systems is a symlink to /run/systemd/journal/dev-log, and imklog reads the kernel ring buffer. Network input comes from imtcp or imudp. The input parses the raw line into properties: facility, severity, hostname, app-name, procid, the message body, and the receive timestamp. Templates then expand those properties into a filename or a forwarding format.

Rulesets control which configuration block sees a message. When you bind an input to a named ruleset with ruleset="remoteLogs", messages from that input never touch the main ruleset at all. That is why a receiver can write remote traffic to /var/log/remote/ and still write its own local messages to /var/log/syslog without any filtering tricks.

Validate before restarting, every time:

Terminal window
rsyslogd -N1

The output prints the version line, then either parses cleanly or names the file and line that failed. A receiver with a broken config starts, fails, and restarts in a loop under systemd, and you lose messages for as long as that loop runs.

Building the receiver on Debian 12

Install rsyslog on the server if the minimal image left it out, then write one drop-in file. Keep the distro config untouched so package upgrades do not conflict with your edits.

Terminal window
apt install rsyslog
systemctl enable --now rsyslog
/etc/rsyslog.d/10-remote.conf
module(load="imtcp"
MaxSessions="500"
KeepAlive="on"
ratelimit.interval="0"
ratelimit.burst="0")
template(name="perHostDay" type="string"
string="/var/log/remote/%fromhost-ip%/%$YEAR%-%$MONTH%-%$DAY%.log")
ruleset(name="remoteLogs") {
action(type="omfile"
dynaFile="perHostDay"
createDirs="on"
dirCreateMode="0750"
fileCreateMode="0640"
fileOwner="root"
fileGroup="adm")
}
input(type="imtcp" port="514" ruleset="remoteLogs")

The ruleset must appear before the input that references it, otherwise rsyslog reports an unknown ruleset at parse time. ratelimit.interval="0" turns off per-source throttling. Older 8.x builds defaulted to 200 messages per 5 seconds per sender, which is enough to lose a burst of authentication failures during a brute-force attempt, exactly the traffic you wanted to keep.

%fromhost-ip% rather than %hostname% in the path is deliberate. The hostname field is whatever the client claims, so a compromised or misconfigured machine can write into another host’s directory. The IP can also be spoofed on a flat network, but it requires more effort, and the directory layout stays stable when someone renames a server. If you need the hostname for readability, put it in the file content, not the path.

Open the port only on the interface you intend:

input(type="imtcp" Address="10.0.0.5" port="514" ruleset="remoteLogs")

Then reload and confirm the socket is actually listening. ss is more honest than systemctl status, which will report active even when the bind failed if the failure happened after the service forked.

Terminal window
systemctl restart rsyslog
ss -ltnp | grep ':514'
tail -n 20 /var/log/syslog

Forwarding from the client

On each client, add a drop-in that matches everything and sends it to the receiver. *.* matches all facilities and all severities, including authpriv and kern. Narrow it with *.info or exclude noisy facilities with mail.none if the volume is a problem, but start broad and measure before you filter.

/etc/rsyslog.d/60-remote.conf
*.* action(type="omfwd"
target="10.0.0.5" port="514"
protocol="tcp"
TCP_Framing="octet-counted"
KeepAlive="on"
action.resumeRetryCount="-1"
queue.type="LinkedList"
queue.size="50000"
queue.filename="fwdq"
queue.maxDiskSpace="1g"
queue.saveOnShutdown="on"
queue.highWaterMark="40000"
queue.lowWaterMark="20000")

TCP_Framing="octet-counted" tells the receiver how long each message is instead of relying on newlines, which matters when a message body contains one. Both sides need to agree. If the receiver runs an old 8.x build that defaults to LF framing, either upgrade it or drop this parameter on the client; mismatched framing shows up as one long mangled line on the server containing several timestamps.

The client keeps writing local files as well, because 50-default.conf still matches everything after your drop-in runs. That duplication costs disk on the client but gives you local logs when the network is down, which is usually the right trade. Add & stop after the forwarding action if you want the message to skip the local selectors entirely.

Test from a host that is not the receiver:

Terminal window
logger -n 10.0.0.5 -P 514 -T -t smoketest "hello from $(hostname)"

-T forces TCP, -n sets the destination, -P the port. On the server, ls /var/log/remote/ should now show a directory named after the client’s IP, and grep smoketest /var/log/remote/*/*.log should find the line.

Keeping messages when the network drops

The queue settings above are the difference between a logging system and a logging demo. Without queue.filename, the queue lives in memory, and a five-minute network blip after 50,000 buffered messages means the client starts dropping new ones. With a filename, rsyslog spills the queue to /var/spool/rsyslog/ and picks up where it left off.

action.resumeRetryCount="-1" means never give up on a suspended action. The default is 0, so after a few failed connects rsyslog discards the message and moves on. If you set a finite number instead, the message is discarded after that many retries and you get one line in the local log about it.

queue.maxDiskSpace caps the spool, and queue.discardMark (not set above, because the disk cap is a better ceiling for most sites) drops the oldest messages once the queue passes a threshold. Pick one limit. A spool with no cap will eventually fill /var/spool during a long outage and take down other services on the box.

The spool directory has to exist and be writable by the rsyslog user before the first start. Debian creates it with the package, but if you purge and reinstall, check:

Terminal window
ls -ld /var/spool/rsyslog

You will find .qi files there while the queue holds data. A stale .qi file from a previous config version can cause startup warnings about an existing queue; delete the spool files only when the queue is empty and the service is stopped, or you lose whatever was buffered.

Encrypting the transport with GnuTLS

Plain syslog TCP sends every message in the clear, including the ones that contain credentials in a URL or a failed login with the username attached. On a single rack behind a switch you control, that may be acceptable. Across anything else, use TLS, or wrap the traffic in WireGuard and keep rsyslog plain.

The receiver needs a certificate, a key, and a CA. Rsyslog wants PEM files; a DER certificate fails to load with a message about the certificate file. Generate the set with OpenSSL:

Terminal window
mkdir -p /etc/rsyslog/tls && cd /etc/rsyslog/tls
openssl req -x509 -newkey rsa:4096 -nodes -days 3650 \
-keyout ca-key.pem -out ca.pem -subj "/CN=rsyslog-ca"
openssl req -newkey rsa:4096 -nodes \
-keyout server-key.pem -out server.csr -subj "/CN=log1.example.com"
openssl x509 -req -in server.csr -CA ca.pem -CAkey ca-key.pem \
-CAcreateserial -days 3650 -out server-cert.pem
chmod 600 ca-key.pem server-key.pem
chown root:root ca-key.pem server-key.pem

The CN on the server certificate must match the name or IP the client uses in StreamDriverPermittedPeers, or the handshake fails with a name mismatch. Put the CA and client credentials on each sender, then change both sides.

# /etc/rsyslog.d/10-remote.conf, receiver
global(DefaultNetstreamDriver="gtls"
DefaultNetstreamDriverCAFile="/etc/rsyslog/tls/ca.pem"
DefaultNetstreamDriverCertFile="/etc/rsyslog/tls/server-cert.pem"
DefaultNetstreamDriverKeyFile="/etc/rsyslog/tls/server-key.pem")
module(load="imtcp"
StreamDriver.Name="gtls"
StreamDriver.Mode="1"
StreamDriver.Authmode="x509/name"
StreamDriver.PermitExpiredCerts="off")
input(type="imtcp" port="6514" ruleset="remoteLogs")
# /etc/rsyslog.d/60-remote.conf, sender
global(DefaultNetstreamDriver="gtls"
DefaultNetstreamDriverCAFile="/etc/rsyslog/tls/ca.pem")
*.* action(type="omfwd"
target="log1.example.com" port="6514"
protocol="tcp"
StreamDriver="gtls"
StreamDriverMode="1"
StreamDriverAuthMode="x509/name"
StreamDriverPermittedPeers="log1.example.com"
action.resumeRetryCount="-1"
queue.type="LinkedList"
queue.filename="fwdq"
queue.saveOnShutdown="on")

StreamDriver.Mode="1" means TLS is required, not optional. Mode 0 would fall back to plaintext on a failed handshake, which defeats the point and produces logs you think are encrypted. Port 6514 is convention only; pick whatever your firewall allows, but update the nftables or iptables rule, because 514 stays open otherwise and every misconfigured client keeps arriving unencrypted.

TLS adds CPU per connection, not per message, so with persistent connections the cost stays low. The real operational cost is that a certificate problem looks exactly like a network problem in the client log, and both surface as a suspended action. Watch for the suspension line in /var/log/syslog on the clients; it fires within seconds of a handshake failure.

Rotation and retention on the receiver

Log files with a date in the name never need to be rotated by size, only deleted. The trade-off is file count: 200 hosts times 365 days is 73,000 files, and grep -r across that many inodes is slow. A single file per host is fine for small fleets and much easier to search, at the cost of one large file that logrotate has to handle.

Whichever you pick, tell logrotate to close the file handles. Rsyslog keeps files open, so a rename under a running daemon writes to the wrong inode until the daemon reopens them. On Debian, invoke-rc.d rsyslog rotate sends SIGUSR1, and rsyslog closes every open file in response.

/etc/logrotate.d/remote-logs
/var/log/remote/*/*.log {
daily
rotate 30
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}

Dry run before trusting it:

Terminal window
logrotate -d /etc/logrotate.d/remote-logs

Size the partition from measurement, not from a guess. After a week, du -sh /var/log/remote and du -sh /var/log/remote/* tell you the daily rate per host. Multiply by the retention you actually promised in your incident policy, add 30 percent, and put /var/log on its own volume or set a quota. A receiver that fills its root filesystem takes down the machine you were relying on to explain why something else broke.

Errors you will hit and what causes them

Every one of these has a real cause, and none of them means “restart and hope”.

error during parsing file ... on or before line N: syntax error

The drop-in mixes legacy and modern syntax, or a parameter belongs to a different module. $ActionQueueType LinkedList next to action(type="omfwd" ...) is the usual culprit, along with a ) in the wrong place. Rsyslog accepts both styles but not in the same expression, and the line number it reports is often the line after the actual mistake. Run rsyslogd -N1 and read the whole output, not the last line.

action 'action-0-builtin:omfwd' suspended, next retry is ... [try http://www.rsyslog.com/e/2007]

The sender cannot establish a TCP connection. On the receiver, check ss -ltnp | grep 514. On the path between them, check the firewall rule with nft list ruleset. Confirm that the sender resolves the target name the way you expect with getent hosts log1.example.com, because a search domain in /etc/resolv.conf turns a short name into a host that does not exist. While suspended, the queue grows; look at /var/spool/rsyslog to see whether messages are still arriving.

Nothing arrives but the sender reports no errors

Journald is dropping messages before rsyslog sees them. Look for a journal line like Suppressed 2412 messages from ... and check /etc/systemd/journald.conf. The defaults (RateLimitIntervalSec=30s, RateLimitBurst=10000) discard bursts from a single service, and a web server in a restart loop hits that ceiling quickly. Set RateLimitIntervalSec=0 on hosts where you care about every line, then systemctl restart systemd-journald. The same behavior exists for kern messages arriving through an overwhelmed ring buffer, which no configuration can recover.

Duplicate lines on the receiver

The sender forwards twice, or the receiver matches the same message in two selectors. Two forwarding actions in different drop-ins is common after someone renamed 50-remote.conf to 60-remote.conf instead of replacing it. On the receiver, remember that an input bound to a ruleset bypasses the main ruleset entirely; duplicates there usually mean two inputs are bound to the same port, or a client is also sending to a second collector.

Handshake failures under TLS

A gnutls_handshake() failure with no further detail is almost always a name mismatch, an expired certificate, or clock skew on a sender whose date drifted far enough that the certificate is not yet valid. Check the CN on the server cert against StreamDriverPermittedPeers, confirm with openssl x509 -in server-cert.pem -noout -text, and run timedatectl on the sender. Also confirm the private key permissions: root-owned 600 is right for a daemon that starts as root, but if you have dropped privileges to syslog, that user must be able to read the key or the module fails to initialize.

Hardening the receiver

Bind the listener to an internal address and firewall the port to the client subnets. Syslog TCP has no authentication of its own, so anyone who can reach 514 writes whatever they want into your log store. With %fromhost-ip% paths they cannot corrupt another host’s directory, but they can fill your disk, which is worse than noise.

Terminal window
nft add table inet filter
nft add chain inet filter input '{ type filter hook input priority 0; policy drop; }'
nft add rule inet filter input ct state established,related accept
nft add rule inet filter input iif lo accept
nft add rule inet filter input ip saddr 10.0.0.0/24 tcp dport 514 accept
nft add rule inet filter input ip saddr 10.0.0.0/24 tcp dport 6514 accept

Keep $EscapeControlCharactersOnReceive at its default, which is on. It rewrites control characters in incoming messages to # codes, so a malicious log line cannot send terminal escape sequences to whoever runs cat on the file later. Turning it off for prettier output is a mistake people make once.

Do not expose 514 to the internet under any configuration, including with TLS. Use WireGuard between sites and keep the syslog port on the private interface. If you need to cross an untrusted network and cannot run a tunnel, TLS with pinned peers is the minimum, and even then the receiver has no way to rate-limit a determined sender beyond MaxSessions and the kernel’s connection limits.

Knowing when this setup stops being enough

Rsyslog writing plain files works well up to tens of gigabytes of daily volume and a handful of queries a day. Past that, grep -r over a month of logs takes minutes, and the usual answer is rg from ripgrep for speed or lnav for time-ordered navigation across many files. Neither changes the storage model; they only make reading less painful.

If you need guaranteed delivery across a flaky WAN, look at RELP (omrelp and imrelp) instead of plain TCP. It adds application-level acknowledgment so the sender only drops a message from its queue after the receiver confirms the write. If you need full-text search across years of logs, ship from rsyslog into Loki, OpenSearch, or Graylog with omhttp or omelasticsearch and keep the file output as a short-term local copy for the first 48 hours.

For fleets where rsyslog on every host is too much to maintain, systemd-journal-remote gives you the same architecture with journald’s binary format and built-in verification, at the cost of a format you cannot read with grep. The choice depends on whether your incident workflow starts with a shell or with a browser.

Run rsyslogd -N1 on both ends after every edit, then send one test message with logger and confirm it lands in the right directory. A config that parses is not a config that delivers, and the gap between those two states is where most of the debugging time goes.

found this useful? share it →
Written by

Dzubayyan Ahmad

System Administrator, SRE & Technical Support Engineer specialising in web hosting infrastructure — Linux servers, automation, and monitoring. Writing these notes since 2015 so future-me can find the fix again.