Enabling log file compression in RHEL

Had to save disk space on some of my web servers.

Red Hat Enterprise Linux uses logrotate to cycle old log files. By default, compression is not turned on but certain rotate configurations such as the one for Apache (/etc/logrotate.d/httpd) do contain either the compress or delaycompress directive.

To enable compression globally you have to was uncomment line 15 of the stock /etc/logrotate.conf configuration file. Note that you do not have to enable compression globally to use compression for individual components: just make sure that the “compress” directive exists in the rotate configuration for the particular component you want it enabled for.

Making compression happen where a rotate configurations contain only the “delaycompress” directive, like the stock httpd config, does require that you add a compress directive as well. Like this:

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    compress
    delaycompress
    postrotate
        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
    endscript
}

Test logrotate (overriding criteria) with this command:

logrotate -d --force /etc/logrotate.conf >/tmp/logrotate.txt 2>&1

The logrotate.txt file will contain the console messages echoed by the script in “debug” (-d) mode.

Keep in mind that logrotate will not actually do any compressing of files until it runs on its normal schedule.

This entry was posted in System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).