Home Linux Basics Managing Linux Log files with Logrotate

Managing Linux Log files with Logrotate

by SupportPRO Admin

Log files are very important and valuable tool available in Linux system security. Logrotate is a log file manager program which provides the administrator with an up-to-date record of events taking place on the system. It may also be used to backup log files. It regularly rotates log files by removing old one from the system and creating new log files as the log files grow too large. This rotation is based on the age of the file, file size and can also set cron utility. It can also be used to compress log files and to configure emails to user when they are rotated. The point of log file rotation is to prevent log files from growing indefinitely.

How to configure logrotate?

/etc/logrotate.conf is the default configuration file for logrotate. The options added to this configuration file can be used to set configuration parameters to any log files in the system. For each package that happens to produce a log file, there is an additional configuration file under / etc/logrotate.d/.

Options

compress :This is used to compress the rotated log file with gzip.

nocompress: This is used when you do not want to compress rotated log files.

copytruncate : This option copies the active log (process are still writing information to open log file) file to a backup and truncates the active log file.

nocopytruncate: This copies the log files to backup, but the open log file is not truncated.

create mode owner group : This rotates the log file and creates a new log file with the specified permissions, owner, and group; by default it uses the same mode, owner, and group as the original file.

nocreate: This prevents the creation of a new log file.

delaycompress : When used with the compress option, the rotated log file is not compressed until the next time it is cycled.

nodelaycompress: This overrides delay compress. The log file is compressed when it is cycled.

errors address: This mails logrotate errors to an address.

ifempty: With this, the log file is rotated even if it is empty. This is the default for logrotate.

notifempty : This does not rotate the log file if it is empty.

mail address : This option mails log files that are cycled to an address. When mail log files are rotated, they are effectively removed from the system.

daily: This is used to rotate log files daily.

weekly:This is used to rotate log files weekly.

monthly : This is used to rotate log files monthly.

rotate count : This specifies the number of times to rotate a file before it is deleted.

size size : The log file is rotated when the specified size is reached.

Running logrotate

Basically, there are three steps to run logrotation.

1. Identify the log files in the system.

2. Create rotation schedules and parameters for the log files.

3. Run logrotate through the cron daemon.

For example :

The default cronjob to allow logrotate to run daily:

/usr/sbin/logrotate /etc/logrotate.conf

The above cron job allows logrotate to run daily with the parameters specified in /etc/logrotate.conf.

If you require help, contact SupportPRO Server Admin

Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value

Leave a Comment