最近一直在研究awstats动态页面,主要想解决生成的日志页面点击二级链接报错问题,期间想下狠心给apache装perl模块,但是悲剧的是mod_perl最新版本不支持apache2.4版本,而本人公司线上服务器就是该版本,苦思冥想研究了几天,终于google到了一篇能够生成二级链接静态页面的awstats脚本的文档。
研究完毕并线上测试成功,这里刚好在之前的基础上修改后分享给大家,也算是不用在apache装perl模块的一种补救方案,效果还不错。
系统环境:centOS6.3
Apache: httpd-2.4.4
配置:
# wget http://sourceforge.net/projects/awstats/files/AWStats/7.1.1/awstats-7.1.1.tar.gz/download
# 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: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.abc.com.cn
----------------------
一路默认回车即可完成awstats配置文件向导,该配置文件保存在/etc/awstats/下
注:该配置向导会在apache主配置文件末尾添加几处awstats配置内容,参照本博文配置的同学建议直接删除,以免引起页面无法访问
# vi /etc/awstats/awstats.www.abc.com.cn.conf
修改如下几处配置
-------------
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
#此处log目录必须具有写入权限
DirData="/usr/local/apache2/htdocs/www.abc.com.cn/awstats/log"
AllowToUpdateStatsFromBrowser=1
#显示简体中文页面
Lang="cn"
------------
相应的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 www.abc.com.cn
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方式查看流量的虚拟目录 www.abc.com.cn ,拷贝显示网页需要的图形工具(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
# cp -R classes /usr/local/apache2/htdocs/www.abc.com.cn/awstats
# cp -R js /usr/local/apache2/htdocs/www.abc.com.cn/awstats
# cd /usr/local/apache2/htdocs/www.abc.com.cn/awstats/
# chmod -R 755 icon css classes js
添加计划任务脚本及内容,使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
-------------
版本二(生成多级链接日志分析,推荐)
---------------
#/bin/bash
########################################
PERL=/usr/bin/perl
awstats=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
hostdir=/usr/local/apache2/htdocs/www.abc.com.cn/awstats
buildstaticpages=/usr/local/awstats/tools/awstats_buildstaticpages.pl
########################################
$buildstaticpages -update -config=www.abc.com.cn -lang=cn -dir=$hostdir -awstatsprog=$awstats
---------------
加入系统计划任务
# crontab -e
-------------
* * * * * /bin/sh /etc/rc.d/awstats.sh
-------------
awstats默认主页为awstats.www.abc.com.cn.html,方便web登录的话可以加一个index.html的软链接
# sh /etc/rc.d/awstats.sh
# cd /usr/local/apache2/htdocs/www.abc.com.cn/awstats
# ln -s awstats.www.abc.com.cn.html index.html
重启计划任务
# service crond restart
添加apache目录访问认证功能
# mkdir /usr/local/apache2/passwd/
# touch /usr/local/apache2/passwd/passwords
加密认证目录
# /usr/local/apache2/bin/htpasswd -cb /usr/local/apache2/passwd/passwords awstats 123456
返回错误提示
-------------
/usr/local/apache2/bin/httpd: error while loading shared libraries: libexpat.so.0: cannot open shared object file: No such file or directory
-------------
使用ldd查看httpd的依赖库信息
# ldd httpd
linux-vdso.so.1 => (0x00007ffffcdff000)
libpcre.so.1 => /usr/local/pcre/lib/libpcre.so.1 (0x00007fa43177b000)
libaprutil-1.so.0 => /usr/lib64/libaprutil-1.so.0 (0x00007fa431543000)
libexpat.so.0 => not found
libapr-1.so.0 => /usr/lib64/libapr-1.so.0 (0x00007fa4310f0000)
librt.so.1 => /lib64/librt.so.1 (0x0000003665c00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003671c00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003665000000)
libc.so.6 => /lib64/libc.so.6 (0x0000003664c00000)
libuuid.so.1 => /lib64/libuuid.so.1 (0x000000366c400000)
libexpat.so.1 => /lib64/libexpat.so.1 (0x0000003669000000)
libdb-4.7.so => /lib64/libdb-4.7.so (0x0000003667800000)
/lib64/ld-linux-x86-64.so.2 (0x0000003664400000)
libfreebl3.so => /lib64/libfreebl3.so (0x0000003672400000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003664800000)
查找该库文件
# find / -name libexpat.so.0
返回 /usr/local/apache2/lib/libexpat.so.0
复制该库文件到apache默认库路径
# cp /usr/local/apache2/lib/libexpat.so.0 /usr/lib64/
重新查看依赖库
# ldd httpd
linux-vdso.so.1 => (0x00007ffffcdff000)
libpcre.so.1 => /usr/local/pcre/lib/libpcre.so.1 (0x00007fa43177b000)
libaprutil-1.so.0 => /usr/lib64/libaprutil-1.so.0 (0x00007fa431543000)
libexpat.so.0 => /usr/lib64/libexpat.so.0 (0x00007fa43131c000)
libapr-1.so.0 => /usr/lib64/libapr-1.so.0 (0x00007fa4310f0000)
librt.so.1 => /lib64/librt.so.1 (0x0000003665c00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003671c00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003665000000)
libc.so.6 => /lib64/libc.so.6 (0x0000003664c00000)
libuuid.so.1 => /lib64/libuuid.so.1 (0x000000366c400000)
libexpat.so.1 => /lib64/libexpat.so.1 (0x0000003669000000)
libdb-4.7.so => /lib64/libdb-4.7.so (0x0000003667800000)
/lib64/ld-linux-x86-64.so.2 (0x0000003664400000)
libfreebl3.so => /lib64/libfreebl3.so (0x0000003672400000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003664800000)
重新加密认证目录
# /usr/local/apache2/bin/htpasswd -cb /usr/local/apache2/passwd/passwords awstats 123456
注:此处若不加b参数,自行暗文添加认证密码,在访问认证页面后会无法通过,起初以为自己是不是输入密码的时候手误,google查了下,老外的意思说是apache2.4.4版本的BUG,解决办法只能换apache版本,或者加b参数直接明文添加密码,非2.4.4版本的apache可以无视。
# vi /usr/local/apache2/conf/httpd.conf
末尾添加:
注:添加Alias链接,防止awstats页面暴图:
-----------------
Alias /awstatscss " /usr/local/apache2/htdocs/www.abc.com.cn/awstats/css/"
Alias /awstatsicons " /usr/local/apache2/htdocs/www.abc.com.cn/awstats/icon/"
Alias /awstatsclasses "/usr/local/apache2/htdocs/www.abc.com.cn/awstats/classes/"
<Directory "/usr/local/apache2/htdocs/www.abc.com.cn/awstats/">
AuthType Basic
AuthName "Awstats"
AuthUserFile /usr/local/apache2/passwd/passwords
Require user awstats
</Directory>
-----------------
重启apache
# /usr/local/apache2/bin/apachectl restart
Web查看awstats流量监控.
注:windows访问需修改主机Hosts文件
浏览器地址栏输入http://www.abc.com.cn/awstats