免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1940 | 回复: 2
打印 上一主题 下一主题

[Web] AWStats,强大的日志分析工具 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-19 13:25 |只看该作者 |倒序浏览
AWStats,强大的日志分析工具,本文原址
http://www.syitren.com/bbs/thread-902-1-1.html

AWStats 是一个免费的强大而有个性的工具,带来先进的网络,流量,FTP或邮件服务器统计图. 本日志分析器作为CGI或从命令行在数个图形网页中显示你日志中包含的所有可能信息. 它利用一部分档案资料就能经常很快地处理大量日志档案, 它能分析日志文件来自从各大服务器工具 ,如 Apache日志档案 s (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C的日志格式)及许多其他网站,Proxy(代理服务器)、Wap、流量服务器、邮件服务器和一些 FTP服务器.

首先安装LAMP环境,这里不做介绍,请参考这篇文章!
http://www.syitren.com/bbs/thread-737-1-1.html


1、安装cronolog,日志截取工具
下载地址:http://cronolog.org/
# tar -zxvf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure
# make
# make install

2、安装awstats
下载地址:http://awstats.sourceforge.net/#DOWNLOAD
# tar -zxvf awstats-6.8.tar.gz
# mv awstats-6.8 /usr/local/awstats
# cd /usr/local/awstats/
# ls -l
docs是一些html格式到文档,里面有安装和使用到方法;
README.TXT是软件到介绍和权利申明等;
tools文件夹里面是一些脚本和配置文件,比如批量update的脚本、转换静态html文件的脚本、httpd.conf的配置
文件等;
wwwroot文件夹里面的东西才是最重要的,下面详细介绍:
wwwroot里面又有4个文件夹:awstats、css、js、icon、和classes。
从我的使用情况上看,有用的只有awstats和icon 文件夹。如果你是自己的服务器,自己能控制apache的服务的
配置文件,那么你可以使用tools/awstats_configure.pl脚本来进行安装。你只需要指出httpd.conf的位置即可
# perl tools/awstats_configure.pl
-----> 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'
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
  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.
-----> 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
-----> 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:
> 输入你的域名
然后就一直回车就行了

3、截取apache日志
例:cronolog命令在/usr/sbin/cronolog下,日志文件在/usr/local/apache/logs/下
把CustomLog "logs/access_log" combined
修改为
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache/logs/access_log.%Y%m%d" combined
ErrorLog "|usr/local/apache/logs/error_log.%Y%m%d"
如果有虚拟主机,虚拟主机也要配置,例如:
<virtualHost *:80>
ServerName www.domain.com
CustomLog "|/usr/local/sbin/cronolog /usr/local/apache/logs/access_log.%Y%m%d" combined
ErrorLog "|usr/local/apache/logs/error_log.%Y%m%d"
</VirtualHost>
重启apache
# /usr/local/apache/bin/apachectl restart
创建/var/lib/awstats目录用来存放分析结果,并将所有权给apache用户(apache用户需要有写权限)
# mkdir /var/lib/awstats
# chmod a+w /var/lib/awstats
修改配置文件
# vi /etc/awstats/awstats.你的域名.conf
把LogFile="/var/log/httpd/mylog.log"
修改为
LogFile="/usr/local/apache/logs/access_log.%YYYY%MM%DD"
%YYYY-24 表示24小时之前的年份,%MM-24表示24小时之前的月份,%DD-24表示24小时之前的天,合起来%YYYY-
24%MM-24%DD-24就表示24小时前的年月日。为什么要减去一个24呢,这是因为我们在使用awstats分析apache日志
的时候,必须分析已经生成的日志。而我们又常常使用cron来自动update,举个例子,当我们于 2007年5月1日凌
晨1点分析我们网站的apahce日志的时候,我们是要分析前一天也就是2007年4月30日的日志,而不是cron运行的
当天5月 1日的日志,这样,减去一个数字,才能够正确得到我们想要分析的apche的日志的文件名。当然,你也可
以不用24这个数字,可以根据自己的实际情况来调整.
AllowToUpdateStatsFromBrowser=1
主页上有手动“立即更新”按钮,默认为0,不出现
4、安装国家和城市插件
分别下载插件程序:
GeoIP:http://www.maxmind.com/download/geoip/api/c/
http://www.maxmind.com/download/geoip/api/perl/
GeoIP安装:
先下载C库:GeoIP C解包后
# tar -zxvf GeoIP-1.4.5.tar.gz
# cd GeoIP-1.4.5
# ./configure
# make
# make install
然后下载Perl库:GeoIP Perl解包后
# tar -zxvf Geo-IP-1.36.tar.gz
# cd Geo-IP-1.36
# perl MakeFile.PL
# make
# make install

再下载GeoIP/GeoIPCityLite两个信息数据包:
http://www.maxmind.com/download/geoip/database/
http://geolite.maxmind.com/downl ... ase/GeoLiteCountry/
# gzip -d GeoLiteCity.dat.gz
# cp GeoLiteCity.dat /etc/awstats/
# gzip -d GeoIP.gz
# cp GeoIP /etc/awstats/
#vi /etc/awstats/awstats.你的域名.conf
修改其中的一些配置选项为:
LoadPlugin="decodeutfkeys"  
LoadPlugin="geoip GEOIP_STANDARD /etc/awstats/GeoIP"     
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /etc/awstats/GeoLiteCity.dat"
如果出现无法调用.so文件或者其他共享文件错误
编辑/etc/ld.so.conf,在其中加入一行
/usr/local/lib
之后再执行
/sbin/ldconfig /etc/ld.so.conf

论坛徽章:
0
2 [报告]
发表于 2009-04-19 13:26 |只看该作者
AWStats,强大的日志分析工具
AWStats,强大的日志分析工具,本文原址
http://www.syitren.com/bbs/thread-902-1-1.html

5、启动awstats
手动生成日志分析文件
#/usr/local/awstats/tools/awstats_updateall.pl now
自动生成日志分析文件
在crond加入
#crontab -e
添加:
*/5 * * * * root /usr/local/awstats/tools/awstats_updateall.pl now
(每5分钟更新日志分析文件)

通过web查看日志
http://你的域名/awstats/awstats.pl?config=你的域名

6、为日志设置密码
<Files "awstats.pl">
    AuthType Basic
    AuthName "awstat access"
    AuthUserFile "/etc/awstats/htpasswd"
    Require valid-user
</Files>
注意:Basic方式密码是用过明文传输,如果想通过加密的方式传输密码,请用Digest方式。
# /usr/local/apache/bin/htpasswd -c /etc/awstats/htpasswd admin
连续两次输入密码,
这样就生成了用户名和密码,下次在访问的时候就需要输入密码了。
注意:如果增加一个用户不要加-c参数
7、安装qqhostinfo插件
awstats是可以增加插件的。爱.EASY.RELOADED做的这个qqhostinfo插件,可以在访问主机表格中增加一列,显示ip对应的位置。当然这个资料来源于著名的QQWry.Dat文件。
插件代码:下载并复制到 awstats/plugins/目录下:
http://www.ieasy.org/download/qqhostinfo.pm
http://www.ieasy.org/download/qqwry.pl
本地下载此文件包
(1)首先下载插件(qqhostinfo.pm)。把它放在awstats/wwwroot/cgi-bin/plugins中。
(2)下载分析QQWry.dat的perl脚本(qqwry.pl)。放在同一目录。
# vi qqhostinfo.pm
只修改这个地方就能够了:
require "/opt/apache/cgi-bin/awstats/plugins/qqwry.pl"; "该目录根据自己情况修改"
# vi qqwry.pl
my $ipfile="/opt/apache/cgi-bin/awstats/QQWry.Dat"; "QQWry.Dat 根据自己情况指定"
(3)去网上下载QQWry.Dat放在同一目录中(http://www.cz88.net/fox/),注意文件名一定要是QQWry.Dat
(4)编辑你得awstats配置文件,大概o"的后面增加一行
LoadPlugin="qqhostinfo"
8、安装hostinfo插件
将LoadPlugin="hostinfo" 之前的注释去掉,保存退出。
再次运行Awstats 报错,提示在已有路径中找不到Net::XWhois 模块,
没有找到包含这个模块的程序包,可以到这个网站查找模块http://search.cpan.org
perl-Net-XWhois
# tar -zxvf Net-XWhois-0.90.tar.gz
# cd Net-XWhois-0.90
# perl Makefile.PL
# make
# make install
通过这个插件得到的查询结果,与使用以下命令得到的内容相同:
# whois 202.108.130.138
9、打开标题提示:
# vi /etc/awstats/awstats.你的域名.conf
LoadPlugin="tooltips"

论坛徽章:
0
3 [报告]
发表于 2009-04-19 18:50 |只看该作者

回复 #1 linjingmin 的帖子

这个还是很有用途的工具
长期分析日志也是进一步进行优化的基础
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP