下载
wget ftp://ftp.mrunix.net/pub/webalizer/webalizer-2.23-05-src.tar.bz2
tar jxvf webalizer-2.23-05-src.tar.bz2
修改增加中文支持(主要是调用ttf字体的gd函数来生成图片)
由于diff文件比较长,这里只帖出关键的部分。
graphs.c
+
/* common public declarations */
@@ -98,6 +101,27 @@
/*****************************************************************/
/* */
+/* */
+/*****************************************************************/
+
+/**
+ * font_path is extern var defined in webalizer.h and set in webalizer.c
+ */
+void my_gdImageString(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
+{
+ gdImageStringFT(im, 0 , color, font_path, 9 , 0.0, x, y+9, s); //font size is 9
+}
+
+void my_gdImageStringUp(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color)
+{
+ gdImageStringFT(im, 0 , color, font_path, 9 , -PI/2, x, y-9 , s);
+}
然后把所有的gdImageStringUp替换为my_gdImageStringUp
gdImageString替换为my_gdImageString
再把my_my_替换为my_
再将lang/webalizer_lang.simplified_chinese重新保存为utf-8编码的文件。
为了增加一个“return top":
diff -Nur webalizer-2.23-05-orig/output.c webalizer-2.23-05/output.c
--- webalizer-2.23-05-orig/output.c 2011-01-03 12:52:05.000000000 +0800
+++ webalizer-2.23-05/output.c 2012-09-02 14:17:37.000000000 +0800
@@ -223,7 +223,7 @@
fprintf(out_fp,"%s\n",lptr->string);
lptr=lptr->next;
}
- fprintf(out_fp,"<CENTER>\n<HR>\n<P>\n");
+ fprintf(out_fp,"<CENTER id='nav'>\n<HR>\n<P>\n");
}
sample.conf
+FontPath /usr/share/fonts/truetype/arphic/uming.ttc
#HTMLHead <META NAME="author" CONTENT="The Webalizer">
#HTMLHead <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
+HTMLHead <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+HTMLEnd <div style='display:block;position:fixed;bottom:45px;right:200px;height:30px;'>
+HTMLEnd <a href='#nav' style='color:blue;'>↑Top</a>
+HTMLEnd </div>
HTMLEnd </BODY></HTML>
webalizer.c
int dump_search = 0; /* Search strings */
int dump_header = 0; /* Dump header as first rec */
char *dump_path = NULL; /* Path for dump files */
+char *font_path = "/usr/share/fonts/truetype/arphic/ukai.ttc"; /*default font path */
@@ -1863,6 +1865,7 @@
case 119: use_flags=1; flag_dir=save_opt(value); break; /* FlagDir */
case 120: searchcasei=
(tolower(value[0])=='n')?0:1; break; /* SearchCaseI */
+ case 121: font_path=save_opt(value); break; /* Font Path */
}
}
fclose(fp);
webalizer.h
extern int dump_header ; /* Dump header as first rec */
extern char *dump_path ; /* Path for dump files */
+extern char *font_path ; /* Chinese font for gragh */
安装
./configure --prefix=/usr/local/webalizer --with-language=simplified_chinese
make && make install
修改webalizer.conf文件
cd /usr/local/webalizer/etc/
cp webalizer.conf.sample webalizer.conf
vim webalizer.conf
主要修改以下几处:
LogFile /var/log/httpd/access_log #apache日志文件
OutputDir /var/log/httpd/weblog #分析的网页文件输出目录
Incremental yes #为yes时,使每天分析结果存在,否则只会为当时分析的
HostName 192.168.52.139 #网站域名
之后执行命令开始生成html文件: /usr/local/webalizer/bin/webalizer -c /usr/local/webalizer/etc/webalizer.conf -o /var/www/html/weblog/
注意:日志格式必须为CLF格式,默认的apache和nginx的格式都为CLF,以apache日志格式为例,
LogFormat "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
详细的配置方法在安装包目录README文件。
添加crontab
* 1 * * * /usr/local/webalizer/bin/webalizer -c /usr/local/webalizer/etc/webalizer.conf -o /var/www/html/weblog/
访问:http://ip/weblog/
附件是我打包好的完整包