用awstats分析apache日志

1.安装Apache(略)

2.安装cronolog(日志截取工具)

tarzxfcronolog-1.6.2.tar.gz

cdcronolog-1.6.2

./configure

make

make install

3.配置apache

在<VirtualHost*:80></VirtualHost>中加入类似:

CustomLog"|/usr/local/sbin/cronolog/usr/local/apache2/logs/%Y/%m/%d/bbs.testtimes.net-access_log"combined

ErrorLog"|/usr/local/sbin/cronolog/usr/local/apache2/logs/%Y/%m/%d/bbs.testtimes.net-error_log"

的日志分年月日截取的设置。

4.安装awstats(http://awstats.sourceforge.net/#DOWNLOAD,最新稳定版6.9)

tarjxfawstats-6.9.tar.bz2

mvawstats-6.9/usr/local/awstats

chown-Rroot:rootawstats

chmod-R755awstats

cd/usr/local/awstats/tools

perl awstats_configure.pl

随后跟随设置向导:Do you want me to setup Apache to write 'combined' log files [y/N] ?y

Do you want me to build a new AWStats config/profile file (required if first install) [y/N] ?y

Your web site, virtual server or profile name:>www.testtimes.net

Directory path to store config file(s) (Enter for default): //直接回车,默认路径/etc/awstats

配置结束后,向导程序自动在apache配置文件httpd.conf中加入awstats的对应段落。如:

#

#DirectivestoallowuseofAWStatsasaCGI

#

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/"

#

#ThisistopermitURLaccesstoscripts/filesinAWStatsdirectory.

#

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

OptionsNone

AllowOverrideNone

Orderallow,deny

Allowfromall

</Directory>

5.创建文件夹mkdir -p /var/lib/awstats

6.给awstats访问设置密码

/usr/local/apache2/bin/htpasswd-cb/etc/awstats/htpasswdadmin123456

在apache配置文件httpd.conf最后添加一段:

<Files"awstats.pl">

AuthTypeBasic

AuthName"awstataccess"

AuthUserFile"/etc/awstats/htpasswd"

Requirevalid-user

</Files>

7.重启Apache/usr/local/apache2/bin/apachectl restart

8.安装国家和城市插件

http://search.cpan.org/CPAN/authors/id/B/BO/BORISZ/Geo-IP-PurePerl-1.23.tar.gz

http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz

http://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.38.tar.gz

tar zxf Geo-IP-PurePerl-1.23.tar.gz

cdGeo-IP-PurePerl-1.23

perlMakefile.PL

make

make install

tar zxf GeoIP-1.4.6.tar.gz

cdGeoIP-1.4.6

./configure

make

make install

tar zxf Geo-IP-1.38.tar.gz

cdGeo-IP-1.38

perlMakefile.PL

make

make install

http://www.maxmind.com/download/geoip/database/

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/

gzip-dGeoLiteCity.dat.gz

cpGeoLiteCity.dat/usr/local/share/GeoIP/

gzip-dGeoIP.dat.gz

cp GeoIP.dat /usr/local/share/GeoIP/

9.安装QQ纯真IP库解析插件

http://www.ieasy.org/download/qqhostinfo.pm

http://www.ieasy.org/download/qqwry.pl

cp qqhostinfo.pm /usr/local/awstats/wwwroot/cgi-bin/pluginscp qqwry.pl /usr/local/awstats/wwwroot/cgi-bin/plugins

编辑qqwry.pl,把./QQWry.Dat 改为 ${DIR}/plugins/QQWry.Dat上传QQWry.Dat到/usr/local/awstats/wwwroot/cgi-bin/plugins目录下

10.安装Net-XWhois

tar zxf Net-XWhois-0.90.tar.gz

cdNet-XWhois-0.90

perlMakefile.PL

make

make install

11.编辑awstats配置文件

配置文件位于/etc/awstats目录下,修改如下:

LogFile="/usr/local/apache2/logs/%YYYY/%MM/%DD/www.testtimes.net-access_log"

SiteDomain="www.testtimes.net"

注:对于多域名的日志分析,每个域名对应一个日志文件,可以复制后修改其中的LogFile、SiteDomain这两项即可。

打开如下的LoadPlugin:

LoadPlugin="tooltips"

LoadPlugin="decodeutfkeys"

LoadPlugin="geoipGEOIP_STANDARD/usr/local/share/GeoIP/GeoIP.dat"

LoadPlugin="geoip_city_maxmindGEOIP_STANDARD/usr/local/share/GeoIP/GeoLiteCity.dat"

LoadPlugin="hostinfo"

LoadPlugin="qqhostinfo"(该项不存在,手动添加的)

12.分析过去的日志可以下载并运行附件中的shell脚本程序,传递域名参数,即可开始分析了。

13.添加crontab

crontab-e

* */3 * * * /usr/local/awstats/tools/awstats_updateall.pl now  (每3小时运行一次)

注:以上是多域名的情况,最简单就是那样了,对于单域名也可以写成/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.testtimes.net

相关推荐