日期:2014-05-17  浏览次数:20935 次

用awstats分析apache日志

1.安装Apache(略)

2.安装cronolog(日志截取工具)
tar zxf cronolog-1.6.2.tar.gz
cd cronolog-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)
tar jxf awstats-6.9.tar.bz2
mv awstats-6.9 /usr/local/awstats
chown -R root:root awstats
chmod -R 755 awstats
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的对应段落。如:
#
# Directives to allow use of AWStats as a CGI
#
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 to scripts/files in AWStats directory.
#
<Directory "/usr/local/awstats/wwwroot">
??? Options None
??? AllowOverride None
??? Order allow,deny
??? Allow from all
</Directory>

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

6.给awstats访问设置密码
/usr/local/apache2/bin/htpasswd -cb /etc/awstats/htpasswd admin 123456
在apache配置文件httpd.conf最后添加一段:
<Files "awstats.pl">
??? AuthType Basic
??? AuthName "awstat access"
??? AuthUserFile "/etc/awstats/htpasswd"
??? Require valid-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
cd Geo-IP-PurePerl-1.23
perl Makefile.PL
make
make install