部署Apache网站访问统计-AWStats分析系统

时间:2021-09-13 13:18:34

环境根据:http://www.cnblogs.com/zzzhfo/p/5925786.html

1、安装AWStats软件包

将软件包解压到httpd服务器中的/usr/lcoal/目录下
[root@www /]# tar zxf awstats-7.3.tar.gz
[root@www /]# mv awstats-7.3 /usr/local/awstats

2、为要统计的站点建立配置文件

[root@www /]# cd /usr/local/awstats/tools/
[root@www tools]# chmod +x awstats_configure.pl
[root@www tools]# ./awstats_configure.pl
指定httpd主配置文件的路径
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):
> /usr/local/httpd/conf/httpd.conf #输入httpd.conf配置文件的路径 设置日志的类型
-----> Check and complete web server config file '/usr/local/httpd/conf/httpd.conf'
Warning: You Apache config file contains directives to write 'common' log files
This means that some features can't work (os, browsers and keywords detection).
Do you want me to setup Apache to write 'combined' log files [y/N] ? y
....... 为指定web站点创建配置文件
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y #确认创建新的站点配置文件 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.httpd.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键接受默认配置 -----> Create config file '/etc/awstats/awstats.www.httpd.com.conf'
Config file /etc/awstats/awstats.www.httpd.com.conf created. -----> Restart Web server with '/sbin/service httpd restart' -----> 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.httpd.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.httpd.com.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.httpd.com' with command:
> perl awstats.pl -update -config=www.httpd.com
You can also read your statistics for 'www.httpd.com' with URL:
> http://localhost/awstats/awstats.pl?config=www.httpd.com Press ENTER to finish...

3、修改站点统计配置文件

[root@www tools]# vim /etc/awstats/awstats.www.httpd.com.conf
LogFile="/usr/local/httpd/logs/access_log"
DirData="/var/lib/awstats"
[root@www tools]# mkdir /var/lib/awstats

4、执行日志分析、并设置cron计划任务

使用awstats提供的awstats_updateall.pl脚本、可以更新所以站点的日志统计数据
[root@www tools]# chmod +x awstats_updateall.pl
[root@www tools]# ./awstats_updateall.pl now
Running '"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.httpd.com -configdir="/etc/awstats"' to update config www.httpd.com

Create/Update database for config "/etc/awstats/awstats.www.httpd.com.conf" by AWStats version 7.3 (build 20140126)
From data in log file "/usr/local/httpd/logs/access_log"...
Phase 1 : First bypass old records, searching new record...
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: 124
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 1 corrupted records,
Found 0 old records,
Found 123 new qualified records.

[root@www tools]# crontab -e
*/ * * * * /usr/lcoal/awstats/tools/awstats_updateall.pl now
[root@www tools]# /etc/init.d/crond start
[root@www tools]# chkconfig --level crond on

访问awstats分析系统

http://192.168.119.131/awstats/awstats.pl?config=www.httpd.com

部署Apache网站访问统计-AWStats分析系统

优化URL 做个跳转网页
[root@www tools]# vim /usr/local/httpd/htdocs/awb.html
<html>
<head>
<meta http-equiv=refresh content="0;
url=http://192.168.119.131/awstats/awstats.pl?config=www.httpd.com">
</head>
<body></body>
</html>

访问192.168.119.131/awb.html