Rotate HAProxy logs hourly
Rational
On production systems HAProxy might be generating a very large amount of logs. It is possible that those logs can become a huge problem unless you rotate them. Daily rotation might be good for low traffic installations, but high trafic ones might generate almost 10gb in a few hours , so you might need to rotate logs every hour. Rotating logs hourly is not configured by default on Ubuntu systems. You need to do a bit just more than you think.
Let’s start
Configure log rotation for haproxy by placing an haproxy
conf file under /etc/logrptate.d/ . All that as long as you have enabled logs for HAProxy in general.
/var/log/haproxy.log {
hourly # Rotate every hour
rotate 0 # keep no logs
missingok
notifempty
postrotate
invoke-rc.d rsyslog rotate >/dev/null 2>&1 || true
endscript
}
Now for the missing part.
By default there is no hourly cronjob for logrotation. So you may configure hourly logrotation, as above, but no logrotation will actually happen. To enable it just copy
the daily logrotate
cronjob file to the hourly directory.
cp /etc/cron.daily/logrotate /etc/cron.hourly/logrotate
Now restart cron and you are good to go.