Sub topic 13
Rotating and Sizing the Central Store
Assume that you can edit files with sudo, use systemctl, and understand TCP ports and /var/log. This chapter assumes an rsyslog receiver already writes remote messages under /var/log/remote.
A central server receives logs from many machines, so its log directory grows faster than a client’s directory. Without a retention policy, the filesystem can fill. A full filesystem can stop logging and may also affect unrelated services.
Plan retention before writing rules
Choose retention from the value of the logs and the available disk space. For example, keeping 30 daily compressed files gives roughly one month of file generations. Compression reduces storage, but it does not make storage unlimited.
Estimate the required space with this rough model:
daily log volume × retention days × compression factor + safety margin
If clients send 2 GB per day, 30 days of retention, and compression reduces logs to 25% of their original size, the compressed archive needs about 15 GB. Add space for current uncompressed files, rotation overlap, filesystem usage, and unexpected increases.
| Decision | Example choice | Effect |
|---|---|---|
| Rotation frequency | `daily` | Limits each file’s size and loss exposure |
| Generations | `rotate 30` | Keeps about 30 rotated files |
| Compression | `compress` | Saves disk space |
| Empty or missing files | `notifempty`, `missingok` | Avoids unnecessary errors |
| Reopen behavior | HUP in `postrotate` | Makes rsyslog use new file descriptors |
Configure central rotation
Create /etc/logrotate.d/remote on the central server:
/var/log/remote/*/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
sharedscripts
postrotate
/usr/bin/systemctl kill -s HUP rsyslog.service
endscript
}The wildcard matches a directory for each host and a log file for each program. daily makes logrotate check these files every day. rotate 30 retains 30 old generations. The exact calendar retention depends on whether files are empty or missing and whether rotation runs successfully.
delaycompress leaves the newest rotated file uncompressed until the next rotation. This can help programs that still have a reference to the recently rotated file. The HUP signal asks rsyslog to close and reopen its files. sharedscripts runs the script once for the whole matched block instead of once per file.
Do not use a broad pattern such as /var/log/remote/**/* without checking the logrotate version and directory layout. A pattern that matches unintended files can rotate local state files or application data.
Keep the store below a hard capacity
rotate 30 controls age indirectly. It does not guarantee that the directory stays below a particular number of gigabytes. High-volume hosts can still consume most of the disk.
Monitor the filesystem and set an alert before it reaches full capacity. If a strict byte limit is required, combine logrotate with a separate capacity policy, such as reducing retention, moving archives to another filesystem, or using a log-management system with quotas. Avoid deleting the newest logs automatically without deciding which evidence must be preserved.
Exercise
Exercise
Why does the central rotation rule send HUP to rsyslog after rotating files?
Show answer
It asks rsyslog to close old file descriptors and reopen the newly named log files, so new messages continue in the active files.