Pages

Sunday, 27 November 2011

AWStats的扩展-GeoIP的安装配置

AWStats 安装后默认是不支持国家或地区的,来源全部显示为“未知”。只有安装在GeoIP后AWStats才能根据IP判断来源。

一、下载与解压

其中 GeoIP 是国家数据,GeoLiteCity 是城市数据,GeoIPASNum 是组织数据
1
2
3
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
1
2
3
4
5
6
7
mkdir /var/GeoIP
mv GeoIP.dat.gz /var/GeoIP/
gunzip /var/GeoIP/GeoIP.dat.gz
mv GeoLiteCity.dat.gz /var/GeoIP/
gunzip /var/GeoIP/GeoLiteCity.dat.gz
mv GeoIPASNum.dat.gz /var/GeoIP/
gunzip /var/GeoIP/GeoIPASNum.dat.gz

二、安装 GeoIP 程序

先安装 GeoIP C API 然后再安装 GeoIP Perl 模块。
1
2
3
4
5
6
apt-get install libtool
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz
tar -zxf GeoIP-1.4.8.tar.gz
cd GeoIP-1.4.8/
./configure
make && make install
1
2
3
4
5
wget http://geolite.maxmind.com/download/geoip/api/perl/Geo-IP-1.39.tar.gz
tar -zxf Geo-IP-1.39.tar.gz
cd Geo-IP-1.39
perl Makefile.PL LIBS='-L/usr/local/lib'
make && make install

三、更新awstats配置文件

1
vim /etc/awstats/awstats.xx.conf
1
2
3
4
5
6
7
8
#1422 行左右添加:
LoadPlugin="geoip GEOIP_STANDARD /var/GeoIP/GeoIP.dat"
 
#1432 行左右添加:
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /var/GeoIP/GeoLiteCity.dat"
 
#1469 行左右添加:
LoadPlugin="geoip_org_maxmind GEOIP_STANDARD /var/GeoIP/GeoIPASNum.dat"
最后更新统计数据:
1
2
rm -rf /var/lib/awstats/*  #删除旧的统计数据
/usr/local/awstats/tools/awstats_updateall.pl now
 
-----------------------------------------------------------------

GeoIP Information for AWStats


Improve country and city location information in your web analytics reports



AWStats offers three different ways to provide Country level information about visitors ("hosts") connecting to your site. By default, the host domain extension is used if you have performed reverse DNS look-up. While this results in human readable host names as well, reverse DNS lookup is time consuming. Alternatively, GeoIP plugins can be used. They match the host IP with a database of IP allocations which is already installed locally on your computer, significantly reducing the time needed to match a host to a location. There are two country level GeoIP databases available. A Geo::IPFree Perl module is available, but it does not appear that the database is being maintained. The better solution is MaxMind's Geo::IP GeoLite Country open source version, said to be 97% accurate. An even more accurate commercial version is also available.
Recently, MaxMind made a free version of its GeoLite City database available. The free version is about 60% accurate; the commercial version improves that to about 75%.
MaxMind's Autonomous System Numbers database works well for organization identification, although the display of AS numbers in AWStats may be incentive enough to license the commercial organization database.
The GeoIP installation can be a bit tedious. The instructions below, for Linux and for MS Windows, should help you get up and running. We conclude with some general observations.
Last updated: 2008-12-18.
[Contents ↓]

GeoIP installation for Linux

Download the current GeoLite Country, GeoLite City and Organization (AS Numbers) databases

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 Create GeoIP data directory if it doesn't already exist
if [ ! -d /usr/local/share/GeoIP ] ; then mkdir /usr/local/share/GeoIP fi Move data files to directory and unzip.
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

Install the GeoIP program.

There are two options:
  1. Install a C program and a Perl program
  2. Install just a Perl program.
Option a) will provide the fastest performance.
The instructions for a) are known to work using Fedora Core 6 - FC6.
  1. Install GeoIP C API http://www.maxmind.com/app/c
Download the GeoIP-*.tar.gz file, uncompress it and compile.
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
2007-10-10: Thanks to James Rice who notified us of version 1.4.3. 2007-02-21: Thanks to Daniel Wallace who notified us of version 1.4.2. 2007-01-13: Thanks to Daniel Wallace who notified us of version 1.4.1. 2006-09-25: Thanks to Oleg Nerus who notified us of version 1.4.0. 2006-05-21: Thanks to Florian Burka who notified us of the availability of version 1.3.17.
With a text editor, add the directory libGeoIP.so was installed in, i.e. /usr/local/lib, to /etc/ld.so.conf, and execute ldconfig
  1. Install Geo::IP Perl Module
Download the Geo-IP-*.tar.gz file, uncompress it and compile.
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 Option b) (in lieu of option a!)
PurePerl Module (is slower, but does not require C library). Download latest Geo-IP-PurePerl-*.tar.gz file, uncompress and compile. Replace the version below with the current version.
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

Update your awstats.mysite.conf configuration file

Look for the following geoip LoadPlugin options in your AWStats configuration file. Update them with the full path to each of the two database files.
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" [Contents ↓]

MS Windows

Install Geo::IP Perl Module

open a windows terminal window
For ActivePerl 6xx builds, use:
C:\> ppm install http://theoryx5.uwinnipeg.ca/ppmpackages/Geo-IP.ppd For 8xx builds, use:
C:\> ppm install http://theoryx5.uwinnipeg.ca/ppms/Geo-IP.ppd ppm is an ActiveState Perl Module Management system. Follow the prompts to install the Perl modules. Optionally install the GeoIP database. Your output should look like this:
C:\>ppm install http://theoryx5.uwinnipeg.ca/ppms/Geo-IP.ppd ==================== Install 'Geo-IP' version 1.27 in ActivePerl 5.8.7.815. ==================== Installing C:\Perl\site\lib\auto\Geo\IP\IP.dll Installing C:\Perl\site\lib\auto\Geo\IP\IP.lib Installing C:\Perl\site\lib\auto\Geo\IP\IP.exp Installing C:\Perl\site\lib\auto\Geo\IP\IP.bs Installing C:\Perl\html\site\lib\Geo\IP.html Installing C:\Perl\html\site\lib\Geo\Mirror.html Installing C:\Perl\html\site\lib\Geo\IP\Record.html Files found in blib\arch: installing files in blib\lib into architecture depende nt library tree Installing C:\Perl\site\lib\Geo\Mirror.pm Installing C:\Perl\site\lib\Geo\IP.pm Installing C:\Perl\site\lib\Geo\IP\Record.pod Installing C:\Perl\site\lib\Geo\IP\Record.pm The database GeoIP.dat is needed to complete the installation, and should be placed in the C:\Program Files/GeoIP directory. I will now fetch and install this for you, if you like. Fetch GeoIP.dat? [yes] yes Fetching http://theoryx5.uwinnipeg.ca/ppms/scripts/GeoIP.dat ... done! C:/Program Files/GeoIP does not exist. Create it? [no] yes GeoIP.dat has been successfully installed to C:/Program Files/GeoIP Successfully installed Geo-IP version 1.27 in ActivePerl 5.8.7.815.

Update the GeoIP GeoLite Country database. Add the GeoIP GeoLite City and Organization (AS Numbers) databases.

  1. Download the current Country, City and Organization (AS Numbers) databases
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
  1. Unzip the files and place them in your GeoIP data directory, i.e. C:\Program Files\GeoIP

Update your awstats.mysite.conf configuration file

Look for the following geoip LoadPlugin options in your AWStats configuration file. Update them with the full path to each of the two database files.
LoadPlugin="geoip GEOIP_STANDARD C:\Program Files\GeoIP\GeoIP.dat" LoadPlugin="geoip_city_maxmind GEOIP_STANDARD C:\Program Files\GeoIP\GeoLiteCity.dat" LoadPlugin="geoip_org_maxmind GEOIP_STANDARD C:\Program Files\GeoIP\GeoIPASNum.dat"
NoteVarious people have reported problems using the geoip_org_maxmind plugin with the PurePerl GeoIP module and MS Windows. This appears to have been addressed in the AWStats 6.6 release. Alternatively, you could compile the GeoIP C library (dll). See the note below on this topic. (Added 2006-05-12)

from http://antezeta.com/awstats/geoip.html
-------------------------------------------------------------------------------------------------

安裝Geo:IPfree和Net:XWhois
wget http://search.cpan.org/CPAN/authors/id/G/GM/GMPASSOS/Geo-IPfree-0.2.tar.gz
tar zxvf Geo-IPfree-0.2.tar.gz
cd Geo-IPfree-0.2
perl Makefile.PL
make
make install
cd ..
wget http://search.cpan.org/CPAN/authors/id/V/VI/VIPUL/Net-XWhois-0.90.tar.gz
tar -xzvf Net-XWhois-0.90.tar.gz
cd Net-XWhois-0.90
perl Makefile.PL
make
make install

修改/etc/awstats/awstats.yourdomain.conf
DNSlookup=1
LoadPlugin="geoipfree"

另一個模組是Geo::IP(資料較常更新,速度較快)
安裝方式如下:
wget http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.2.tar.gz
tar zxvf GeoIP-1.4.2.tar.gz
cd GeoIP-1.4.2
./configure
make
make check
make install
echo '/usr/local/lib' >> /etc/ld.so.conf
/sbin/ldconfig /etc/ld.so.conf
cd ..
wget http://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.27.tar.gz
tar zxvf Geo-IP-1.27.tar.gz
cd Geo-IP-1.27
perl Makefile.PL
make
make test
make install
cd ..
wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /etc/awstats/GeoIP.dat

修改/etc/awstats/awstats.yourdomain.conf
LoadPlugin="geoip GEOIP_STANDARD /etc/awstats/GeoIP.dat"

smilie注意:您只能使用geoip或geoipfree其中一種,如果您先前使用geoipfree,現在改用geoip,則您需在geoipfree的那一行LoadPlugin前面加上#。

由於GeoIP.dat每個月初會更新一次,雖然網站上號稱是5/1更新,可是實際解壓縮後看到的檔案日期卻是5/3,故我們可以讓系統每個月排定一天去抓這個壓縮檔,解壓縮後,覆蓋掉/etc/awstats/GeoIP.dat這個檔即可。

首先編輯一個shell script:
vi /root/admin/updateGeoIP_dat.sh
#!/bin/bash
# Name: updateGeoIP_dat.sh
# Author: Andowson Chang (andowson [at] gmail [dot] com)
# Version: 0.1
# Last Modified: 2007-05-24
wget http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /etc/awstats/GeoIP.dat

我將它存在/root/admin/updateGeoIP_dat.sh,並更改檔案權限為可執行:
chmod 755 /root/admin/updateGeoIP_dat.sh

接著我們再設定crontab,例如我們排定每個月的5日凌晨2點,執行這個/root/admin/updateGeoIP_dat.sh:
# update GeoIP.dat (2007.05.24)
00 2 5 * * root /root/admin/updateGeoIP_dat.sh >/dev/null
 Filename updateGeoIP_dat.sh [Disk] Download
 Description updateGeoIP_dat.sh
 Filesize 266 bytes
 Downloaded:  16 time(s)

from http://www.andowson.com/posts/list/28.page

No comments:

Post a Comment