wordpress 微软 程序员 java google php Ubuntu Windows Android Firefox HTML5 nginx linux命令 Python centos mysql shell apache 开源 linux

Awstats 7.1 在Apache下的配置及使用

Awstats简介

AWStats是一个专门用来分析Web站台记录档(log)的GPL授权软体,Awstats 是在 SourceForge 上发展很快的一个基于 perl 的 WEB 日志分析工具,一个充分的日志分析让 Awstats 显示你的下列资料:

  1. 参观者:按来访者不重复的ip统计,一个IP代表一个参观者.
  2. 参观次数:一个参观者可能1天之内参观多次(比如:上午一次,下午一次),所以按一定时间内(比如:1个小时) ,不重复的IP数统计,参观者的访问次数.
  3. 网页数:不包括图片,CSS, JavaScript文件等的纯页面访问总数,但如果一个页面使用了多个帧,每个帧都算一个页面请求.
  4. 文件数:来自浏览器客户端的文件请求总数,包括图片,CSS,JavaScript等,用户请求一个页面是,如果页面中包含图片等,所以对服务器会发出多次文件请求,文件数一般远远大于文件数.
  5. 字节:传给客户端的数据总流量.

Awstats安装配置

1:基本安装(.configure 执行时需检查其权限)

[root@chenyi1 ~]# tar zxf awstats-7.1.tar.gz
[root@chenyi1 ~]# mv awstats-7.1 /usr/local/awstats
[root@chenyi1 ~]# cd /usr/local/awstats/tools/
[root@chenyi1 tools]# chmod a+x awstats_configure.pl
[root@chenyi1 tools]# ./awstats_configure.pl
----- AWStats awstats_configure 1.0 (build 1.9) (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 filesapache groupapacheconfhttpd.conf
Config file path ('none' to skip web server setup):
> /etc/httpd/conf/httpd.conf                     #输入你httpd.conf的路径,这里将awstats的配置信息直接写入了httpd.conf
 
-----> 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.
 
#下面问你是否要创建一个新的配置文件,选择y,需要创建
-----> 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
#下面是要生成conf文件的名称了,因为conf文件的名称都是awstats.yourdomainname.conf格式的,所以这里要求你输入你要监测的域名,其实这个域名只是与其他域名相区分的,并不一定非要真实的。我这里输入的是www.linuxde.net
-----> 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.linuxde.net
 
#下面是让你输入配置文件的路径,直接回车就可以了,当然你也可以自己定义
-----> 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
 
-----> Create config file '/etc/awstats/awstats.www.linuxde.net.conf'
Config file /etc/awstats/awstats.www.linuxde.net.conf created.
 
-----> Restart Web server with '/sbin/service httpd restart'
停止 httpd:                                               [确定]
正在启动 httpd:                                           [确定]
 
-----> 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.linuxde.net
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.linuxde.net.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'www.linuxde.net' with command:
> perl awstats.pl -update -config=www.linuxde.net
You can also read your statistics for 'www.linuxde.net' with URL:
> http://localhost/awstats/awstats.pl?config=www.linuxde.net
 
Press ENTER to finish...

2. 建立数据存放目录

[root@chenyi1 tools]# cd /usr/local/awstats/
[root@chenyi1 awstats]# mkdir -m 755 data          #设置权限为755,不能被别人修改

3. 修改httpd.conf配置文件

[root@chenyi1 awstats]# cd tools/
[root@chenyi1 tools]# grep -v "^#" httpd_conf | grep -v "^$"       #如果httpd.conf文件里没有这些参数的话,需写入进去后重启httpd服务
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/"
<Directory "/usr/local/awstats/wwwroot">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>

4. 修改/etc/awstats下的日志配置文件

[root@chenyi1 tools]# cd /etc/awstats/
[root@chenyi1 awstats]# ls
awstats.www.linuxde.net.conf
[root@chenyi1 awstats]# vi awstats.www.linuxde.net.conf

编辑LogFile为web server的log文件位置 LogFile= /etc/httpd/logs/access_log

设置所要分析网站域名 SiteDomain="www.linuxde.net"

设置awstats的数据库存放目录 DirData="/usr/local/awstats/data

修改图片位置DirIcons="/awstatsicons"

如果是分析IIS日志,即修改:

LogFormat= 2
LogFormat = "%time2 %method %url %query %logname %host %ua %referer %code %bytesd %other "

5. 生成数据

[root@chenyi1 awstats]# cd /usr/local/awstats/wwwroot/cgi-bin/
[root@chenyi1 cgi-bin]# chmod a+x awstats.pl

[root@chenyi1 cgi-bin]# ./awstats.pl -update -config=www.linuxde.net
Create/Update database for config "/etc/awstats/awstats.www.linuxde.net.conf" by AWStats version 7.1 (build 1.982)
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...
Phase 2 : Now process new records (Flush history on disk after 20000 hosts)...
Jumped lines in file: 0
Parsed lines in file: 37
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 37 new qualified records.

6. 访问(如果你不可以访问的话,请检查其awstats的目录树权限)

http://www.linuxde.net/awstats/awstats.pl?config=www.linuxde.net

7. 安装插件:

利用QQ的纯真库IP信息来显示中国化的IP来源

[root@chenyi1 ~]# cd /usr/local/awstats/wwwroot/cgi-bin/plugins/
[root@chenyi1 plugins]# mv /root/plugins/awstats_qq/qqhostinfo.pm ./
[root@chenyi1 plugins]# mv /root/plugins/awstats_qq/QQWry.dat ./
[root@chenyi1 plugins]# mv /root/plugins/awstats_qq/qqwry.pl ./
[root@chenyi1 plugins]# chmod 755 qq*
[root@chenyi1 plugins]# chmod 755 QQ*
[root@chenyi1 plugins]# vi qqwry.pl                 #在约18行处去掉#注释,并修改路径!
my $ipfile="/usr/local/awstats/wwwroot/cgi-bin/plugins/QQWry.Dat";
[root@chenyi1 plugins]# vi /etc/awstats/awstats.www.linuxde.net.conf   #在 # PLUGINS 部分加上一句 LoadPlugin=”qqhostinfo”。

8.执行日志分析并cron计划任务

[root@chenyi1 plugins]# /usr/local/awstats/tools/awstats_updateall.pl now

crontab -e       #写入下面的命令,表示每5分钟分析一次!

*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now

延伸阅读

评论