ChinaUnix首页 > 精华文章 > FTP服务器 > 正文

[原创] 原创:用AWStats对VSFTP日志进行统计


http://www.chinaunix.net 作者:eagerlinuxer  发表于:2005-02-22 10:06:42
发表评论】 【查看原文】 【FTP服务器讨论区】【关闭

(放linux版里没人看,所以放FTP版里试试,呵呵)
一、 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模块的方法。我想这对日志分析还是很有用的,希望大家帮忙。



 seacaptain 回复于:2004-08-16 18:22:18

支持。
收藏


 hrcxf 回复于:2004-08-19 09:31:02

好啊!
支持!


 dongdonga 回复于:2004-08-19 13:04:53

收藏,谢谢!


 z33 回复于:2004-09-07 11:19:18

有用,先收了,谢谢!


 chfzoe 回复于:2004-10-25 19:07:17

您好
我依照你的文章做,可是仍然無法使用
我是用redhat 9 
vsftp-1.1.3-8
awstats-6.2


當我執行 ./awstats.pl以下的執行結果是否正確
-------------------------------------------------------------
[root@localhost cgi-bin]# ./awstats.pl -update -config=bjftp.xxx.com
Update for config "/etc/awstats/awstats.bjftp.xxx.com.conf"
With data in log file "/var/log/vsftpd.log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 335)
Jumped lines in file: 335
 Found 335 already parsed records.
Parsed lines in file: 0
 Found 0 dropped records,
 Found 0 corrupted records,
 Found 0 old records,
 Found 0 new qualified records.
-------------------------------------------

還有當我在網址列上打上
"http:///awstats/awstats.pl?-config=bjftp.xxx.com"
它會連結到"www.awstats.com"

如果可以請跟我連絡
justcafe.tw@yahoo.com.tw


 eagerlinuxer 回复于:2004-10-26 13:25:39

呵呵,谢谢大家支持。
你的日志格式好象有问题,能不能贴出来看一下。


 cyrus 回复于:2004-11-06 22:35:48

引用:原帖由 "chfzoe"]alhost cgi-bin 发表:
# ./awstats.pl -update -config=bjftp.xxx.com
Update for config "/etc/awstats/awstats.bjftp.xxx.com.conf"
With data in log file "/var/log/vsftpd.log"...
Phase 1 : First bypass old rec..........


ft..
SiteDomain="bjftp.xxx.com” #域名、服务器名(一定要定义,在生成awstats数据库时要用到) 
HostAliases="bjftp.xxx.com bjftp 127.0.0.1 localhost" 
这个你没看全 这个要和你自己的主机域名相符合


 cyrus 回复于:2004-11-07 02:29:44

很感谢楼主的开拓精神,发点自己的使用经验对你支持

1,一定要把域名写到配置文件里面
这个在awstats.model.conf的配置行里面添加,如果是ip的话,可以参照以下格式
eg:ip=192.168.0.1
那么必须添加两行
SiteDomain="192.168.0.1"
HostAliases="192.168.0.1 www.192.168.0.1 127.0.0.1 localhost"
至于为什么这样填写,没仔细研究,
不过如果要通过例子理解的话,可以在
tools/awstats_configure.pl
用一个ip或者域名对一个apache.log分析

2,文件夹和文件的可读权限
配置过程中一般提示可读权限的地方集中在
DirData="/home/awstats"#自定义分析分析数据文件夹
LogFile="/var/log/vsftpd.log"#vsftp的日志文件
这两个我一般设置为770 毕竟是用一般系统用户执行的命令

3,主要配置参数 如果以上几点都做好了 那么应该考虑这些配置
LogType=F
LogFormat="%time3 %other %host %bytesd %url %other %other %method %other %logname %
other %code %other %other"
LogSeparator="\s"

4 其他参数的功能还没发掘,不过一个从http://awstats.sourceforge.net/docs/awstats_faq.html#SERVERSOS找到的一个ftp配置例子已经能解决很多问题,当然,关键参数要加上,不过这个程序会提示出错的地方,自己看手册和FAQ拉,希望大家的英语ok:)

good luck


 DreamJiang 回复于:2004-11-08 15:06:32

我在利用Awstat為vsftpd生成統計網頁時,在相應的目錄下執行./awstats -update -config=linuxtest.abc.com時,出現與上樓兄弟一樣的錯誤提示,不知上樓的兄弟是如何解決的?請多指點,多謝!!!


 eagerlinuxer 回复于:2004-11-08 17:56:59

呵呵,你用的是vsftpd的日志格式,要用wuftp的日志格式:          

Sun May 23 08:34:27 2004 67 192.168.13.102 975291 /lastlog a _ o a -anonymous@ ftp 0 * c 

你必须在vsftpd.conf中做以下设置:

xferlog_enable=YES 
xferlog_std_format=YES 
xferlog_file=/var/log/vsftpd.log 
(注:如果有vsftpd_log_file=/XXX/XXX请把它注释掉) 


如果你用的vsftpd的版本在1.2以下,即使在vsftpd.conf中做了以上的设置,也可能生成不了这种格式的日志文件。


 eagerlinuxer 回复于:2004-11-08 18:21:52

引用:原帖由 "cyrus" 发表:
很感谢楼主的开拓精神,发点自己的使用经验对你支持

1,一定要把域名写到配置文件里面
这个在awstats.model.conf的配置行里面添加,如果是ip的话,可以参照以下格式
eg:ip=192.168.0.1
那么必须添加两行
Site..........



感谢cyrus的补充,这些我的确没有写完整  :oops: 
希望大家一起来补充这个文档。包括用GeoIP来定义不同的省市,这样我们就可以知道什么地方的用户使用你的ftp最多了  :em02:


 DreamJiang 回复于:2004-11-12 18:02:04

我己經利用./awstats.pl -update -config=linuxtest.abc.com生成了awstats.linuxtest.abc.com.conf文件,但是利用ie時,輸入http://linuxtest.abc.com/awstats/awstats.pl?-config=linuxtest.abc.com時,卻出現“下載awstats.pl文件的對話框”,卻不能顯示頁面。如果輸入http://linuxtest.abc.com/awstats時卻出現:
Forbidden
You don't have permission to access /awstats/ on this server.


--------------------------------------------------------------------------------

Apache/1.3.23 Server at linuxtest.abc.com Port 80

此時在/var/log/httpd/error_log文件中有如下信息:
[Fri Nov 12 15:57:59 2004] [error] [client 192.168.60.87] Directory index forbidden by rule: /usr/local/awstats/wwwroot/cgi-bin/

不知是為什麼?請大家多指點,多謝了!!!


 jackieyuan 回复于:2004-11-20 18:39:12

这篇文章可以被评选Top100了!! 强烈支持! :em09:  :em16:


 jackieyuan 回复于:2004-11-20 18:42:03

引用:原帖由 "eagerlinuxer" 发表:
(放linux版里没人看,所以放FTP版里试试,呵呵)
一、 AWStats简介 

AWStats是在Sourceforge上发展很快的一个基于Perl的WEB日志分析工具。现今它也可以用来分析多种日志包括:Apache 1.3.x and 2.x, IIS 5.0 an..........



一个我的例子,不知道对你有没有帮助。
http://linux.dalouis.com/awstats/awstats.pl?config=hzmjpbbs

另外作一点补充。如果你的 vsftpd 使用的是 virtual username 的话,要把
红色部分去掉。
引用:LogFormat="%time3 %other %host %bytesd %url %other %other %method %other[color=red] %logname [/color]%other %code %other %other" 


同时要重新编译 vsftpd 包里面的 loggin.c 文件

找到


  /* Access mode: anonymous/real user, and identity */
  if (p_sess->;is_anonymous)
  {
    str_append_text(p_str, "a ");
    str_append_str(p_str, &p_sess->;anon_pass_str);
  }
  else
  {
    str_append_text(p_str, "r ");
    str_append_str(p_str, &p_sess->;user_str);
  }
/*  str_append_char(p_str, ' ');  # --Edit by Kreny
  /* Service name, authentication method, authentication user id */
  str_append_text(p_str, "ftp 0 * ");
  /* Completion status */
  if (succeeded)
  {
    str_append_char(p_str, 'c');
  }
  else
  {
    str_append_char(p_str, 'i');
  }
}


其中 这一行是我修改的。原本会添加一个空格,现在把这个空格去掉就ok了。
/*  str_append_char(p_str, ' ');  # --Edit by Kreny

当然,如果要保留上面的 $logname 的话,在这个空格里面添加一个自己喜欢的名字也可以。

以下就是编译前和编译后的log的区别。
-->; "a" 和 "ftp" 之间有两个空格
Sat Nov 20 21:52:54 2004 806 220.112.93.119 43780 /download/file.rar b _ o a  ftp 0 * i


-->; "a" 和 "ftp" 之间只有一个空格
Sat Nov 20 21:54:37 2004 3 220.112.93.119  48180 /download/file.rar b _ o a ftp 0 * i



 klark 回复于:2004-11-20 21:56:25

可以支持solaris8吗?

而且我在httpd.conf中没找到CustomLog logs/access_log common 
只有
#    CustomLog logs/dummy-host.example.com-access_log common

如何更改?


 deng805 回复于:2005-01-03 16:35:26

我是参考楼主和它官站上的
With ProFTPd:

1- Setup your server log file format:

Modify the proftpd.conf file to add the following two lines : LogFormat awstats "%t %h %u %m %f %s %b"     # WARNING: You must use a tab char between % tags and not a space ! 
ExtendedLog /var/log/xferlog read,write awstats     # WARNING: ExtendedLog directive might need to be placed inside a virtual host context if you use them.  
Then turn off old format Transfer log: TransferLog none     # WARNING: TransferLog directive might need to be placed inside a virtual host context if you use them.  

To have the change effective, stop your server, remove old log file /var/log/xferlog and restart the server.
Download a file by FTP and check that your new log file looks like this:
[01/Jan/2001:21:49:57 +0200] ftp.server.com user RETR /home/fileiget.txt 226 1499

2- Then setup AWStats to analyze the FTP log file:

Copy config file "awstats.model.conf" to "awstats.ftp.conf".
Modify this new config file: LogFile="/var/log/xferlog" 
LogType=F 
LogFormat="%time1 %host %logname %method %url %code %bytesd" 
LogSeparator="\t" 
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  




运行那个命令是,错误如下图(远程管理不会复制就截了个图):


 good_bad_boy 回复于:2005-02-22 10:06:42

楼主,我给你发过邮件,可是地址不存在,想问你现在通过IP地址显示国内省市的插件搞定了吗?俺也很想要这个,不知还能不能看到这个留言了。
盼复




原文链接:http://bbs.chinaunix.net/viewthread.php?tid=388056
转载请注明作者名及原文出处