參考網頁:
awstats + GeoIP | Peter Luk’s Blog
使用者:Minwei/資訊筆記/日誌分析進階設定 – 台灣棒球維基館
讓AWstats可以透過IP反解出國家和Domiain Name
AWStats LOG 檔分析系統安裝設定 @ 工作雜記 :: 隨意窩 Xuite日誌
1. 下載 GeoIP 檔 http://dev.maxmind.com/geoip/legacy/geolite/
# wget -P /etc/awstats -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
# wget -P /etc/awstats -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
# wget -P /etc/awstats -N http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
2 解壓縮
# gunzip /etc/awstats/GeoIP.dat.gz
# gunzip /etc/awstats/GeoLiteCity.dat.gz
# gunzip /etc/awstats/GeoIPASNum.dat.gz[@more@]
3. 修改 /etc/awstats 目錄下設定檔
# sed -i ‘s/DNSLookup=2/DNSLookup=1/’ /etc/awstats/awstats.abc.*
並在 DNSLookup=1 後面加入
LoadPlugin=”geoip GEOIP_STANDARD /etc/awstats/GeoIP.dat”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD /etc/awstats/GeoLiteCity.dat”
LoadPlugin=”geoip_org_maxmind GEOIP_STANDARD /etc/awstats/GeoIPASNum.dat”
4. 測試設定檔
# /usr/share/awstats/wwwroot/cgi-bin/awstats.pl –update –config=abc.tces.ilc.edu.tw
Create/Update database for config “/etc/awstats/awstats.abc.tces.ilc.edu.tw.conf” by AWStats version 7.4 (build 20150714)
From data in log file “/var/log/httpd/access_log”…
Phase 1 : First bypass old records, searching new record…
Direct access after last parsed record (after line 4670)
Jumped lines in file: 4670
Found 4670 already parsed records.
Parsed lines in file: 1
Found 1 dropped records,
Found 0 comments,
Found 0 blank records,
Found 0 corrupted records,
Found 0 old records,
Found 0 new qualified records.
5. 更新 GeoIP 檔
# cat /usr/local/bin/UpdateGeoIP.sh
#!/bin/bash
/bin/wget -P /etc/awstats -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
/bin/wget -P /etc/awstats -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
/bin/wget -P /etc/awstats -N http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
/bin/gunzip /etc/awstats/GeoIP.dat.gz
/bin/gunzip /etc/awstats/GeoLiteCity.dat.gz
/bin/gunzip /etc/awstats/GeoIPASNum.dat.gz
6. 更改檔案權限
# chmod 700 /usr/local/bin/UpdateGeoIP.sh
7. 加入工作排程,每月凌晨更新
# crontab -e
0 0 1 * * /usr/local/bin/UpdateGeoIP.sh > /dev/null 2>&1