CentOS Logrotate Example
While this article discusses log rotation in CentOS, you will want to also read my other article on tricking out the OS to allow instant rotation of files. You will find it here in Linux – Forcing Log Rotation – Get Past the Frustration.
Rotating Logs in Linux – Should be on by Default
Because there is a script file in /etc/cron.daily for logrotate already, it is scheduled and ready to go, we just need to specify which files we want to have it rotate for us. While this example was done in CentOS, Linux Log Rotation is similar in most versions of Linux.
Additionally, the /etc/logrotate.conf file which configures the whole log rotation thing specifies this inclusion:
include /etc/logrotate.d
Add New Files for Logrotate to Rotate
All we have to do is add a file in the /etc/logrotate.d directory. In my case, I name it /etc/logrotate.d/uptimemadeeasy because it relates to my specific files for my applications. While I used cat to create the file, you can use whatever editor you like when you create your file:
cat > /etc/logrotate.d/uptimemadeeasy <<EOF /data/uptimemadeeasy/application1/logs/*.log { daily # <– Run this daily rotate 7 # <– Number of times a file is rotated before it is deleted. Here, we keep a week’s worth. dateext # <– Add a date timestamp to the rotated files. compress # <– Compress the rotated files. missingok # <– If the file is missing, go to the next without error msgs. Opposite is “nomissingok” copytruncate # <– Truncate the original file after creating a copy instead of moving the old file. create 0664 deploy deploy # <– Set the permissions and ownership after rotation } EOF |
This will make it begin to consider the files in the specified directory for logrotation.
You can now manually run logrotation. I like using the verbose option when running it manually so I can see what it is doing:
logrotate -v /etc/logrotate.conf |
This will cause the logrotation to run manually. I normally find that I have to wait a day for a new log rotation configuration to be run.
Latest posts by Jeff Staten (see all)
- Configure Your HP Procurve Switch with SNTP - May 5, 2015
- Configuring HP Procurve 2920 Switches - May 1, 2015
- Troubleshooting Sendmail - November 28, 2014