awstats 强大的线上web服务器访问统计
suse 11
一 安装awstats.
#zypper in httpd
#cd /srv/www/htdocs
#chown -R wwwrun:www *
修改/etc/apache2/httpd.conf 如下字段:
<Directory "I:/build/dist">
#开启目录列表索引模式
Options Indexes
Order allow,deny
IndexOptions NameWidth=25 Charset=UTF-8
Allow from all
</Directory>
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
修改/etc/apache2/default-server.conf:
DocumentRoot "/media/sources"
<Directory "/media/sources">
Options All
AllowOverride None
Order allow,deny
Allow from all
</Directory>
启动http服务:
#/etc/init.d/apache2 restart
1. 安装包下载地址:http://awstats.sourceforge.net/
2. 上传awstats-7.0.tar.gz到/usr/local目录下。
3. 赋予执行权限。
#chmod +x awstats-7.0.tar.gz
4. 解压文件。
#tar zxvf awstats-7.0.tar.gz
5. 解压完后会生成awstats7.0文件夹,包含docs README.TXT tools wwwroot。
6. 将awstats7.0重命名为awstats
#mv awstats7.0 awstats
7. 运行脚本生成awstats的配置文件.
#cd /usr/local/awstats/tools
#perl awstats_configure.pl
8. 配置过程.
-----> 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/apache2/httpd.conf //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 '<Directory>' 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.
-----> 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
2
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.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.comwww.test.com www.test.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):
>Enter //回车使用默认的配置/etc/awstats(最好使用默认配置,否则会出现很多意想不到的错误)
-----> 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):
>
-----> Create config file '/etc/awstats/awstats.www.test.com.conf' //生成awstats的配置文件,注意路径和文件名
Config file /etc/awstats/awstats.www.test.com.conf created.
-----> Restart Web server with '/sbin/service httpd restart'
httpd: apr_sockaddr_info_get() failed for test
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Stopping httpd: [ OK ]
Starting httpd: [ OK ] //重启apache
-----> 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.test.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.test.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.test.com' with command:
> perl awstats.pl -update -config=www.test.com
You can also read your statistics for 'www.test.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.test.com
Press ENTER to finish...
配置完成。
二 编辑配置文件
9. 编辑awstats配置文件
#vi /etc/awstats/awstats.www.test.com.conf
更改如下配置
LogFile=/var/log/apache2/access_log
设置apache的logfile位置,一定要保证和httpd.conf中的log文件保证一致,httpd.conf中log名称为CustomLog logs/access_log combined
LogType=W
设置要分析的服务日志类型,W表示为WEB日志
LogFormat=1
设置日志格式,1表示采用NCSA apache combined/ELF/XLF log format
SiteDomain="www.test.com"
设置所要分析网站域名 ,引号中一定要填上域名,或者服务器主机名
DirData="/usr/local/awstats/data"
设置awstats的数据库存放目录
三 创建数据库文件
10. 创建数据库存放目录
#mkdir -p /usr/local/awstasts/data
#chmod -R 755 /usr/local/awstasts/data
11. 更改脚本权限
#chmod 755 /usr/local/awstats/wwwroot/cgi-bin/*.pl
12. 创建awstats初始化数据库
#cd /usr/local/awstats/wwwroot/cgi-bin
#./awstats.pl -update -config=www.test.com
13. 执行成功会显示如下信息
Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 7.0 (build 1.971)
From data in log file "/etc/httpd/logs/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 0
Found 0 dropped records,
4
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
14. 执行过程中可能会遇到错误:日志的格式不匹配
解决方式:删掉access_log,重新启动apache,会在相应位置再次生成access_log
四 创建页面文件
15. 创建awstats文件夹
#cd /var/www/html
#mkdir awstats
16. 执行awstats_buildstaticpages.pl脚本,生成页面文件
#cd /usr/local/awstats/tools/
#./awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn -dir=/srv/www/htdocs/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
执行成功会显示如下信息
Launch update process : "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -update -configdir=
Build main page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output
Build alldomains page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=alldomains
Build allhosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=allhosts
Build lasthosts page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=lasthosts
Build unknownip page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"
5
-config=www.test.com -staticlinks -lang=cn -output=unknownip
Build allrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=allrobots
Build lastrobots page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=lastrobots
Build session page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=session
Build urldetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=urldetail
Build urlentry page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=urlentry
Build urlexit page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=urlexit
Build osdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=osdetail
Build unknownos page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=unknownos
Build browserdetail page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=browserdetail
Build unknownbrowser page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=unknownbrowser
Build refererse page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=refererse
Build refererpages page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=refererpages
Build keyphrases page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=keyphrases
Build keywords page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"
6
-config=www.test.com -staticlinks -lang=cn -output=keywords
Build errors404 page: "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -config=www.test.com -staticlinks -lang=cn -output=errors404
20 files built.
Main HTML page is 'awstats.www.test.com.html'.
18. 设置awstats文件夹权限
#chmod -R 755 /var/www/html/awstats
五 添加定期执行脚本
19. 加入定期执行脚本,每分钟更新一次
#crontab -e
*/1 * * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.test.com -update
20. 查看主页流量分析
http://www.test.com/awstats/awstats.pl?config=www.test.com
如果遇到访问拒绝错误,请确认awstats目录及其所含文件的权限,
关闭selinux并重启系统。
六 为awstats加入认证功能
//创建存放密码的目录
#mkdir �Cp /etc/httpd/password
//生成密码文件,用户名:admin
#cd /usr/bin
#./htpasswd -c /etc/httpd/password/passwords admin
New password: 输入密码
Re-type new password: 再次输入密码
7
Adding password for user admin
//在文件/etc/httpd/conf/httpd.conf,加入如下红字内容
<Directory "/usr/local/awstats/wwwroot">
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/httpd/password/passwords
Require user admin
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>