Linux 日志分析工具之awstats详解

二、awstats 简介

AWStats is a free powerful and featureful server logfile analyzer that shows you all your Web/Mail/FTP statistics including visits, unique visitors, pages, hits, rush hours, os, browsers, search engines, keywords, robots visits, broken links and more Drag screenshots to sort.

AWStats 软件是一个免费的强大的服务器的日志文件分析工具,显示你所有的网页/邮件/ FTP统计包括访问,访问者,页面,点击,高峰时间,操作系统,浏览器,搜索引擎,关键字,机器人访问,断开的链接和更多的阻力截图排序。

三、awstats 特点

Awstats 是在 SourceForge 上发展很快的一个基于 Perl 的 WEB 日志分析工具,一个充分的日志分析让 Awstats 显示您下列资料:

Awstats 的运行是需要 PERL 环境的支持,从 awstats 的文档来看,它对 Apache HTTP Server 的支持是非常完美的,而当我们把 Web 服务器换成 Nginx 后,要运行 awstats 变得很麻烦。首先 Nginx 本身对 Perl 的支持是比较弱的,甚至官方也不建议使用;另外在日志格式上有需要修改后才能运行。

四、awstats 运行原理

(1).工作原理

AWStats的功能很多,我在此主要用它来分析apache服务器的日志。安装使用之前还是说说大致的工作原理,AWStats提供一系列的perl脚本实现:服务配置,日志读取,报表生成等功能。而功能实现的具体执行过程是:首先,当然是apache将访问情况记录到日志中,AWStats每次执行更新时读取这些日志,分析日志数据,将结果存储到数据库中,(这个数据库是AWStats自带的(就是一文本文件),并不需要第三方软件支持。),最后AWStats提供一个cgi程序通过web页面来显示数据库中所统计的数据。

(2).工作模式

AWStats的工作模式是这样的:

分析日志:运行后将这样的日志统计结果归档到一个AWStats的数据库(纯文本)里;

输出日志:分两种形式

一种是通过cgi程序读取统计结果数据库输出(Linux中);

一种是运行后台脚本将输出导出成静态文件(Windows中);

五、awstats 安装与配置详解

1.环境准备

(1).安装yum源

[root@node6 src]# wget [root@node6 src]# rpm -ivh epel-release-6-8.noarch.rpmwarning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEYPreparing…########################################### [100%]1:epel-release########################################### [100%]

(2).安装cronolog日志切割工具

[root@node6 src]# wget [root@node6 src]# tar xf cronolog-1.6.2.tar.gz[root@node6 src]# cd cronolog-1.6.2[root@node6 cronolog-1.6.2]# ./configure[root@node6 cronolog-1.6.2]# make && make install[root@localhost ~]# which cronolog/usr/local/sbin/cronolog

2.时间同步

[root@node6 src]# yum install -y ntp[root@node6 src]# ntpdate 202.120.2.10128 Dec 17:59:17 ntpdate[1413]: step time server 202.120.2.101 offset -25666.776448 sec

3.安装awstats

(1).yum直接安装

[root@node6 ~]# yum install -y awstats

(2).源码包安装

首先,我们要下载awstats软件包,并将其放在常规目录(/usr/local)下。

[root@node6 src]# wget [root@node6 src]# tar xf awstats-7.2.tar.gz[root@node6 src]# mv awstats-7.2 /usr/local/awstats [root@node6 src]# cd /usr/local/awstats [root@node6 awstats]# ls docs README.TXT tools wwwroot

注,由于wget下载下来的包中权限是非root的,所以这里要修改权限,否则稍后*.pl将无法运行。

[root@node6 awstats]# chown -R root.root /usr/local/awstats [root@node6 awstats]# ll 总用量 20 drwx——. 4 root root 4096 7月 10 04:01 docs -rw——-. 1 root root 6790 7月 10 03:50 README.TXT drwx——. 5 root root 4096 7月 10 04:01 tools drwx——. 7 root root 4096 7月 10 04:01 wwwroot [root@node6 awstats]# chmod +x /usr/local/awstats/tools/*.pl [root@node6 awstats]# cd tools/ [root@node6 tools]# ls awstats_buildstaticpages.pl awstats_exportlib.pl geoip_generator.pl logresolvemerge.pl nginxwebmin awstats_configure.plawstats_updateall.pl httpd_confmaillogconvert.pl urlaliasbuilder.pl xslt [root@node6 tools]# chmod +x /usr/local/awstats/wwwroot/cgi-bin/*.pl [root@node6 tools]# cd .. [root@node6 awstats]# cd wwwroot/cgi-bin/ [root@node6 cgi-bin]# ls awdownloadcsv.pl awredir.pl awstats.model.conf awstats.pl lang lib plugins

(3).接下来,我们要执行/usr/local/awstats/tools下的awstats_configure.pl配置向导,用来生成awstats的配置文件,awstats配置文件的命名规则是awstats.website.conf。

[root@node6 ~]# cd /usr/local/awstats/tools/ [root@node6 tools]# ./awstats_configure.pl此时会出现如下提示,—– AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur —– This tool will help you to configure AWStats to analyze statistics for one web server. You can try to use it to let it do all that is possible in AWStats setup, however following the step by step manual setup documentation (docs/index.html) is often a better idea. Above all if: – You are not an administrator user, – You want to analyze downloaded log files without web server, – You want to analyze mail or ftp log files instead of web log files, – You need to analyze load balanced servers log files, – You want to ‘understand’ all possible ways to use AWStats… Read the AWStats documentation (docs/index.html).—–> Running OS detected: Linux, BSD or Unix—–> Check for web server installEnter 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):> /usr/local/apache2/conf/httpd.conf #这里让你输入apache配置文件的目录,我这里的apache是源码安装的,所以我的路径是/usr/local/apache2/conf/httpd.conf 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/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 #询问是否创建一个新的配置文件,这里填y即可。—–> Define config file name to create What is the name of your web site or profile analysis ? Example: Example: demo Your web site, virtual server or profile name: > #这里让填写你的网站域名,虚拟主机名或者随便一个配置名。—–> Define config file path In which directory do you plan to store your config file(s) ? Default: /etc/awstats Directory path to store config file(s) (Enter for default): > #这里要填写你配置文件存放路径,我们使用它默认的路径/etc/awstats,所以直接回车即可。—–> Create config file ‘/etc/awstats/awstats.’ Config file /etc/awstats/awstats. 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/awstats/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/awstats/tools/awstats_updateall.pl now Press ENTER to continue… #提示不能自动加入crontab定时任务,需要稍后自己添加,我们按回车继续即可。A SIMPLE config file has been created: /etc/awstats/awstats. 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.comPress ENTER to finish… #提示配置文件创建完成和如何更新配置及建立静态报告页,这里我们回车即可结束这个配置向导。[root@node6 tools]# cd /etc/awstats/ [root@node6 awstats]# ls awstats.[root@node6 awstats]# vim awstats. #这个配置文件有很多配置,我们这里只讲解重点配置。LogFile=”/log/www/access_%YYYY-24%MM-24%DD-24.log” #日志文件存放路径,其中%YYYY-24%MM-24%DD是指年月日模式DirData=”/var/lib/awstats” #创建生成的数据路径Lang=”cn” #默认语言中文SkipHosts=”127.0.0.1 REGEX[^192\.168\.]” #本地及内部的访问不做分析统计LevelForWormsDetection=2 #日志等级,不对警告日志进行统计

好了,到这里我们awstats配置文件就修改完成。

会得到最大的满足,因为它填补了你的空虚。

Linux 日志分析工具之awstats详解

相关文章:

你感兴趣的文章:

标签云: