我們這裡介紹幾個免費IP資料庫的更新,對於國外IP資料,我們使用Maxmind的開源項目GeoIP,而國內IP資料我們使用純真的QQWry, 由於QQWry是rara格式的,我們首先在系統安裝unrar
wget http://www.rarlab.com/rar/unrar-3.7.7-centos.gz
gzip -d unrar-3.7.7-centos.gz
mv unrar-3.7.7-centos /usr/local/bin/
編寫以下指令碼用於自動同步IP資料到/usr/local/share目錄下
vi update_ipdata.sh
#!/bin/bash
if [ ! -d /usr/local/share/GeoIP ] ; then
mkdir /usr/local/share/GeoIP
fi
if [ ! -d /usr/local/share/qqIP ] ; then
mkdir /usr/local/share/qqIP
fi
wget -t 5 -O /tmp/GeoIP.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget -t 5 -O /tmp/GeoLiteCity.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget -t 5 -O /tmp/GeoIPASNum.dat.gz http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
wget -t 5 -O /tmp/qqwry.rar http://update.cz88.net/soft/qqwry.rar
gzip -df /tmp/GeoIP.dat.gz
gzip -df /tmp/GeoLiteCity.dat.gz
gzip -df /tmp/GeoIPASNum.dat.gz
/usr/local/bin/unrar e -nQQWry.Dat -o+ /tmp/qqwry.rar /tmp/
mv -f /tmp/Geo*.dat /usr/local/share/GeoIP/
mv -f /tmp/QQWry.Dat /usr/local/share/qqIP/
我們在每周三早晨6點20更新一次ip資料庫:
20 6 * * 3 /usr/local/awstats/update-ipdata-cron.sh
最後我們需要確認一下目錄配置, 查看awstats.common.conf,修改以下三行:
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"
在awstats/wwwroot/cgi-bin/plugins目錄下修改qqwry.pl,將
my $ipfile=”/QQWry.Dat”;
修改為:
my $ipfile=”/usr/local/share/qqIP/QQWry.Dat”;
以上GeoIP的安裝介紹參考了Antezenta的awstats部落格,純真資料庫格式說明參見LumaQQ的QQWry格式解析,PHP解析QQ格式可以考慮使用QQWry的PHP擴充(C代碼)