Monday, May 25, 2015

Logrotate uses 100% CPU issue on CentOS

A typical /var/lib/logrotate.status looks like:

logrotate state -- version 2
"/var/log/daemon.log" 2015-5-9
"/var/log/portage/elog/summary.log" 2015-5-9
"/var/log/mysql/mysql.err" 2015-5-9
"/var/log/mysql/mysql.log" 2015-5-9
"/var/log/mysql/mysqld.err" 2015-5-9
"/var/log/atop/dummy_before" 2015-5-25
"/var/log/atop/dummy_after" 2015-5-25
"/var/log/net-snmpd.log" 2015-5-9
"/var/log/xinetd.log" 2015-5-23
"/var/log/wtmp" 2015-5-9

It is a small file say hundred bytes, but the size may reaches megabytes if there are some config errors.

Following command can be used to check the configuration of logrotate without change anything:

sudo /usr/sbin/logrotate -d /etc/logrotate.conf
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file daemon
reading config info for /var/log/daemon.log
reading config file elog-save-summary
reading config info for /var/log/portage/elog/summary.log
reading config file mysql
...

It may indicate a bad logrotate.status file if the command hangs with a huge logrotate status file,  

To fix the problem, simply delete the logrotate.status. The logrotate will re-create a new one for you.