[原创]使用apache日志分析软件webalizer来分析日志

webalizer

日志分析利器-webalizer

日志统计分析程序webalizer的安装和配置
webalizer是一个高效的、免费的web服务器日志分析程序。其分析结果是HTML文件格式,
从而可以很方便的通过web服务器进行浏览。Internet上的很多站点都使用webalizer进行web服务器日志分析。
Webalizer具有以下一些特性(直接复制官方站点的说明,请自行谷歌或者百度.呵呵):
Is written in C to be extremely fast and highly portable. On my 1.6Ghz laptop, it can process close to 70,000 records per second, which means a log file with roughly 2 million hits can be analyzed in about 30 seconds.

Handles standard Common logfile format (CLF) server logs, several variations of the NCSA Combined logfile format, wu-ftpd/proftpd xferlog (FTP) format logs, Squid proxy server native format, and W3C Extended log formats. In addition, gzip (.gz) and bzip2 (.bz2) compressed logs may be used directly without the need for uncompressing.

Generated reports can be configured from the command line, or more commonly, by the use of one or more configuration files. Detailed information on configuration options can be found in the README file, supplied with all distributions.

Supports multiple languages. Currently, Albanian, Arabic, Catalan, Chinese (traditional and simplified), Croatian, Czech, Danish, Dutch, English, Estonian, Finnish, French, Galician, German, Greek, Hungarian, Icelandic, Indonesian, Italian, Japanese, Korean, Latvian, Lithuanian, Malay, Norwegian, Polish, Portuguese (Portugal and Brazil), Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, Thai, Turkish and Ukrainian are available.

Unlimited log file sizes and partial logs are supported, allowing logs to be rotated as often as needed, and eliminating the need to keep huge monthly files on the system.

Fully supports IPv4 and IPv6 addresses. Includes built-in distributed DNS lookup capability and native Geolocation services.

Distributed under the GNU General Public License, complete source code is available, as well as binary distributions for some of the more popular platforms. Please read the Copyright notices for additional information
webalizer的官方站点: www.webalizer.org
它是用C语言写的程序,所以其具有很高的运行效率。在主频为1.6GHz的机器上,webalizer每秒钟可以分析70000条记录,所以分析一个200万点击率的站点的日志文件只需要30秒.

webalizer支持标准的一般日志文件格式(Common Logfile Format);除此之外,也支持几种组合日志格式(Combined Logfile Format)的变种,从而可以统计客户情况以及客户操作系统类型。并且现在webalizer已经可以支持wu-ftpd xferlog日志格式以及squid日志文件格式了。[*] 支持命令行配置以及配置文件。[*]可以支持多种语言,也可以自己进行本地化工作。
支持多种平台,比如UNIX、linux、NT, OS/2 和MacOS等。
我就简单的翻译这些, 大家有兴趣了解的可以访问官方站点看它的feature.
另外,webalizer生成的访问统计分析报表的内容包含每个月的平均访问量的表格和条形图统计分析情况。点击每个月分,可以得到这个月每天的详细统计信息。

1.安装
在安装以前首先需要确保系统已经安装有gd库,可以使用:
[root@yoyojacky root]# rpm -qa|grep gd
gd-devel-1.8.4-4
gdbm-devel-1.8.0-14
gdbm-1.8.0-14
sysklogd-1.4.1-8
gd-1.8.4-4
来确认系统已经安装有gd-deve和gd两个rpm包。
安装webalizer有两种方式,一种是下载源代码来安装,一种是直接使用rpm包来安装。使用rpm包方式安装非常简单,从rpmfind.net找到webalizer包,下载以后:
rpm –ivh webalizer-2.01_10-1.i386.rpm
即可实现安装。
对于源代码方式首先需要从http://www.mrunix.net/webalizer/下载,然后安装,首先解开源代码包:
#tar xvzf webalizer-2.01-10-src.tgz
在生成的目录中有个lang目录,该目录中保存了各种语言文件,但是只有繁体中文版本,可以自己转换成简体,或者自己重新翻译一下。然后进入生成的目录:
cd webalizer-2.01-10
./configure
make –with-language=Chinese
make install
编译成功后,会在/usr/local/bin/目录下安装一个webalizer可执行文件。
2 配置和运行对webalizer运行的控制可以通过配置文件或者在命令行指定参数的两种方
式进行。而使用配置文件方式是比较简单和灵活的,适用于自动web服务器日志统计分析的应用环境。
webalizer的默认配置文件为/etc/webalizer.conf,当启动Webalizer时没有使用“-f“选项时,Webalizer就会寻找文件/etc/webalizer.conf,也可以使用“-f”来指定配置文件(当服务器有虚拟主机时,就需要配置多份不同的webalizer配置文件,不同的虚拟主机的webalizer使用不同的配置文件。

Webalizer.conf配置文件中需要修改的配置选项如下:
LogFile /var/logs/httpd/access_log
用来指示配置文件的路径信息,webalizer会将该日志文件作为输入进行统计分析;

OutputDir /var/www/html/bizsmooth/usage
用来指示生成的统计报表的保存目录,在前面我们使用alias,使得用户可以使用

http://www.bizsmooth.org/bizsmooth/usage/来访问统计报表。

HostName http://www.bizsmooth.org
用来指示主机名,统计报表中会引用该主机名。

其他选项就无需修改,配置文件修改完毕以后,就需要在定时webalizer,每天生成当日的统计分析。
以root身份运行:crontab –e 进入定时运行任务编辑状态,加入如下任务:
5 0 * * * /usr/local/bin/webalizer –f /etc/webalizer.conf
我们这里假设系统运行有个虚拟主机,并定义了日志分析配置文件webalizer.conf。这样我们定义在凌晨00:05对日志进行统计分析;然后第二天使用http://www.bizsmooth.org/bizsmooth/usage 来进行访问并查看日志分析的状态.

如果希望保护日志统计分析报告不被未授权用户访问,我们可以通过使用apache自带的基本验证模块(auth_basic_module)来实现基本验证.
目前的实例中,我们需要将usage目录保护起来,只允许合法用户访问。
1、配置apache的主配置文件/etc/httpd/conf/httpd.conf,加入如下内容
在配置文件中对目录”/bizsmooth/usage/”应该设置为:

AllowOverride All
AuthName “Please Enter Your Identifier Name & Password!”
AuthType Basic
AuthUserFile “/var/www/webpass”
Require valid-user

2、生成验证文件webpass
需求:限制对 http://www.bizsmooth.org/bizsmooth/usage/的访问,要求用户认证才能访问。这里设置用户为”jacky”,口令为”123456″。
3、使用htpasswd建立用户文件
[root@yoyojacky /var/www]#htpasswd -cm /var/www/webpass jacky
此程序会询问用户”jacky”的口令,你输入”123456″,两次生效。
4、配置webpass文件的权限和属主
# chown apache.apache /var/www/webpass
# chmod 600 /var/www/webpass
5、重新启动或者重新加载apache的配置文件。
#service httpd restart 或者
#service httpd reload
至此, 基本的配额就完成了,可以通过IE访问这台web服务器试试看, 经过一段时间再次访问看看服务器的日志,就可以知道每天都有多少人来访问你的站点,并且访问的时候重点访问了那些页面.
支持原创! 请各位转贴的朋友,保留本帖的原始链接及作者信息! 谢谢!

About 李 伟斌

Just K.I.S.S To Be Or Not To Be, It's Your Qustion. --Keep It Simple & Stupid.
This entry was posted in Linux and tagged , , , , , , , . Bookmark the permalink.

发表评论