ubuntu8.04下载安装配置awstats日志分析
制作:高进波
时间:2009-09-11
AWStats简介:Apache/Windows IIS的日志分析工具的下载,安装,配置样例和使用
apache2安装
apt-get install apache2 libapache2-mod-perl2
1.下载安装awstats:
wget http://downloads.sourceforge.net/project/awstats/AWStats/6.9/awstats-6.9.tar.gz?use_mirror=nchc
tar xvzf awstats-6.9.tar.gz
cd awstats-6.9
mv wwwroot/cgi-bin/ /var/www/cgi-bin/awstats #cgi脚本放到根下cgi-bin
mv wwwroot/* /var/www/ #静态文件放到WEB根
mv tools/* /var/www/cgi-bin/awstats/ #工具插件
2.安装GeoIP的应用库:C
http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar xvzf GeoIP.tar.gz
cd GeoIP-1.4.6
./configure
make && make install
3.安装perl插件-统计国家-城市
perl -MCPAN -e ‘install "Geo::IP"’
perl -MCPAN -e ‘install "Geo::IPfree"’
下载GeoIP/GeoIPCityLite包:解包到/var/www/cgi-bin/awstats目录下:
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
4.配置awstats
将缺省awstats.model.conf 命名成common.conf
cd /var/www/cgi-bin/awstats
mv awstats.model.conf common.conf
修改其中的一些配置选项:
vi common.conf
LoadPlugin="decodeutfkeys"
LoadPlugin="geoip GEOIP_STANDARD /var/www/cgi-bin/awstats/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/www/cgi-bin/awstats/GeoLiteCity.dat"
提高统计的速度(减少磁盘IO)
vi awstats.pl
修改第45行为
$LIMITFLUSH = 50000;
5.添加网站分析配置文件
vi awstats.114la.conf
Include "common.conf"
LogFile="/var/www/logs/7527_20090910_w3c"
SiteDomain="www.114la.com"
HostAliases="114la.com"
DefaultFile="index.html"
DirData="/var/www/data/"
建立相关目录
mkdir /var/www/logs/ 日志文件目录
mkdir /var/www/data/ 分析后数据存放的目录
6.生成分析文件
日志分析
./awstats.pl -update -config=114la -lang=cn
统计输出
http://localhost/cgi-bin/awstats/awstats.pl?config=114la
合并日志
./logresolvemerge.pl /var/www/logs/* >all-log-6885
附:
多站点日志统计
AWStats自带了一个批处理工具:tools/awstats_updateall.pl,可以批量地遍历一个目录下所有地配置文件并运行统 计。因此剩下的工作就主要是日志的同步问题了。
针对多个站点,很多配置选项是重复的,如果每个配置文件都修改维护起来会很麻烦,AWStats从5.4版本开始提供了配置文件包含的功能,所以我们可 以配置一个通用配置,比如:common.conf
然后其他站点的配置设置为:可以通过后面的选项覆盖和缺省不一致的配置。
awstats.bbs.chedong.conf
Include "chedong.common.conf"
LogFile "/path/to/bbs_log"
SiteName "bbs.chedong.com"
awstats.www.chedong.conf
Include "chedong.common.conf"
LogFile "/path/to/www_log"
SiteName "www.chedong.com"
HostAliases="chedong.com"
apache虚拟主机配置(可选)
vi /etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerName 114log.com
ServerAlias www.114log.com
DirectoryIndex index.html index.htm index.php
DocumentRoot /var/www/
Alias /awstatsclasses "/var/www/cgi-bin/awstats/classes/"
Alias /awstatscss "/var/www/cgi-bin/awstats/css/"
Alias /awstatsicons "/var/www/icon/"
Alias /awstats/ "/var/www/cgi-bin/awstats/"
<directory "/var/www/cgi-bin/awstats">
AllowOverride None
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</directory>
</VirtualHost>
数据源日志格式和按天的截断规则
对于Apache:日志格式好设置:设置成combined格式即可,日志截断麻烦一点:需要安装cronolog工具,将日志设置成按天截断:
CustomLog "|/usr/local/sbin/cronolog /path/to/apache/logs/access_log.%Y%m%d" combined
比如:logs/access_log.20030326
日志是压缩格式,可以使用gzip -d < /home/apache/logs/access_log.%YYYY-24%MM-24%DD-24.gz | 动态解压缩统计。
统计Apache日志只需修改:LogFile SiteDomain这2个选项
1. GNU/Linux LogFile="/path/to/apache/logs/access_log.%YYYY-24%MM-24%DD-24"
Windows 2000 LogFile="d:\iis_logs\W3SV3\ex%YY-24%MM-24%DD-24.log"
这个配置的意思是用24小时前的年份,月份,日期拼出的日志文件名;
2. SiteDomain="www.chedong.com"
站点的名称,缺省是空的,如果为空,AWStats将拒绝运行;
完成!
六月 26th, 2010 at 12:17
These tips are so true
三月 9th, 2011 at 13:54
Pretty good post…
I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your rss and I hope you post again soon….
五月 9th, 2011 at 20:08
Related Websites…
[...]here are some other links to sites that we find everyday so here are some popular sites we like today[...]…