利用webalizer解析apache日志(不乱码版)

这是转载文章
来源如下
http://haolulu.blog.51cto.com/3164472/630894

假定系统是centos

首先下载
ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.23-05-src.tgz

然后,
yum install gd
yum install gd-devel

tar zxvf webalizer-2.23-05-src.tgz
cd webalizer-2.23-05
cd lang
找到webalizer_lang.simplified_chinese  将文件格式转化为utf-8,可以借助外部工具,修改后放回即可。
(可以安装enca,然后
find /下载程序所在目录/ -name webalizer_lang.simplified_chinese|xargs enca -L zh_CN -x UTF-8




cd ..
首先确认某个字体文件必须存在
find / -name ukai.ttf
得到一个字体全路径
例如
/usr/share/fonts/chinese/TrueType/ukai.ttf

vim graphs.c
在最后加几句话,注意,要把字体路径改为本机有的字体路径!
void gdImageString(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color){
  gdImageStringFT(im, 0, color, "/usr/share/fonts/chinese/TrueType/ukai.ttf", 9 , 0.0, x, y+9, s);
}

void gdImageStringUp(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color){
  gdImageStringFT(im, 0 , color, "/usr/share/fonts/chinese/TrueType/ukai.ttf", 9 , -PI/2, x, y-9 , s);
}


./configure --prefix=/usr/local/webalizer --with-language=simplified_chinese
make
make install

cp sample.conf /etc/webalizer.conf

vim /etc/webalizer.conf

============================
在配置最后加上
LogFile        /home/apache_log/combined # 填写apache的日志文件,见下

LogType clf

OutputDir      网站文档根目录/logs
# 把“网站文档根目录”换成真实路径
# 要求logs这个目录事先创建好,并且可以任意写入。

Incremental     yes # 据说速度快一些
============================
修改httpd.conf

在虚拟机virtualhost的块里面,
  SetEnvIfNoCase Request_URI "(\.css|\.js|\.ico|\.gif|\.png|\.jpe?g|\.swf|\.swc)" dontlog
  CustomLog "/home/apache_log/combined" combined env=!dontlog
  <Directory /文档根目录/logs>
         AddDefaultCharset utf-8
  </Directory>
====================================================
现在,每当执行
/usr/local/webalizer/bin/webalizer -c /etc/webalizer.conf
时,会自动往logs这个目录加一些html和图片,只需在浏览器输入
http://域名/logs/index.html
就会看到统计结果。

为了自动化,编辑
vim  /etc/crontab
加入
0 1 * * * root /usr/local/webalizer/bin/webalizer -c /etc/webalizer.conf
然后保存
再执行
/etc/init.d/crond restart

================

猜你喜欢

转载自xieye.iteye.com/blog/1460275