Log viewer setup

From Smith family

Jump to: navigation, search
Server setup
← Previous Next →
Samba Backup

I use AWStats to keep track of the usage of my web sites and mail server. Setting it up is quite simple

Contents

Installation

  • Install AWStats
root@desktop:~# apt-get install awstats libnet-ip-perl libgeo-ipfree-perl
  • Because I have the cgi-bin directory in a non-standard location, copy the awstats script to that location:
root@desktop:~# cp /usr/lib/cgi-bin/awstats.pl /var/www/cgi.site.domain.tld/

AWStats configuration

Websites

  • Each site you want to generate a log view for needs its own configuration. For the site site.domain.tld. copy the basic config file /etc/awstats/awstats.conf to /etc/awstats/awstats.site.domain.tld.conf. Make the following changes
LogFile="/var/log/apache2/site.domain.tld.access.log"

SiteDomain="site.domain.tld"
HostAliases="localhost 127.0.0.1 site.domain.tld"

LogFormat=1

LoadPlugin="tooltips"
LoadPlugin="geoipfree"
  • Create the statistics databases
root@desktop:~# /var/www/cgi.site.domain.tld/awstats.pl -config=site2.domain.tld -update
Repeat for each site you have
  • Set up a cron job to update the statistics periodically. Add lines to /etc/cron.d/awstats for each site you want stats for:
# 0,10,20,30,40,50 * * * * www-data [ -x /usr/lib/cgi-bin/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache/access.log ] && /usr/lib/cgi-bin/awstats.pl -config=awstats -update >/dev/null

0,10,20,30,40,50 * * * * root [ -x /var/www/cgi-bin.domain.tld/awstats.pl -a -f /etc/awstats/awstats.conf -a -r /var/log/apache/access.log ] && /var/www/cgi-bin.domain.tld/awstats.pl -config=awstats -update >/dev/null
0,10,20,30,40,50 * * * * root [ -x /var/www/cgi-bin.domain.tld/awstats.pl ] && /var/www/cgi-bin.domain.tld/awstats.pl -config=site2.domain.tld -update >/dev/null
Note that the cron jobs need to run as root, not www-data.

Mail servers

This is very similar to the setup for Web log statistics, but the config file is a bit different. This assumes you're using Postfix as the mail server.

  • Create the config file /etc/awstats/awstats.mail.conf with the following changes:
# MAIN SETUP SECTION (Required to make AWStats work)
LogFile="perl /usr/share/doc/awstats/examples/maillogconvert.pl standard < /var/log/mail.log |"
LogType=M 
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd" 
SiteDomain="mail.domain.tld"
HostAliases="localhost 127.0.0.1 mail.domain.tld smtp.domain.tld"

# OPTIONAL ACCURACY SETUP SECTION (Not required but increase AWStats features)
LevelForBrowsersDetection=0 
LevelForOSDetection=0 
LevelForRefererAnalyze=0 
LevelForRobotsDetection=0 
LevelForWormsDetection=0 
LevelForSearchEnginesDetection=0 
LevelForFileTypesDetection=0 

# OPTIONAL ACCURACY SETUP SECTION (Not required but increase AWStats features)
ShowMenu=1 
ShowSummary=HB 
ShowMonthStats=HB 
ShowDaysOfMonthStats=HB 
ShowDaysOfWeekStats=HB 
ShowHoursStats=HB 
ShowDomainsStats=0 
ShowHostsStats=HBL 
ShowAuthenticatedUsers=0 
ShowRobotsStats=0 
ShowEMailSenders=HBML 
ShowEMailReceivers=HBML 
ShowSessionsStats=0 
ShowPagesStats=0 
ShowFileTypesStats=0 
ShowFileSizesStats=0 
ShowBrowsersStats=0 
ShowOSStats=0 
ShowOriginStats=0 
ShowKeyphrasesStats=0 
ShowKeywordsStats=0 
ShowMiscStats=0 
ShowHTTPErrorsStats=0 
ShowSMTPErrorsStats=1
  • Add a line to the /etc/cron.d/awstats file, the same as the lines for the web sites:
0,10,20,30,40,50 * * * * root [ -x /var/www/cgi-bin.scripts.njae.me.uk/awstats.pl ] && /var/www/cgi-bin.scripts.njae.me.uk/awstats.pl -config=mail -update >/dev/null

Apache configuration

  • Allow whatever virtual host you're using to view the statistics. Update site.domain.tld to include these lines inside the VirtualHost block
Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /statistics/ /var/www/cgi-bin.domain.tld/
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

<Files "awstats.pl">
  AuthType Basic
  AuthName "AWStats"
  require valid-user
  AuthUserFile /etc/apache2/awstats.passwd
</Files>
  • The final stanza places the statistics behind a password (though only one password is needed to view the statistics of any of the sites). Add passwords for viewing the statistics with hte command
root@desktop:~# htpasswd -c /etc/apache2/awstats.passwd user_name
where user_name is the relevant user and then give the password.
  • Reload Apache config
root@desktop:~# /etc/init.d/apache2/reload

View stats

You can now view the statistics by browsing to http://site.domain.tld/statistics/awstats.pl?config=site2.domain.tld, where site2.domain.tld is the name of one of the AWStats config files created earlier.

See also

Personal tools