Logs rotation

From ISPWiki
Jump to: navigation, search

General information

By default for logs rotation ISPmanager 5 uses the logrotate utility.

You need to activate rotation for each web-domain in its edit form. Click "Show hidden fields" for flexible configuration of logs rotation.

Rotate1.png

logrotate is started every day in /etc/cron.daily/logrotate . The configuration file is located in

/etc/logrotate.conf 

Logs rotation settings for each web-domain are located in

/etc/logrotate.d/web/domain.com

By default the following logs settings are active (contents of /etc/logrotate.d/web/domain.com)

#The first line is a template of log-files. 
/var/www/httpd-logs/domain.com.access.log {
        olddir /var/www/user/data/logs #Locate archived files into specified directory
        copytruncate #Create a copy of the original log-file and then reset it. Thus the file won't be deleted. 
        compress #Archive files (gzip is used by default)
        monthly #Rotate once a day/week/month
        prerotate #Similar to postrotate, but the operations will be performed before archiving
                /etc/webanalyzer.d/user/domain.com #Analyze logs
        endscript
}
/var/www/httpd-logs/domain.com.error.log {
        olddir /var/www/user/data/logs
        copytruncate
        compress
        monthly
}


Start rotation manually

/usr/sbin/logrotate -d -f <path_to_config_of_required_web_domain>

-d - detailed information -f - rotate in any case (for example, even if logs were rotated totay) Example: if you need to rotate logs only for domain.com , the command will look like /usr/sbin/logrotate -f /etc/logrotate.d/web/domain.com

Possible problems

  • log does not need rotating

Cause - logs have already been rotated. You can modify status in the file

/var/lib/logrotate/status

Or delete this file, but you will have to start rotation for all logs again

/usr/sbin/logrotate -f /etc/logrotate.conf

Logs on control panels v5 are rotated by the built-in mechanism once their size reaches 100 MB

Logs analyzer

ISPmanager 5 supports:

  • awstats
  • webalizer

To install a log analyzer, go to ISPmanager --- Settings--- Software.

You need to activate analyzer for each web-domain in its edit form. Click "Show hidden fields" for flexible configuration of logs rotation.

Rotate2.png

Example: Awstats

Once logs analyzer for the web domain domain.com is activated, the configuration file with rules will be created. Normally it is located in

/etc/awstats/awstats.domain.com.conf

The followings are specified in the file

LogFile="/var/www/httpd-logs/dasha.com.access.log" #location of log for analysis
SiteDomain="dasha.com" #site for analysis
DirData="/var/www/user/data/www/dasha.com/webstat/" #location of statistics after analysis
and others. 

You can view statistics per web-domain in ISPmanager --- Web domains--- select a required domain --- click "Statistics".

Execute the following command for collecting statistics manually

/etc/webanalyzer.d/user/domain.name

or

/usr/bin/perl /usr/lib/cgi-bin/awstats.pl -update -config=domain.com

When statistics collection starts

  • If the period is set to "during rotation", the analyzer will start by logrotate.

The directive prerotate that starts the log analyzer will be added into the configuration file /etc/logrotate.d/web/<domain.name>


/var/www/httpd-logs/domain.name.access.log { 	
olddir /var/www/username/data/logs 	
daily 	
copytruncate 	
compress 	
rotate 10 	
prerotate 		
        /etc/webanalyzer.d/username/domain.name 	
endscript 
}
/var/www/httpd-logs/domain.name.error.log { 	
olddir /var/www/username/data/logs 	
daily 	
copytruncate 	
compress 	
rotate 10
}
  • If the period is set to "every hour", the statistics collection script will be added into user cron
# crontab -u username -l
MAILTO=""#
#ISPmanager log rotate domain.name
0 * * * *	/etc/webanalyzer.d/username/domain.name

Possible problems with statistics collection

  • Statistics shows only one unique visitor.

This may happen in case Nginx + Apache are installed. Solution - install mod_rpaf for Apache.

  • Statistics shows zero

Make sure that the following line in the awstats configuration file for the domain (/etc/awstats/awstats.domain.com.conf) is specified

LogFormat=1

You also make sure log format is combined in the Apache configuration file

CustomLog /var/www/httpd-logs/domain.access.log combined
  • How to exclude my IP address from statistics?

Edit the configuration file /etc/awstats/awstats.domain.com.conf .

SkipHosts="123.123.123.123"


See also: the official documentation Awstats