对日志的分析是很重要的,能及时的了解服务器的状况和用户的习惯等,
对日志的分析可以使用awstats,webalizer等等工具,我选择webalizer的原因是
因为它很简单,安装,配置简单,速度快,而且提供给我的数据能满足我的需求,如果想更
强大的分析程序,请google awstats。
首先去下载webalizer,如果使用xampp等套件的同学已经有webalizer了,
在windows下,webalizer在xampp目录下,或者你指定的安装目录,这里主要说linux下,因为你的
服务器应该是在linux环境下。
下载后tar ......; cd ......; 需要先说明的,因为需要生成图片,所以服务器上必须先安装:jpeg,png,zlib,freetype,gd等程序,这个一般你的php能跑到话这些都已经安装好了。
然后直接./configure;make;make install;
安装完成,然后找到sample.webalizer.conf文件(没有自己从源码里面copy一份)放到自己定义的路径下,
配置这个文件,如:
29 LogFile /usr/local/apache2/logs/access_log.20090913
30
31 # LogType defines the log type being processed. Normally, the Webalizer
32 # expects a CLF or Combined web server log as input. Using this option,
33 # you can process ftp logs (xferlog as produced by wu-ftp and others),
34 # Squid native logs or W3C extended format web logs. Values can be 'clf',
35 # 'ftp', 'squid' or 'w3c'. The default is 'clf'.
36
37 LogType clf
38
39 # OutputDir is where you want to put the output files. This should
40 # should be a full path name, however relative ones might work as well.
41 # If no output directory is specified, the current directory will be used.
42
43 OutputDir /home/dongzhiguo/accesslog
每个配置前都有很详细的说明,这里也不多举了,然后cp webalizer文件到/usr/sbin/下(不cp也可以,只是为了放到包含路径可以方便些)。
最后,执行 webalizer -c /usr/local/etc/webalizer.conf (你自定义的配置文件),会在你指定的OutputDir目录下生成分析文件。有很多图标,具体的也不解释了。
如:

注意:执行webalizer和创建目录都要需要有权限。我在apache的log配置里面过滤了图片,js,css等,这样省去很多不必要的数据分析,文件数就可以认为是pv。
附apache的配置:
1 LogLevel warn
2
3 LogFormat "%h %l %u %t "%r" %>s %b" common
4 LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
5 LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" "%{B}C" %v %I %O %D" combinedio
6
7 SetEnvIf Request_URI (.gif$|.jpg$|.swf$|.js$|.vbs$|.css$) log-ignore
8
9 ErrorLog logs/error_log
10 CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/access_log.%Y%m%d 86400 480" combinedio env=!log-ignore
如果你访问量比较大的话,日志会分割,就像上面的httpd.conf配置,如果要统计一个月的日志,需要把日志进行合并,
简单的办法是使用cat log1 log2 ....> logall ; 或者sort -m -t " " -k 4 -o logall log1 log2 ...;
这个语句指:对log1,log2里面的日志按第四列进行排序后合并成logall,我认为没有必要排序,webalizer这个已经能分别了。
另外说一下webaliezer.hist这个文件,这个文件会记录上次统计的结果,就是上个月的数据,这样就很好的连接成了连贯的数据了。