
简介
AWStats,全名为 Advanced Web Statistics,是一套免费功能强大并支援多国语言的工具软件,专门用来分析Web.Streaming.FTP或Mail服务器的统计资料,并可产生统计报表,显示用户端连线至网站存取网页的日志信息。它可以分析许多主要服务器的日志文件,如 Apache 的日志文件 (NCSA combined/XLF/ELF 日志格式或者 common/CLF 日志格式)、WebStar、IIS (W3C 日志格式) 以及许多其它的 Web、Proxy、Wap、Streaming 服务器、Mail 服务器及部份 FTP 服务器。
AWStats 与其它统计分析软件(Analog、Webalizer、HitBox…)相较之下,可以产生更多样的纪录,并做更详细的分析。你可以到这里查看比较著名的分析工具 (AWStats、Analog、Webalizer...)的功能及差异性的功能比较表。
AWStats 是免费的 GPL (GNU General Public License) 授权软件,你可以查看 license chart 看哪些是可以或不能做的。
AWStats 是以 Perl 透过指令列的方式执行,但也可以从浏览器透过 CGI 的方式来做即时更新的动作,因此请在安装之前确认系统中已安装 Perl 程序或组件,并启动 CGI 的执行权限。
下载
访问 http://awstats.sourceforge.net/#DOWNLOAD 下载最新的稳定版本或者最新的测试版。本文使用最新的测试版来做介绍
wget http://awstats.sourceforge.net/files/awstats-6.95.tar.gz
安装前准备工作
yum -y install php php-devel php-eaccelerator httpd httpd-devel perl perl-URI perl-Geo-IP perl-Geo-IP-PurePerl perl-Geo-IPfree geoip perl-Net-XWhois
系统环境
CentOS 5.3
Apache 2.2.3
PHP 5.1.6
Awstats 6.95
安装前的规定
/usr/local/awstats awstats的安装路径
/usr/local/awstats/wwwroot 这目录下的文件就是用户通过浏览器访问到的页面
/etc/awstats awstats的站点配置路径
/usr/local/awstats/log awstats所要分析的日志路径 需要手工创建
/usr/local/awstats/datadir awstats的db路径 需要手工创建
安装
# sed -i "265 s/#ServerName www.example.com:80/ServerName localhost:80/g" /etc/httpd/conf/httpd.conf
# tar -xvzf awstats-6.95.tar.gz -C /usr/local/
# mv awstats-6.95/ awstats
# mkdir awstats/{log,datadir}
# chown apache.apache datadir/ -R # 使用web界面更新数据信息该目录必须可写
# cd awstats/tools
# ./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.8) (c) Laurent Destailleur -----
This tool will help you to configure AWStats to analyze statistics for
one web server. You can try to use it to let it do all that is possible
in AWStats setup, however following the step by step manual setup
documentation (docs/index.html) is often a better idea. Above all if:
- You are not an administrator user,
- You want to analyze downloaded log files without web server,
- You want to analyze mail or ftp log files instead of web log files,
- You need to analyze load balanced servers log files,
- You want to 'understand' all possible ways to use AWStats...
Read the AWStats documentation (docs/index.html).
-----> Running OS detected: Linux, BSD or Unix
-----> Check for web server install
Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path ('none' to skip web server setup):
>/etc/httpd/conf/httpd.conf 由于apache是yum安装的故其主配置文件在这里
输入完apache配置路径后,配置程序会将awstats的配置信息写入到apache主配置文件中。
-----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
Add '' directive
AWStats directives added to Apache config file.
-----> Update model config file '/usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf'
File awstats.model.conf updated.
这一步是询问是否要创建一个标准的awstats配置文件。
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? Y
定义配置文件
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.myweb.com
定义配置文件路径
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> 直接回车即可,按照默认的路径/etc/awstats
这一步说明刚刚创建的www.myweb.com的配置文件路径
-----> Create config file '/etc/awstats/awstats.www.myweb.com.conf'
Config file /etc/awstats/awstats.www.myweb.com.conf created.
修改完配置文件后 重启apache服务
-----> Restart Web server with '/sbin/service httpd restart'
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
将更新进程加入到计划任务中。该脚本不支持写入计划任务的操作,需要手动完成
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.myweb.com
Or if you have several config files and prefer having only one command:
/usr/local/awstats/tools/awstats_updateall.pl now
Press ENTER to continue...
简单的配置文件已经完成,这个配置文件还需要手动设置一些变量,且第一次手动来执行更新脚本。
A SIMPLE config file has been created: /etc/awstats/awstats.www.myweb.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.myweb.com' with command:
> perl awstats.pl -update -config=www.myweb.com
You can also read your statistics for 'www.myweb.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.myweb.com
Press ENTER to finish... |
系统集成
# cd /usr/local/bin
# ln -s /usr/local/awstats/tools/*.pl .
配置awstats
至此为止,利用awsats_configure.pl脚本进行安装的工作已经完成,接下来手动编辑配置文件,修改如下选项
# vi /etc/awstats/awstats.www.myweb.com.conf
LogFile="/var/log/httpd/mylog.log"
修改为
LogFile="/usr/local/awstats/log/www.myweb.com.log"
DirData="/usr/lib/awstats"
修改为
DirData="/usr/local/awstats/datadir"
AllowToUpdateStatsFromBrowser=0
修改为
AllowToUpdateStatsFromBrowser=1
或直接执行下面sed命令完成修改
sed -i -e "51 s/LogFile=\"\/var\/log\/httpd\/mylog.log\"/#LogFile=\"\/var\/log\/httpd\/mylog.log\"\nLogFile=\"\/usr\/local\/awstats\/log\/www.myweb.com.log\"/" -e "204 s/DirData=\"\/var\/lib\/awstats\"/#DirData=\"\/var\/lib\/awstats\"\nDirData=\"\/usr\/local\/awstats\/datadir\"/" -e "240 s/AllowToUpdateStatsFromBrowser=0/AllowToUpdateStatsFromBrowser=1/" /etc/awstats/awstats.www.myweb.com.conf |
执行完上面的命令后,配置文件的相应行被修改成了如下内容:
LogFile="/var/log/httpd/mylog.log"
LogFile="/usr/local/awstats/log/www.myweb.com.log"
#DirData="/var/lib/awstats"
DirData="/usr/local/awstats/datadir"
#AllowToUpdateStatsFromBrowser=0
AllowToUpdateStatsFromBrowser=1
将www.myweb.com的日志复制到配置awstats的机器中,并更名为www.myweb.com.log复制到/usr/local/awstats/log目录下。
# cp access.log /usr/local/awstats/log/www.myweb.com.log
# /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.myweb.com
Create/Update database for config "/etc/awstats/awstats.www.myweb.com.conf" by AWStats version 6.95 (build 1.932) From data in log file "/usr/local/awstats/log/www.myweb.com.log"... Phase 1 : First bypass old records, searching new record... Direct access to last remembered record has fallen on another record. So searching new records from beginning of log file... Phase 2 : Now process new records (Flush history on disk after 20000 hosts)... Jumped lines in file: 0 Parsed lines in file: 111879 Found 166 dropped records, Found 43153 corrupted records, Found 33 old records, Found 68527 new qualified records. |
# crontab -e
5 2 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.myweb.com
如果有多个站点可以使用awstats提供的批量更新状态的程序
5 2 * * * /usr/local/awstats/tools/awstats_updateall.pl now 2>&1>/dev/null
awstats_updateall.pl 使用方法和参数如下:
# ./awstats_updateall.pl --help
----- awstats_updateall 1.0 (build 1.15) (c) Laurent Destailleur ----- awstats_updateall 程序会更新所有 AWStats 配置文件(awstats.model.conf除外) 因此可以设置一条简单的cron/scheduler 任务。程序扫描的目录默认为/etc/awstats. 用法: awstats_updateall.pl now [options] 选项: # 指定awstats.pl的文件路径 -awstatsprog=pathtoawstatspl # 配置文件路径。默认为/etc/awstats -configdir=directorytoscan # 需要排除的配置文件。awstats.model.conf 永久排除 -excludeconf=conftoexclude[,conftoexclude2,...] |
重新启动apache
# service httpd restart
访问awstats页面

设置awstats安全登录
# htpasswd -c /etc/httpd/awstatspass awstats
New password: 密码:******
Re-type new password:
Adding password for user awstats
# vi /etc/httpd/conf/httpd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 | Options none AllowOverride None Order allow,deny Allow from all #修改为 Options IncludesNoExec AuthType Basic AuthName "Awstats Web Login" AuthUserFile "/etc/httpd/awstatspass" Require User awstats AllowOverride None Order allow,deny Allow from 192.168.0.0/16 |
# service httpd restart
再访问页面

提示输入密码方可进入web页面
附录
更新历史
2009/06/09 ZhouYueQiu First release
2009/07/14 ZhouYueQiu 修正DirData参数错误,增加了。更新所有配置文件的命令。
近期评论