Installing AWstats
Today I decided to install AWStats for analysing my webserver traffic.
Running Debian Etch with apache 2.2 on the webserver / webproxy, the following steps are taken:
- Install awstats with
apt-get install awstats
- Put following in /etc/awstats/awstats.conf.local:
LoadPlugin="ipv6"
LoadPlugin="decodeutfkeys"
- Install the needed perl libs:
apt-get install libnet-dns-perl libnet-ip-perl libnet-ipv6addr-perl liburi-perl
- Create config files for each website running:
vim /etc/awstats/awstats.www.welmers.net.confInclude "/etc/awstats/awstats.conf" LogFile=”/var/log/apache2/www.welmers.net-access.log” LogType=W LogFormat=1 SiteDomain=”www.welmers.net” DefaultFile=”index.php index.html” LevelForWormsDetection=2
The log format is set to 1. This is the apache combined log format, with referer URLs and browser info. Use 4 for the simple apache log format (however I would recommend combined format anyway)
- After this, some weird bug showed up in awstats. It warns about nested includes that don’t work because perl version < 5.6 is installed. Great, I got 5.8.8. I found this bug on http://www.mail-archive.com/debian-bugs-dist%40lists.debian.org/msg385558.html and applied the patch.
- Next thing to do is to create initial awstat databases with the logfiles I already have.
One problem: they are alreay rotated several times. This can be solved this way:
rm /tmp/logfilefor i in `ls www.welmers.net-access.log.* | sort -n -r -t . -k 5`; do
zcat $i >> /tmp/logfile;
donecat www.welmers.net-access.log.1 >> /tmp/logfile
cat www.welmers.net-access.log >> /tmp/logfileEdit /etc/awstats/awstats.www.welmers.net.conf to temporarily use /tmp/logfile instead of /var/log/apache2/www.welmers.net-access.log
Then:
perl /usr/lib/cgi-bin/awstats.pl -config=www.welmers.net -update
And edit back /etc/awstats/awstats.www.welemrs.net.conf with the usual logfile. - Great. all old stuf is in awstats database! Now make it visible:
cp /usr/share/doc/awstats/examples/apache.conf /etc/apache2/awstats.conf
Include this file in your favorite virtual host container where awstats stuff can be viewed by authorized people only. Higly recommended, the reputation of awstats.pl CGI makes it neccessary to do so.
After inclusion, the script aliasScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
could be removed because it was already mentioned in my virtual host.
Now, when calling https://securehost.domain.com/cgi-bin/awstats.pl?config=www.welmers.net , you should be able to see all gathered data in the log files. - Now we want the awstats dbases update automagicly every 10 minutes, and just before rotating the apache logfiles:
EDITOR=vim crontab -e
# m h dom mon dow command
*/10 * * * * for config in `ls /etc/awstats/awstats.*.conf | cut -f2,3,4 -d"."`; do perl /usr/lib/cgi-bin/awstats.pl -config=$config -update; done
vim /etc/logrotate.d/apache2
and add:
prerotate
for config in `ls /etc/awstats/awstats.*.conf | cut -f2,3,4 -d"."`; do
perl /usr/lib/cgi-bin/awstats.pl -config=$config -update
done
endscript
in the /var/log/apache2/*.log block.
Done! My statistics get updated once per 10 minutes and I can view them easily via the awstats.pl CGI with the paramater ?config=www.mysite.com