Log Files Filling Up Disk on a Linux Server

The /var partition filling up and application services crashing with write errors.

Problem

Disk usage on an application server reached 100%, and services were crashing with 'No space left on device' errors.

Cause

logrotate wasn't configured, and an application's debug log level had accidentally been left enabled in production, generating tens of gigabytes of logs per day.

Solution

Compressed and archived the largest log files, lowered the application's log level to info, and added daily rotation/compression/retention rules under /etc/logrotate.d. Also added a simple cron script that emails an alert once disk usage crosses 80%.

du -sh /var/log/* | sort -rh | head -10

cat >/etc/logrotate.d/myapp <<EOF
/var/log/myapp/*.log {
  daily
  rotate 7
  compress
  missingok
  notifempty
}
EOF

logrotate -f /etc/logrotate.d/myapp

View solution source on GitHub