Linux logrotate: Difference between revisions
(3 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
A log rotation consists in renaming the current log fie, so my.log becomes my.log.1, my.log.1 becomes my.log.2 and so forth, and setting up a new my.log log file. The number of log files to be retained is specified in the configuration. Additional operations like compression may be specified. | A log rotation consists in renaming the current log fie, so my.log becomes my.log.1, my.log.1 becomes my.log.2 and so forth, and setting up a new my.log log file. The number of log files to be retained is specified in the configuration. Additional operations like compression may be specified. | ||
The command is /usr/sbin/logrotate, and the cron configuration file that triggers logrotate to be executed once a day is /etc/cron.daily/logrotate: | |||
<syntaxhighlight lang='bash'> | |||
#!/bin/sh | |||
/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf | |||
EXITVALUE=$? | |||
if [ $EXITVALUE != 0 ]; then | |||
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" | |||
fi | |||
exit 0 | |||
</syntaxhighlight> | |||
The configuration file is [[#Configuration|/etc/logrotate.conf]]. | |||
=Installation= | =Installation= | ||
Line 27: | Line 42: | ||
./etc/rwtab.d/logrotate | ./etc/rwtab.d/logrotate | ||
./var/lib/logrotate | ./var/lib/logrotate | ||
=Configuration= | |||
The configuration file is /etc/logrotate.conf. | |||
/etc/logrotate.conf may include other configuration files from /etc/logrotate.d, by specifying the following: | |||
include /etc/logrotate.d |
Latest revision as of 20:20, 12 February 2018
External
- https://www.networkworld.com/article/3218728/linux/how-log-rotation-works-with-logrotate.html
- https://linux.die.net/man/8/logrotate
Internal
Overview
logrotate is a tool that is run periodically - by default, daily - by cron. Every tine it is executed, logrotate reads its configuration files and manages log files declared in those configuration files, according to the specified rules.
A log rotation consists in renaming the current log fie, so my.log becomes my.log.1, my.log.1 becomes my.log.2 and so forth, and setting up a new my.log log file. The number of log files to be retained is specified in the configuration. Additional operations like compression may be specified.
The command is /usr/sbin/logrotate, and the cron configuration file that triggers logrotate to be executed once a day is /etc/cron.daily/logrotate:
#!/bin/sh
/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
The configuration file is /etc/logrotate.conf.
Installation
yum install -y logrotate
Footprint
./usr/sbin/logrotate ./etc/logrotate.d ./etc/cron.daily/logrotate ./etc/logrotate.conf ./etc/rwtab.d/logrotate ./var/lib/logrotate
Configuration
The configuration file is /etc/logrotate.conf.
/etc/logrotate.conf may include other configuration files from /etc/logrotate.d, by specifying the following:
include /etc/logrotate.d