系统环境:CentOS6.3
Apache: httpd-2.4.4
配置:
# wget
# tar -zxvf awstats-7.1.1.tar.gz -C /usr/local/
# cd /usr/local/
# mv awstats-7.1.1 awstats
# cd awstats/tools/
# perl awstats_configure.pl
------------------------------
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
What is the name of your web site or profile analysis ?
Example:
Example: demo
Your web site, virtual server or profile name:
>
----------------------
一路默认回车即可完成awstats配置文件向导,该配置文件保存在/etc/awstats/下
注:该配置向导会在apache主配置文件末尾添加几处awstats配置内容,参照本博文配置的同学建议直接删除,以免引起页面无法访问
# vi /etc/awstats/awstats.
修改如下几处配置
-------------
LogFile="/usr/local/apache2/logs/access_log"
#apache若建立分段日志见修改如下
LogFile="/usr/local/apache2/logs/www.abc.com.cn-%YYYY_%MM_%DD.access_log"
LogType=W
LogFormat=1
DirData="/usr/local/apache2/htdocs/www.abc.com.cn/awstats/log" #此处log必须具有写入权限
AllowToUpdateStatsFromBrowser=1
------------
相应的apache分段日志配置:
# vi /usr/local/apache2/conf/httpd.conf
去掉注释#
Include conf/extra/httpd-vhosts.conf
# vi /usr/local/apache2/conf/extra//httpd-vhosts.conf
-------------
<VirtualHost *:80>
DocumentRoot "/usr/local/apache2/htdocs/www.abc.com.cn"
ServerName
CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/www.abc.com.cn-%Y_%m_%d.access_log 86400 480" combined
ErrorLog "|/usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/www.abc.com.cn-%Y_%m_%d.error_log 86400 480"
</VirtualHost>
-------------
创建Web方式查看流量的虚拟目录 ,拷贝显示网页需要的图形工具(icon、css)
# mkdir -p /usr/local/apache2/htdocs/www.abc.com.cn/awstats
# cd /usr/local/apache2/htdocs/www.abc.com.cn/awstats/
# mkdir log/ && chmod -R 777 log
# cd /usr/local/awstats/wwwroot/
cp -R icon /usr/local/apache2/htdocs/www.abc.com.cn/awstats
cp -R css /usr/local/apache2/htdocs/www.abc.com.cn/awstats
添加计划任务脚本及内容,使crond每分钟执行一次脚本文件来刷新awstats web页面:
# vi /etc/rc.d/awstats.sh
-------------
#/bin/bash
PERL=/usr/bin/perl
awstats=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
$PERL $awstats -update -config=www.abc.com.cn
$PERL $awstats -config=www.abc.com.cn -output -staticlinks > /usr/local/apache2/htdocs/www.abc.com.cn/awstats/index.html
-------------
# crontab -e
-------------
* * * * * /bin/sh /etc/rc.d/awstats.sh
-------------
重启计划任务
# service crond restart