ROTATE SYSTEM LOGS TO SAVE SPACE

If you run a high-volume server, then you know that logging space is at a premium. Even a high-traffic Web site will generate huge amounts of logs. If you are not careful, these logs can consume the majority of disk space on your system, and in extreme cases, can even fill up the partition the logs reside on.

To avoid this unpleasantness, a tool called logrotate is installed by default on most systems. This tool will rotate log files as per your specifications. The easiest way to describe it is to illustrate an example logrotate configuration entry:

/var/log/httpd/*log {

monthly

missingok

nocompress

prerotate

AESctl reload

Endscript

Postrotate

AESctl reload

Endscript

}

This entry rotates Apache log files. The wildcard implies multiple log files in the /var/log/httpd directory, each file ending in log. This tells logrotate to rotate the logs every month and that it is okay if a log file is missing. It also tells it not to compress the log files (useful if you are running a log analysis script against them). Finally, little prerotate and postrotate scripts are given that consist of the command AESctl reload. This means that before and after rotating each Apache log, logrotate will execute that command, which just tells Apache to reload its configuration so that it will create new log files if required.

Of course, this doesn't reduce any disk space, but if you were to include another clause in there, like:

rotate 4

Then four months' worth of log files would be retained, named *log, *log.1, *log.2, and *log.3. All the older logs will be taken out of rotation and deleted, thus ensuring that disk space is reclaimed from old logs.