一、 AWStats简介 

AWStats是在Sourceforge上发展很快的一个基于Perl的WEB日志分析工具。现今它也可以用来分析多种日志包括:Apache 1.3.x and 2.x, IIS 5.0 and 6.0, WebStar, WebLogic, WebSite, Windows Media Server, Tomcat, Squid, Sambar, Roxen, Resin, RealMedia server, Oracle9iAS, Lotus Notes/Domino, Darwin, IPlanet, IceCast, ZeroBrand, Zeus, Zope, Abyss、proftp、wuftp、vsftp、Postfix, Sendmail, QMail, Mdaemon, www4mail…… HOHO~~够多的了吧。现在就让我来介绍一下,用它来分析vsftp日志的安装配置方法吧。 

二、 安装简介 

1、Awstats的安装CU上有,很详细,下面是两个相关的链接: 
RPM包安装: http://bbs.chinaunix.net/forum/viewtopic.php?t=362206&highlight=awstat 
Tar包安装:http://bbs.chinaunix.net/forum/viewtopic.php?t=120108&highlight=awstat 

2、下面是我的安装过程简介: 
1)AWStats从6.2 版(beta)开始支持wuftp 格式的vsftp日志文件,所以你想要对你的vsftpd日志进行分析,你就只得到http://awstats.sourceforge.net/#DOWNLOAD 下最新的AWStats-6.2的tgz包了,其它的都不支持喔,呵呵。 
2)安装: 
tar –zxvf awstats-6.2.tgz 
cp –r awstats-6.2 /usr/local/awstats 
vi /etc/httpd/conf/httpd.conf #在最后加上下面的几行: 

# Directives to allow use of AWStats as a CGI 

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>; 
service httpd restart #重启apache服务 
cp /usr/local/awstats/wwwroot/cgi-bin/awstats.model.conf /etc/awstats/awstats.bjftp.conf #考贝配置文件 

OK,AWStats的安装已经基本完成了。说明一下上面的安装过程:AWStats是一个用perl写的CGI脚本,它需要Apache或IIS的支持,才能把相应的统计结果用网页的行式显示出来。所以在把awstats-6.2考贝到/usr/local下后,就需要更改apache的配置文件,定义classes、css 、icon、cgi-bin目录的真实路径和/usr/local/awstats/wwwroot目录的属性,然后重启apache服务。如果是新手,也可以执行/usr/local/awstats/tools/ awstats_configure.pl,通过回答几个问题,去自动做这些工作。 

三、设置awstats的配置文件 

这是我主要要向大家介绍的内容。要实现对vsftp的日志的统计,你必须把vsftpd的日志格式改成wuftp格式的,我个人认为vsftpd日志格式十分不适合作日志统计,因为它的每行的列数不都是相同的,这相当不利于日志统计。 
1)要生成wuftp格式的日志,你首先得更改/etc/vsftpd.conf文件,在文件最后回上这么几条: 
xferlog_enable=YES 
xferlog_std_format=YES 
xferlog_file=/var/log/vsftpd.log 
(注:如果有vsftpd_log_file=/XXX/XXX请把它注释掉) 
上面的设置会使生成的wuftp格式的日志存到/var/log/vsftpd.log文件中。当然,你也可以更改xferlog_file=/xxx/xxx来选择其它的目录文件。这样你生成的vsftpd.log日志格式将是下面的样子: 
Sun May 23 08:34:27 2004 67 192.168.13.102 975291 /lastlog a _ o a -anonymous@ ftp 0 * c 
Sun May 23 08:34:28 2004 68 192.168.13.106 975291 /lastlog a _ o a -anonymous@ ftp 0 * c 
Sun May 23 08:34:28 2004 68 192.168.13.102 975291 /lastlog a _ o a -anonymous@ ftp 0 * c 
2)现在我们来配置一个生成vsftpd日志统计的awstats配置文件。 
vi /etc/awstats/awstats.bjftp.conf #把文件中相应的配置设成与下面相同LogFile=”/var/log/vsftplog” #日志文件的路径、名字 
LogType=F #日志文件的类型FTP 
LogFormat=”%time3 %other %host %bytesd %url %other %other %method %other %logname %other %code %other %other” 
#日志文件的格式定义,这点很重要,一定要和你的日志格式一样,在awstats.bjftp.conf文件中有详细的格式定义解释,大家可以看一下。(awstats-6.2以下版本之所以不支持vsftpd日志统计,就是因为它的%time3格式定义与日志的不符) 
LogSeparator=”\s” #日志各列之间用的分隔符 
SiteDomain=”bjftp.xxx.com” #域名、服务器名(一定要定义,在生成awstats数据库时要用到) 
HostAliases=”bjftp.xxx.com bjftp 127.0.0.1 localhost” 
DNSLookup=0 #不逆向解析域名 
DirData=”/home/awstats” #生成的统计数据库的位置(注意,生成的文件可是rw-rw-rw-权限的喔,最好把他改一下。) 
DirCgi=”/awstats” #CGI统计脚本的执行目录,这个和你在apache中的ScriptAlias定义相对应。 
DirIcons=”/awstatsicons” #icons在apache对应目录的定义 
AllowToUpdateStatsFromBrowser=0 #是否可以用浏览器来执行更新,默认是不可以。如果设成1,你就可以在IE中更新统计了。 
NotPageList=”” 
LevelForBrowsersDetection=0 
LevelForOSDetection=0 
LevelForRefererAnalyze=0 
LevelForRobotsDetection=0 
LevelForWormsDetection=0 
LevelForSearchEnginesDetection=0 
ShowLinksOnUrl=0 
ShowMenu=1 
ShowMonthStats=UVHB 
ShowDaysOfMonthStats=HB 
ShowDaysOfWeekStats=HB 
ShowHoursStats=HB 
ShowDomainsStats=HB 
ShowHostsStats=HBL 
ShowAuthenticatedUsers=HBL 
ShowRobotsStats=0 
ShowEMailSenders=0 
ShowEMailReceivers=0 
ShowSessionsStats=1 
ShowPagesStats=PBEX 
ShowFileTypesStats=HB 
ShowFileSizesStats=0 
ShowBrowsersStats=0 
ShowOSStats=0 
ShowOriginStats=0 
ShowKeyphrasesStats=0 
ShowKeywordsStats=0 
ShowMiscStats=0 
ShowHTTPErrorsStats=0 
ShowSMTPErrorsStats=0 

其它的一些我就不一一解释了,可以看一下/etc/awstats/awstats.bjftp.conf文件,里面写得很清楚的。只要把/etc/awstats/awstats.bjftp.conf中的相关先项设成这样,一个vsftp的awstats配置文件已经设定好了。下面要做的就是统计日志了。 

四、生成统计网页 

cd /usr/local/awstats/ wwwroot/cgi-bin 
./awstats.pl -update -config=
bjftp.xxx.com 
(注意:-config=后的参数要和SiteDomain=中定义的相同。最好不要用root去执行这个命令,因为生成的文件是 all can wirte!!!的) 。这样就会在” DirData”定义的目录—/home/awstats下生成一个或多个awstats072004.bjftp.xxx.com.txt、awstats062004.bjftp.xxx.com.txt它们是以日志有月分来分开的,有几个月的日志就会有几个文件。你可以把上面命令加到crontab中,让它定时更新。 
在IE中打入 http:///awstats/awstats.pl?-config=bjftp.xxx.com 就可以看到一张漂亮的日志统计表了。大家可以去http://awstats.sourceforge.net/awstats.ftp.html 看一下一个awstats的FTP日志统计分析结果网页,很不错的。 

五、其它类型日志文件awstats配置方法 

最后,要说的是awstats支持的日志种类很多,从WEB到FTP到MAIL到Media,各种日志都有自己的awstats.xxx.conf的定义,所以大家可以去 http://awstats.sourceforge.net/docs/awstats_faq.html#LOGFORMAT 看一下各种日志的awstats配置文件的定义,还是比较全的,不过E文要过关,呵呵。本人对IIS5、apache1.3*、apache2.*、vsftp日志作了测试统计,都能成功。特别是对apache日志的分析、统计,做得真的是很完美。 

对了还有个问题问大家,有人知道用GeoIP或GeoIPfree的perl模块自定义地区和IP的方法吗?用默认的只能把访问IP的各个国家分出来,不能把国内访问IP的省及市分出来。我已经有IP和省分的对应数据库了,少的就是把它加入perl模块的方法。我想这对日志分析还是很有用的,希望大家帮忙。