User Tools

Site Tools


control-panels:cpanel-whm:how-can-i-change-or-configure-log-rotation-on-my-cpanel-server

How can I change or configure log rotation on my cPanel server?

This article will cover log rotation on cPanel servers using logrotate. ( logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large. )

For this article, all access is being performed via SSH Terminal and nano plain text editor.

/etc/logrotate.conf

The default configuration for /etc/logrotate.conf shoud look similar to this:

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
 monthly
 create 0664 root utmp
 minsize 1M
 rotate 1
}

/var/log/btmp {
 missingok
 monthly
 create 0600 root utmp
 rotate 1
}

# system-specific logs may be also be configured here.

An important setting to make note of is: include /etc/logrotate.d This is letting us know, that all files inside that folder are seperate programs settings/configurations. For example, inside /etc/logrotate.d we have the following configuration files:

  • exim
  • mysql
  • named
  • syslog
  • yum

Let's take a look at the yum configuration file:

/var/log/yum.log {
 missingok
 notifempty
 yearly
 create 0600 root root
}

We can use this as an example to create new log rotation config files.

Creating a logrotate configuration

A log file that is not rotated by default, but commonly requested to be rotated is the chkservd log. Located at /var/log/chkservd.log So, let's make a configuration to rotate this log.

  1. Create a new file inside of /etc/logrotate.d/ named as the program for the logs. For this example it will be: /etc/logrotate.d/chkservd
    • touch /etc/logrotate.d/chkservd
  2. Let's take a look at the actual log file with stat.
    • stat /var/log/chkservd.log
      • File: `/var/log/chkservd.log'
         Size: 13952399 Blocks: 27264 IO Block: 4096 regular file
        Device: 98h/152d Inode: 88236606 Links: 1
        Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
        Access: 2014-09-12 19:01:50.908900649 -0400
        Modify: 2014-12-02 11:07:09.766631054 -0500
        Change: 2014-12-02 11:07:09.766631054 -0500
  3. So this tells us the permissions on the file are -rw——- or 600. The owner is root. The group is root. Great, let's use that for the configuration file.
  4. Here's the example configuration file used for chkservd:
    • /var/log/chkservd.log { 
       missingok
       notifempty
       weekly 
       create 0600 root root
  5. Make sure you save the added configuration file and logrotate should see it automatically.
control-panels/cpanel-whm/how-can-i-change-or-configure-log-rotation-on-my-cpanel-server.txt · Last modified: 2015/01/12 21:26 by dlevey