安装日志分析工具awstats
AWStats是在Sourceforge上发展很快的一个基于Perl的WEB日志分析工具。相对于另外一个非常优秀的开放源代码的日志分析工具Webalizer,AWStats的优势在于:1.界面友好:可以根据浏览器直接调用相应语言界面(有简体中文版)
2.基于Perl:并且很好的解决了跨平台问题,系统本身可以运行在GNU/Linux上或 Windows上(安装了ActivePerl后);分析的日志直接支持Apache格式(combined)和IIS格式(需要修改)。Webalizer虽然也有Windows平台版,但目前已经缺乏维护;AWStats完全可以实现用一套系统完成对自身站点不同WEB服务器:GNU/Linux/Apache和Windows/IIS服务器的统一统 计。
3.效率比较高:AWStats输出统计项目比Webalizer丰富了很多,速度仍可以达到Webalizer的1/3左右,对于一个日访问量 百万级的站点,这个速度都是足够的;
4.配置/定制方便:系统提供了足够灵活但缺省也很合理的配置规则,需要修改的缺省配置不超过3,4项就可以开始运行,而且修改和扩展的插件还是 比较多的;
5.AWStats的设计者是面向精确的"Human visits"设计的,因此很多搜索引擎的机器人访问都被过滤掉了,因此有可能比其他日志统计工具统计的数字要低,来自公司内部的访问也可以通过IP过滤 设置过滤掉。
6.提供了很多扩展的参数统计功能:使用ExtraXXXX系列配置生成针对具体应用的参数分析会对产品分析非常有用。
AWStats是一个免费的强大而有个性的工具,带来先进的网络,流量,FTP或邮件服务器统计图.本日志分析器作为CGI或从命令行在数个图形网页中显示你日志中包含的所有可能信息. 它利用一部分档案资料就能经常很快地处理大量日志档案,它能分析日志文件来自从各大服务器工具 ,如 Apache日志档案 s (NCSA combined/XLF/ELF log format orcommon/CLF log format), WebStar, IIS(W3C的日志格式)及许多其他网站,Proxy(代理服务器)、Wap、流量服务器、邮件服务器和一些 FTP服务器 .
一.安装
[*]cd /usr/ports/www/awstats
[*]make install clean
二、配置
安装后,会产生一个 /usr/local/www/awstats目录,然后执行tools目录中的 awstats_configure.pl 配置向导,创建一个新的统计。
[*]www# cd /usr/local/www/awstats/tools
[*]www# ./awstats_configure.pl
系统会提示:
[*]-----> Check for web server install
[*]
[*]Enter full config file path of your Web server.
[*]Example: /etc/httpd/httpd.conf
[*]Example: /usr/local/apache2/conf/httpd.conf
[*]Example: c:\Program files\apache group\apache\conf\httpd.conf
[*]Config file path ('none' to skip web server setup):
[*]#>
#因为我们这里用的是Nginx,所以写 none,跳过。
[*]Your web server config file(s) could not be found.
[*]You will need to setup your web server manually to declare AWStats
[*]script as a CGI, if you want to build reports dynamically.
[*]See AWStats setup documentation (file docs/index.html)
[*]
[*]-----> Update model config file '/usr/local/awstats/www/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,创建一个新的统计配置
[*]-----> 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:
[*]#>
输入您需要统计的域名,例如:www.test.com,回车:
[*]-----> Create config file '/etc/awstats awstats.www.mytest.com.conf'
[*]Config file /etc/awstats/awstats.www.test.com.conf created.
[*]
[*]-----> Add update process inside a scheduler
[*]Sorry, configure.pl does not support automatic add to cron yet.
[*]You can do it manually by adding the following command to your cron:
[*]/usr/local/wwwroot/cgi-bin/awstats.pl -update -config=www.test.com
[*]
[*]Or if you have several config files and prefer having only one command:
[*]
[*]/usr/local/tools/awstats_updateall.pl now
[*]
[*]Press ENTER to continue...
回车,继续……
[*]A SIMPLE config file has been created: /etc/awstats/awstats.www.test.com.conf
[*]
[*]You should have a look inside to check and change manually main parameters.
[*]
[*]You can then manually update your statistics for 'www.test.com' with command:
[*]
[*]> perl awstats.pl -update -config=www.test.com
[*]
[*]You can also build static report pages for 'www.test.com' with command:
[*]> perl awstats.pl -output=pagetype -config=www.test.com
[*]
[*]Press ENTER to finish...
回车完成!
三、编辑配置文件
[*]#ee /etc/awstats/awstats.www.test.com.conf
修改LogFile="/var/log/httpd/mylog.log" 为nginx web的日志文件
这里,我后面要使用每天定时任务,所以需要设置动态的目录和动态的文件,参考自带的说明文档,设置如下:
[*]LogFile="/var/log/nginx/%YYYY-0%MM-0/test.access_%YYYY-0%MM-0%DD-1.log"
意思是从nginx下的一个年月文件,例如201205中读取如test.access_20120514.log的文件,这里有个DD-1,是当前时间减去1小时的日期,比如自动任务执行时间为2012年5月15日00:10,那么实际上设置为DD-1,就可以找到文件名为20120514.log这个文件。
修改DirData="/var/lib/awstats" 为一个可工作的web目录。
四、测试
[*]# /usr/local/www/awstats/cgi-bin/awstats.pl -update -config=www.test.com
显示结果:
[*]Create/Update database for config "/etc/awstats/awstats.www.test.com.conf" by AWStats version 7.0 (build 1.971)
[*]From data in log file "/var/log/nginx/www.test.access.log"...
[*]Phase 1 : First bypass old records, searching new record...
[*]Direct access after last parsed record (after line 36861)
[*]Jumped lines in file: 36861
[*] Found 36861 already parsed records.
[*]Parsed lines in file: 2889
[*] Found 0 dropped records,
[*] Found 0 comments,
[*] Found 0 blank records,
[*] Found 0 corrupted records,
[*] Found 0 old records,
[*] Found 2889 new qualified records.
五、查看结果
在 Apache 上,可以直接打开 Perl 程序的网页查看统计。 但Nginx 对 Perl 支持并不好,所以我们要换个方法,利用 awstats 的工具将统计的结果生成静态文件,具体的步骤如下:
首先在 /www/www.test.com 目录下创建一个文件夹z。例:/data/www.test.com/z
然后让 Awstats 把静态页面生成到该目录中
# /usr/local/www/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn -dir=/data/www.test.com/z -awstatsprog=/usr/local/www/cgi-bin/awstats.pl执行上面的命令后,在最后会提示一行信息,如:Main HTML page is 'awstats.www.test.com.html'.
这个时候,可以通过路径http://www.test.com/z/awstats.www.test.com.html查看生成的结果。
六、计划任务
上面的测试都通过之后,可以设置crontab,让awstats每天进行一次,对每天00点切好的前一天的日志进行分析,生成报表,awstats会自动将前一天的数据update到统计报表中。
添加计划任务:cd /var/cron/tabs/
ee root 注:我是用root执行的;
加入:
[*]01 00 * * * /bin/sh /usr/local/www/nginx/sbin/cut_nginx_log.sh #将nginx日志进行切分;
[*]10 00 * * * /usr/local/www/awstats/cgi-bin/awstats.pl -update -config=www.test.com #更新分析数据;
[*]15 00 * * * /usr/local/www/awstats/tools/awstats_buildstaticpages.pl -update -config=www.test.com -lang=cn8 -dir=/www/awstats/log -awstatsprog=/usr/local/www/cgi-bin/awstats.pl
我用的语言为cn8,是为了避免显示乱码,我将awstats下的cn的语言包转码了。(我的默认语言设置的是utf-8,awstats默认的cn语言为gbk)
走自己的路,让别人打车去吧。 长大了娶唐僧做老公,能玩就玩一玩,不能玩就把他吃掉。 微机原理闹危机,随机过程随机过,实变函数学十遍,汇编语言不会编! 长大了娶唐僧做老公,能玩就玩一玩,不能玩就把他吃掉。 生活***好玩,因为生活老***玩我!
页:
[1]