webalizer是一个高效的、免费的web服务器日志分析程序。其分析结果以HTML文件格式保存,从而可以很方便的通过web服务器进行浏览。Internet上的很多站点都使用webalizer进行web服务器日志分析。
搭建环境以及所需软件包:
系统为:cent os 5.5
Jpeg库
Zlib库
Libpng库
Freetype字库
Gd库
http服务 (rpm包)
GeoIP-1.4.8.tar.gz GeoIP库,用于解析IP地址所对应的国家列表
webalizer-2.23-05-src.tgz webalizer主程序包
<!--[if !supportLists]-->一、<!--[endif]-->搭建环境
Webalizer需要用到相关的jpeg,png,zlib库,这些库有部分是默认安装的,有些需要手动安装,安装的步骤不能颠倒,需要安装顺序安装。
可以下载源码包进行安装,步骤一般为:
# ./configure
# make
# make install
这里我用yum包安装,这样可以轻松解决依赖包问题,适用于新手。
<!--[if !supportLists]-->1、 <!--[endif]-->首先挂载光盘,记住自己挂载光盘的路径
# mount /dev/cdrom /mnt/cdrom/ 这里我挂载到/mnt/cdrom的目录下
<!--[if !supportLists]-->2、 <!--[endif]-->修改yum配置文件
# vi /etc/yum.repos.d/CentOS-Media.repo 配置文件存放路径
[c5-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///mnt/cdrom/ 将此处修改为光盘挂载路径
file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
保存退出、使用# yum list命令,查看yum包,如果yum制作成功则会列出列表。
<!--[if !supportLists]-->3、 <!--[endif]-->接下来安装我们所需要的一些库。
首先安装第一个jpeg库,
# yum install jpeg* 安装jpeg库命令,系统将自动安装
所有的库安装方法相同,可以安装顺序逐个安装。
<!--[if !supportLists]-->4、 <!--[endif]-->安装httpd服务
这里我们也可以利用yum包进行安装
# yum install httpd*
<!--[if !supportLists]-->二、<!--[endif]-->安装webalizer
<!--[if !supportLists]-->1) <!--[endif]-->安装GeoIP库,支持对国家的ip分析极其整理
# tar -zxmf GeoIP-1.4.8.tar.gz 解压源码包
# cd GeoIP-1.4.8 进入解压目录
# ./configure 进行编译前配置
# make 编译
# make install 安装
安装完成后,会在/usr/local/share/GeoIP/下生成一个GeoIP.dat文件
<!--[if !supportLists]-->2) <!--[endif]-->编译汉化字体,支持中文输出
# tar -zxmf webalizer-2.23-05-src.tgz 解压webalizer
# cd webalizer-2.23-05 进入解压目录
# cd lang 进入语言目录
找到webalizer_lang.simplified_chinese 将文件格式转化为utf-8,可以借助外部工具,修改后放回即可。这里我使用EditPlus 3进行格式转换,大家可以去网上下载一些软件,将文件格式转换即可,如无需汉化,此步骤可略过。
# cd .. 返回上级目录
找一个中文字体,传到服务器上,比如/usr/share/fonts/chinese/TrueType/ukai.ttf,前提是服务器已经安装了gd包,并且顺利支持freetype,这个在安装gd的时候可以看到是不是支持.我用的cent os 直接就支持中文,所以在此选用的系统自带的黑体
字体搜索方法:find / -name *.ttf 查找
# vi graphs.c 打开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);
} // 注意这里修改成你自己字体路径
这样汉化过程结束,我们开始正式安装webalizer
<!--[if !supportLists]-->3) <!--[endif]-->安装webalizer
# ./configure --prefix=/usr/local/webalizer 安装目录
> --enable-geoip 启用geoip支持
> --with-geoip=/usr/local/include geoip路径
> --with-geoiplib=/usr/local/lib geoiplib库路径
> --with-language=simplified_chinese 支持中文简体
# make 编译 这里如果你系统的时钟不正确则会发出警告,检测到时钟错误,我们可以修改下时钟,然后继续进行。
修改时间方法:
# date 080410382011.10 顺序为:月日时分年.秒
然后再继续操作
# make install 安装
# cp sample.conf /etc/webalizer.conf 复制源码包实力文件,放入/etc下。如果不进行此步骤操作,则系统会自动调用默认的主配置文件。
<!--[if !supportLists]-->4) <!--[endif]-->
<!--[if !supportLists]-->三、<!--[endif]-->配置webalizer
<!--[if !supportLists]-->1) <!--[endif]-->将日志导入系统中,这里我再服务器中拉入一些日志文件,放在/opt/下
<!--[if !supportLists]-->2) <!--[endif]-->修改主配置文件
# vi /etc/webalizer.conf
LogFile /opt/access.tar.gz 指定日志文件位置,可以是压缩包
LogType clf 设置日志类型
OutputDir /var/www/html/test 生成统计数据记录目录
HostName test 统计网站名
GeoIP yes 启用geoip功能
GeoIPDatabase /usr/local/share/GeoIP/GeoIP.dat 指向geoipdatabase路径
保存退出
<!--[if !supportLists]-->3) <!--[endif]-->建立生成数据记录的目录
# mkdir -p /var/www/html/test
<!--[if !supportLists]-->4) <!--[endif]-->将libGeoIP复制到/usr/lib下,要不然启动服务会报错。
# cp -d -p /usr/local/lib/libGeoIP* /usr/lib/
<!--[if !supportLists]-->四、<!--[endif]-->启动服务,并测试
<!--[if !supportLists]-->1) <!--[endif]-->创建脚本
# vi test.sh
#!/bin/sh
run=/usr/local/webalizer/bin/webalizer
$run -F clf -p -n ' ' -c '/etc/webalizer.conf' 各个参数的解释参考本文末尾。
<!--[if !supportLists]-->2) <!--[endif]-->启动服务
[root@Rytong /]# . /test.sh
Webalizer V2.23-05 (Linux 2.6.18-92.el5 i686) Simplified Chinese
使用日志文件 /opt/access.tar.gz (gzip-clf)
Using GeoIP Country Edition (/usr/local/share/GeoIP/GeoIP.dat)
输出结果到 /var/www/html/test
产生报表的主机名是 'test'
没有找到历史信息文件...
没有找到上次运行的数据...
警告: 截断太长的 hostname 域
跳过错误记录 (1)
正在保存当前运行的数据... [07/15/2011 16:29:39]
正在生成报表 ---- 为 七月 2011
正在保存历史信息文件...
正在生成综合报表
185 条记录 (7 条被忽略, 1 条无效) 共用时 1 秒, 9185/sec
开启httpd服务,并在浏览器中访问统计页面
http://192.168.20.167/test
<!--[if !supportLists]-->3) <!--[endif]-->访问结果:
<!--[endif]-->
访问首页。
<!--[endif]-->
查看每月的统计信息
<!--[endif]-->