AWSTATS-日志分析

Awstats是一个免费非常简洁而且强大有个性的网站日志分析工具。

  PV(访问量):即Page View, 页面浏览量或点击量,用户每次刷新即被计算一次。

  UV(独立访客):即Unique Visitor,访问您网站的一台电脑客户端为一个访客。00:00-24:00内相同的客户端只被计算一次。

  IP(独立IP):即Internet Protocol,指独立IP数。00:00-24:00内相同IP地址之被计算一次。


参考文档:http://www.chinaunix.net/old_jh/13/447225.html

http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.1/awstats-7.1.tar.gz

http://awstats.sourceforge.net/files/awstats-7.2.tar.gz     ##下载源码包


一、安装-配置

# tar -zxf awstats-7.1.tar.gz

# cd awstats-7.1

# mv awstats-7.1 /usr/local/awstats

# cd /usr/local/awstats/tools/

# chmod 775 awstats_configure.pl

# ./awstats_configure.pl        ##运行自动安装向导(多个WEB站点。运行多次、产生多个配置文件)

> /etc/httpd/conf/httpd.conf    //指定web配置文件路径

file (required if first install) [y/N] ?y        //同意创建新的站点配置

> web.tarena.com             //创建新的站点名称

Default: /etc/awstats        //默认awstats配置文件存放位置

 


自动会在web配置文件末尾生成以下内容

# tail /usr/local/apache/conf/httpd.conf        ##依据自己的WEB服务配置文件查看

 

# Directives to allow use of AWStats as aCGI

#

Alias /awstatsclasses"/usr/local/awstats/wwwroot/classes/"

Alias /awstatscss"/usr/local/awstats/wwwroot/css/"

Alias /awstatsicons"/usr/local/awstats/wwwroot/icon/"

ScriptAlias /awstats/"/usr/local/awstats/wwwroot/cgi-bin/"

 

#

# This is to permit URL access toscripts/files in AWStats directory.

#

<Directory"/usr/local/awstats/wwwroot">

   Options None

   AllowOverride None

   Order allow,deny

   Allow from all

</Directory>


2.修改awstats配置文件

# vim /etc/awstats/awstats.xx.xx.xx.conf

LogFile="/data/nginx/logs/010tarena_access.log"       //要分析的日志文件

SiteDomain="www.010tarena.com"

HostAliases="010tarena.comwww.010tarena.com 127.0.0.1 localhost"

DirData="/data/nginx/awstats"//默认工作目录(需要自己手动创建)生成的日志分析结果的保存路径

DirCgi="/awstats"

DirIcons="/awstatsicons"

 

# mkdir /data/nginx/awstats

# chmod 775 awstats_updateall.pl

# chmod R 775 ../wwwroot/

 

4.更新日志数据

# ./awstats_updateall.plnow    //更新统计信息(加入crond)手动更新的命令:/usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update -config=web.tarena.com


# crontab -e

* 02 * * * /usr/local/awstats/tools/awstats_updateall.plnow

 

5.使用WEB页面访问

http://118.145.21.181/awstats/awstats.pl?config=www.023tarena.net   //验证访问地址

 

二、模块的添加

  Awstats默认安装之后是不具有识别访问者的国家和地区信息的,所以需要安装插件支持Awstats列出访问者的国家和地区,便于分析

  安装配置GeoIP插件:

GeoIP免费的是国家/IP的数据表,GeoIPCityLite是地区的数据表

MaxMind目前免费提供了GeoIP和GeoIPCityLite数据包:可以定期每个月从以下地址下载:

wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

 

下载之后

# mkdir /var/GreIP

把两个文件移入新建的目录中gunzip解压即可


GeoIP安装步骤如下:

先下载GeoIP C库:

去https://www.maxmind.com/download/geoip/api/c/下载GeoIP-1.4.8.tar.gz 

# tar xf GeoIP-1.4.8.tar.gz 

cd进入解压目录,执行如下操作安装

# ./configure ; make && make install 


接下来下载GeoIP perl库:

去https://www.maxmind.com/download/geoip/api/perl/下载Geo-IP-1.40.tar.gz 

# tar xf Geo-IP-1.40.tar.gz 

cd 进入解压目录,执行如下操作安装

# perl Makefile.PL LIBS='-L/usr/local/lib' 

//这里必需使用这种方法安装,笔者尝试把/usr/local/lib加入/etc/ld.so.conf.d/geoip.conf并执行ldconfig,单独执行perl Makefile.PL还是发现不了GeoIP的C库,所以只能以perl Makefile.PL LIBS='-L/usr/local/lib' 这种方式执行

# make && make install


最后修改/etc/awstats/awstats.IP/HOSTNAME.conf

# vim /etc/awstats/awstats.IP/HOSTNAME.conf

#加入以下两行

LoadPlugin="geoip GEOIP_STANDARD /var/GeoIP/GeoIP.dat"   #约1422行

LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/GeoIP/GeoLiteCity.dat"   #约1432行

# rm -rf /var/lib/awstats/*   #删除旧的统计数据

# /usr/local/awstats/tools/awstats_updateall.pl now

#重新生成数据即可,查看监控页面就可以获取来访者的国家和地区了



参考文档: http://wangyan.org/blog/howto-setup-geoip-for-awstats.html  

                  http://www.chedong.com/tech/awstats.html