20140414 enabling log file compression in rhel - plembo/onemoretech GitHub Wiki

title: Enabling log file compression in RHEL link: https://onemoretech.wordpress.com/2014/04/14/enabling-log-file-compression-in-rhel/ author: phil2nc description: post_id: 7385 created: 2014/04/14 15:33:07 created_gmt: 2014/04/14 19:33:07 comment_status: closed post_name: enabling-log-file-compression-in-rhel status: publish post_type: post

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.

Copyright 2004-2019 Phil Lembo