awstats通过一个简单的安装,就可以实现对于一个web 以及多个web界面进行一个访问量进行统计,并记录访问者的位置以及特别字,方便管理员进行网站更新和统计。awstats的官网是http://www.awstats.org/

废话不多说,我们来做一个简单的页面测试。比如我的虚拟机使用的是redhat linux enterprises AS5,设置的主机名为localhost.linux.net。

具体步骤如下:

{注意:为了能够保证测试能够完全没有问题,建议首先使用以下命令

mkdir   /etc/awstats

建立的一个放置awstats的配置文件位置

mkdir  /var/lib/awstats}

建立一个放置库文件的目录

iptables  -A  INPUT   -p  tcp  -i eth0  --sport  80  -j ACCEPT

建立一个iptables,允许所有源端口为80从eth0进入
  wget  http://www.awstats.org/files/awstats-7.1.tar.gz
   /etc/rc.d/init.d/iptables save

保存刚才自定义的iptabels

tar zxvf awstats-7.1.tar.gz
  mv awstats-7.1  /usr/local/awstats

放置应用程序到usr下面的local目录下
  cd /usr/local/

根据官网的文件,首先执行perl脚本程序

[root@localhost tools]# perl   awstats_configure.pl

-----> Check and complete web server config file '/usr/local/apache/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] ?

检测系统,并写入信息到apache的配置文件中 确定


-----> Running OS detected: Linux, BSD or Unix

-----> Check for web server install
  Found Web server Apache config file '/usr/local/apache/conf/httpd.conf'

-----> Check and complete web server config file '/usr/local/apache/conf/httpd.conf'
  All AWStats directives are already present.

-----> 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

创建一个新的awstats的新文件

-----> 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:
> localhost.linux.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):
>

-----> Create config file '/etc/awstats/awstats.localhost.linux.net.conf'
 Config file /etc/awstats/awstats.localhost.linux.net.conf created.

-----> 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=localhost.linux.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.localhost.linux.net.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for 'localhost.linux.net' with command:
> perl awstats.pl -update -config=localhost.linux.net
You can also read your statistics for 'localhost.linux.net' with URL:
> http://localhost/awstats/awstats.pl?config=localhost.linux.net

Press ENTER to finish...

创建的文件已经访问awstats的路径!完成请回车

[root@localhost tools]# perl  awstats_configure.pl
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LANG = "en_US.GB2312"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

提示perl语言错误没有设置LC_ALL ,设置一个

[root@localhost tools]# export  LC_ALL="C"

查看生成的文件

[root@localhost tools]# cat /etc/awstats/awstats.localhost.linux.net.conf

修改配置文件

LogFile="/usr/local/apache/logs/access_log"(确保日志文件的位置正确)

(这个地方的日志文件的路径为本机网站生成日志文件的位置,如果是rpm安装的,应该是/etc/www/html/...
LogType=W
LogFormat=1
LogSeparator=" "
SiteDomain="localhost.linux.net"
HostAliases="localhost.linux.net www.localhost.linux.net 127.0.0.1 localhost"
DNSLookup=2
DirData="/var/lib/awstats"
DirCgi="/awstats"
DirIcons="/awstatsicons"

确保这些信息正确

查看apche主配置文件的信息

#
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>

刚才我们执行的那个perl脚本自动添加信息到apache配置文件中

修改配置文件的信息 添加CGI的执行权限

    Options +ExecCGI

重新启动apache服务并更新awstats的数据库

  /usr/local/apache/bin/apachectl restart( 修改过apache的配置文件的时候,需要重新启动服务,让配置生效)

  perl  awstats.pl -config=localhost.linux.net  -update  -output >index.html

指定任务计划 5分钟刷新一次 

[root@localhost ~]# cat awstats.sh
perl  awstats.pl  -config=localhost.linux.net  -update  -output  >index.html

*/5  * * * * root /root/awstats.sh(格式分别为分 时  日 月 星期  用户  执行的命令)

如果是每天的18点应该是  *  18 * * * root /root/awstats.sh(时间格式为24小时)

打开awstats的页面查看


Error: AWStats database directory defined in config file by 'DirData' parameter (/var/lib/awstats) does not exist or is not writable.

Setup ('/etc/awstats/awstats.localhost.linux.net.conf' file, web server or permissions) may be wrong.
Check config file, permissions and AWStats documentation (in 'docs' directory).

错误:awstats的数据目录文件存放的位置为 /var/lib/awstats目录中但是目录不存在或者不能写入.

[root@localhost ~]# mkdir /var/lib/awstats

现在正常不过没有刷新页面

[root@localhost ~]# cd /usr/local/awstats/wwwroot/cgi-bin/
[root@localhost cgi-bin]# perl  awstats.pl  -update -config=localhost.linux.net
Create/Update database for config "/etc/awstats/awstats.localhost.linux.net.conf" by AWStats version 7.0 (build 1.976)
From data in log file "/usr/local/apache/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: 48
 Found 0 dropped records,
 Found 0 comments,
 Found 0 blank records,
 Found 45 corrupted records,
 Found 0 old records,
 Found 3 new qualified records.

刷新页面

 

对访问的页面进行加密认证,验证访问者的身份

用户名就admin 密码  www.awstats.org (因为是做测试,设置一个简单的密码没有关系)通过htpasswd来设置密码 并修改apache的主配置文件

[root@localhost bin]# /usr/local/apache/bin/htpasswd   /usr/local/apache/apache.passwd admin
New password:
Re-type new password:
Adding password for user admin

修改apche主配置文件的认证类型

<Directory "/usr/local/awstats/wwwroot">
    Options +ExecCGI
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>

在要保护的目录下面建立.htaccess文件,直接建立

[root@localhost bin]# cd /usr/local/awstats/wwwroot/
[root@localhost wwwroot]# vim  .htaccess
[root@localhost wwwroot]# cat  .htaccess
AuthName  "Protect  awstats  date"
#这里可以自定义
Authtype   Basic
#认证文件的类型
AuthUserFile  /usr/local/apache/apache.passwd
#认证用户文件的位置
require  user  admin 
#这个为了安全设置为只允许admin登录,其他用户拒绝,可以设置valid-user

重新启动apache服务

[root@localhost wwwroot]# /usr/local/apache/bin/apachectl restart

重新打开awstats网页

访问下localhost.linux.net 并更新数据库

[root@localhost ~]# bash awstats.sh
Can't open perl script "awstats.pl": No such file or directory
[root@localhost ~]# vim awstats.sh
[root@localhost ~]# cat awstats.sh
perl  /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -config=localhost.linux.net  -update  -output  >/usr/local/awstats/wwwroot/cgi-bin/index.html(刚才这里写错了,更新一下)
 [root@localhost ~]# bash  awstats.sh