Sub topic 9
Forwarding Logs from Client Servers
This chapter assumes that you can edit files with sudo, use systemctl, understand TCP ports and firewalls, and know that rsyslog evaluates messages against configuration rules. You should also know the difference between the systemd journal and traditional syslog messages.
A client server is a machine that produces logs and sends them to another machine. The receiving machine is the central log server. Forwarding gives you one place to search logs and preserves evidence when a client is damaged or replaced.
The client forwarding path
On many Linux systems, applications write to the journal, to the syslog socket, or directly to files. rsyslog can receive messages from the system and forward matching messages to a remote host.
The basic path is:
TCP is usually preferable to UDP for forwarding. TCP establishes a connection and detects a broken connection. UDP is simpler, but messages can be lost without the sender knowing.
Add a forwarding rule
Create a file such as /etc/rsyslog.d/50-forward.conf on every client:
# /etc/rsyslog.d/50-forward.conf
action(type="omfwd"
target="loghost.example.com" port="514" protocol="tcp"
queue.type="LinkedList"
queue.filename="fwd_queue"
queue.maxDiskSpace="1g"
queue.saveOnShutdown="on"
action.resumeRetryCount="-1")This action forwards messages to loghost.example.com on TCP port 514. The hostname must resolve correctly from the client, either through DNS or a suitable /etc/hosts entry.
The queue controls what happens when the central server is unavailable.
| Setting | Effect |
|---|---|
| `queue.type="LinkedList"` | Holds messages in a memory-backed queue |
| `queue.filename="fwd_queue"` | Gives the disk queue a persistent filename |
| `queue.maxDiskSpace="1g"` | Limits queued data to 1 GB |
| `queue.saveOnShutdown="on"` | Saves queued messages during a clean shutdown |
| `action.resumeRetryCount="-1"` | Retries indefinitely |
A queue reduces loss during a short outage, but it does not provide unlimited storage. When the queue reaches its limit, new messages may be discarded or blocked according to the queue and action behavior. Monitor available disk space and queue growth.
This example uses unencrypted TCP. Protect the connection with TLS when logs cross an untrusted network. TLS configuration belongs on both the client and receiver, and both sides must trust the configured certificate authority.
Validate and activate the rule
Check the configuration before restarting the service:
sudo rsyslogd -N1
sudo systemctl restart rsyslog
sudo systemctl status rsyslog --no-pagerrsyslogd -N1 parses the configuration without starting a second logging daemon. Fix every reported error before restarting. After activation, check that the hostname resolves and that an outbound firewall permits TCP port 514.
Send a test message
Use logger to create a syslog message with a recognizable tag:
logger -t forwarding-test "client forwarding test from $(hostname)"The receiver should eventually contain a message with the forwarding-test program name. If the receiver is offline, watch the client's queue and disk usage, then bring the receiver back and confirm that queued messages drain.
Exercise
Why should a client use a disk-assisted queue when forwarding logs over TCP?
Show answer
The queue stores messages while the receiver or network is unavailable, allowing rsyslog to retry later instead of immediately losing those messages.