Wednesday, October 24, 2012

linux apache2下日志分析工具awstat之三-安装geo-ip插件

本文继续linux apache2下日志分析工具awstat之二

本系列全部经实际操作的原创博文.

此插件需要参考这里 这个插件就是显示来访者IP所在的国家及城市的.像这样:

image

1.下载安装

wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz


2.创建Geo-IP的相关工作目录
mkdir /usr/local/share/GeoIP


把下载的文件转移并解析到新创建的相关工作目录:
mv GeoIP.dat.gz /usr/local/share/GeoIP/
gunzip /usr/local/share/GeoIP/GeoIP.dat.gz

mv GeoLiteCity.dat.gz /usr/local/share/GeoIP/
gunzip /usr/local/share/GeoIP/GeoLiteCity.dat.gz

mv GeoIPASNum.dat.gz /usr/local/share/GeoIP/
gunzip /usr/local/share/GeoIP/GeoIPASNum.dat.gz
进入该工作目录:
cd /usr/local/share/GeoIP/

查看该目录下的文件:


[root@ip-10-174-26-246 GeoIP]# ls
GeoIPASNum.dat GeoIP.dat GeoLiteCity.dat


3.安装Geo的解析程序


3.1 下载+编辑+安装,如果嫌3.1麻烦,就选装3.2吧(人家说比3.1运行略慢些,我看还不是一样):

wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.5.tar.gz
tar -xvzf GeoIP-1.4.5.tar.gz
cd GeoIP-1.4.5

./configure
make
make check
sudo make install


因为我使用Amazon Linux AMI操作系统,默认很干净没有任何编辑器.所以我出现了
[root@ip-10-174-26-246 GeoIP-1.4.5]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets $(MAKE)... no
checking for working aclocal-1.4... missing
checking for working autoconf... missing
checking for working automake-1.4... missing
checking for working autoheader... missing
checking for working makeinfo... missing
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
[root@ip-10-174-26-246 GeoIP-1.4.5]# make
-bash: make: command not found


解决:
yum install gcc



再运行./configure就好了.


问题2,又提示说我没有zlib开发包:

configure: error: Zlib header (zlib.h) not found. Tor requires zlib to build. You may need to install a zlib development package.



解决:

yum install zlib-devel

再运行./configure就好了.


问题3,说没有make命令:


[root@ip-10-174-26-246 GeoIP-1.4.5]# make
-bash: make: command not found


解决:

yum install make

再运行./configure就好了.


配置库目录:

vim /etc/ld.so.conf


增加一行:
/usr/local/lib

/usr/local/lib,因为这个目录下有刚才生成的libGeoIP.so文件.把这个目录加到这里,为了其它程序可以直接使用.


下面是安装Geo-IP-1.35,刚才我忘了装这一步,出现GEO-IP.PM找不到的错误:

wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.35.tar.gz

tar -xvzf Geo-IP-1.35.tar.gz
cd Geo-IP-1.35

perl Makefile.PL LIBS='-L/usr/local/lib'
make
make test
sudo make install

 


问题:


[root@ip-10-174-26-246 Geo-IP-1.35]# perl Makefile.PL LIBS='-L/usr/local/lib'
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
BEGIN failed--compilation aborted at Makefile.PL line 1.





解决:

yum install perl-devel





3.2 与3.1可选的是或者使用官方的另一个教程


此教程3.1执行过的话,就跳过.

wget http://www.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.17.tar.gz
tar -xvzf Geo-IP-PurePerl-1.17.tar.gz -C /usr/local/src/
cd /usr/local/src/Geo-IP-PurePerl-1.17
perl Makefile.PL
make
make test
make install



3.3 启用插件


打开该awstat的网站配置文件

vim /var/www/awstats/wwwroot/cgi-bin/awstats.pk17s.cn.conf
查找:
#LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /pathto/GeoIPOrg.dat"


下面增加:
LoadPlugin="geoip GEOIP_STANDARD /usr/local/share/GeoIP/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoLiteCity.dat"
LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /usr/local/share/GeoIP/GeoIPASNum.dat"

问题:

Error: Plugin load for plugin 'geoip' failed with return code: Error: Can't locate Geo/IP.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /var/www/cgi-bin/lib /var/www/cgi-bin/plugins) at (eval 2) line 1. Can't locate Geo/IP/PurePerl.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /var/www/cgi-bin/lib /var/www/cgi-bin/plugins) at (eval 3) line 1. Error: Need Perl module Geo::IP or Geo::IP::PurePer



至此,应该是算装好了这个插件了吧.


No comments: