Notes
Time on servers
First, time. Servers should run in UTC. Ours did: zero thirty UTC, which was six in the morning India time. Logs from machines in different regions then line up without conversion, and there are no daylight saving jumps. Convert to local time only when you show it to people. Remember episode seventeen, where a two thirty schedule fired at nine in the evening UTC: time zones cause real bugs.
$ date -u Wed Dec 2 00:30:01 UTC 2026 $ TZ=Asia/Kolkata date Wed Dec 2 06:00:01 IST 2026 /etc/timezone: Etc/UTC servers: UTC; show local time only to humans
NTP
Clocks drift, so servers sync them with NTP, the network time protocol. On modern Ubuntu and Red Hat, chrony does it. chronyc tracking shows how far off the clock is, and timedatectl shows whether it is synchronised. In the cloud, use the provider's own time service, which on AWS is a link-local address every instance can reach. Our sandbox does not run a time daemon, so try these in your lab VM.
$ chronyc tracking how far off, and drifting how $ chronyc sources -v which servers, which is used $ timedatectl look for: synchronized: yes cloud: use the provider's time source (AWS 169.254. 169.123)
Why it matters
Why does a few minutes matter? TLS checks certificate dates, so a wrong clock makes valid certificates look expired. Signed requests and tokens include times, and AWS rejects request signatures that are more than a few minutes off. Logs from different machines appear in the wrong order during an incident. Distributed systems that use leases and timeouts misbehave. And scheduled jobs fire at the wrong moment.
- TLS: certificate "not yet valid" or "expired"
- tokens: JWT, AWS signatures rejected (AWS allows ~5 min)
- logs: events out of order
- distributed systems: leases, locks, ordering
- cron and timers fire at the wrong time
Log rotation
Next, logs. Without rotation they grow until the disk fills, as in episode eleven. logrotate renames the current log, compresses old copies, keeps a fixed number and deletes the rest. Our config: rotate daily, keep seven, compress, ignore a missing log, skip an empty one, and copy-truncate. We forced a rotation: a five hundred and eighty nine thousand byte log became an empty app dot log and a compressed copy of two hundred and fifteen thousand bytes, about a third of the size.
/tmp/lr/app.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
}
before: app.log 588,895 bytes
after: app.log 0, app.log.1.gz
215,157 bytes copytruncate vs reopen
There is a trap here, from episode four. If logrotate just renames a log, the app keeps writing to its open file, now renamed, and space is never freed. Two fixes. Copytruncate copies the log and then empties the original, so the app keeps writing to the same file; a few lines can be lost in the gap. Or rename and then signal the app to reopen its logs, in a postrotate script: nginx uses USR one, many daemons use SIGHUP.
- copytruncate: copy, then empty the original; the app keeps writing; tiny gap may lose a few lines
- create + postrotate: rename, then tell the app to reopen (nginx: kill -USR1; many daemons: SIGHUP)
- rename only → the app writes to the old, renamed file
journald and apps
The journal needs limits too: set a maximum size and retention in journald's config, or vacuum it by hand. In containers the rule changes: apps log to standard output, and the container runtime captures and rotates it, but only if you set a maximum size, which Docker does not by default. Either way, the long-term copy belongs in a central log system, which part eleven builds.
/etc/systemd/journald.conf SystemMaxUse=1G MaxRetentionSec=14day $ journalctl --vacuum-size=500M containers: log to stdout; the runtime rotates (docker json-file max-size) ship logs off the box (part 11)
sysctl
Finally, sysctl, which reads and writes the kernel settings under slash proc slash sys. Our machine had eight hundred and eight of them. somaxconn, four thousand and ninety six, caps the queue of connections waiting to be accepted. swappiness was sixty. The whole system could open about eight hundred and nineteen thousand files. And outgoing connections use local ports from thirty two thousand seven hundred and sixty eight to sixty thousand nine hundred and ninety nine, about twenty eight thousand ports.
$ sysctl -a | wc -l 808 $ sysctl net.core.somaxconn 4096 listen queue limit vm.swappiness = 60 fs.file-max = 818942 net.ipv4.ip_local_port_range = 32768 60999
Tune with evidence
Change settings only for a measured reason, in a file under sysctl dot d so it survives reboots, then apply with sysctl system. Typical examples: a bigger listen queue for a busy proxy, a wider port range for a server making many outgoing connections, or lower swappiness. Note that per-process limits, like open files per process, are separate: ulimit in a shell, LimitNOFILE in a systemd unit. Too many open files is usually that limit, not the kernel's.
# /etc/sysctl.d/90-shop.conf net.core.somaxconn = 8192 net.ipv4.ip_local_port_range = 10240 65535 vm.swappiness = 10 $ sudo sysctl --system apply per-process limits are separate: ulimit -n, LimitNOFILE=
Common mistakes
Mistakes. Servers set to local time zones. No time sync, or a firewall blocking it. Logs with no rotation. Rotating by rename without telling the app, so space is never freed. Pasting long tuning lists from blogs without measuring. And changing settings with sysctl minus w only, so they vanish at the next reboot.
- servers in local time zones
- no NTP, or a blocked NTP port
- logs with no rotation
- rename-only rotation (space never freed)
- copying sysctl "tuning" lists from blogs
- sysctl -w only: lost on reboot
Say it like this
In the interview: first I free space safely, truncating or rotating rather than deleting open files. Then I add rotation: daily, keep seven, compress, with copytruncate or a postrotate reload so the app reopens its log. I cap journald, set a max size for container logs, ship logs to a central system, and alert on disk usage and its growth rate. I would also check the clock is synced, because rotation and incidents depend on time.
- "I free space safely first, then add logrotate: daily, rotate 7, compress, and copytruncate or a postrotate reload so the app
- reopens the file. I cap journald, set max-size for container logs, ship logs centrally and alert
- on disk usage and growth."