最後更新: 2022-02-08
目錄
- Installation
- Command Usage
- 由 Source 安裝 GeoIP
- 安裝 Perl library
- geolite2legacy
- Troubeshoot
- 另一款 source - db-ip
介紹
# Open Source DB - Country, City
Homepage: https://dev.maxmind.com/geoip/legacy/geolite/
Maxmind is a company that sells geolocation technology that matches IP addresses to countries, regions, cities and ISPs.
All of their databses are available for an initial fee and a monthly update subscription and include greater accuracy and a higher frequency of updating.
GeoLite Legacy builds
Updated versions of the GeoLite Legacy databases are now only available to redistribution license customers,
although anyone can continue to download the March 2018 GeoLite Legacy builds.
Starting January 2, 2019, the last build will be removed from Maxmind website.
GeoLite Legacy database users will need to switch to the GeoLite2 or commercial GeoIP databases and
update their integrations by January 2, 2019.
Installation
Debain
apt-get install geoip-bin geoipupdate geoip-database
Centos
yum install GeoIP
This package includes GeoLite data created by MaxMind
ls -lh /usr/share/GeoIP/*.dat
lrwxrwxrwx 1 root root 17 Apr 6 2020 /usr/share/GeoIP/GeoIP.dat -> GeoIP-initial.dat -rw-r--r-- 1 root root 1.2M Aug 8 2019 /usr/share/GeoIP/GeoIP-initial.dat lrwxrwxrwx 1 root root 19 Apr 6 2020 /usr/share/GeoIP/GeoIPv6.dat -> GeoIPv6-initial.dat -rw-r--r-- 1 root root 2.3M Aug 8 2019 /usr/share/GeoIP/GeoIPv6-initial.dat
Package: GeoIP (必要) - C library & CLI Tools
Config:
/etc/GeoIP.conf
CLI
- /usr/bin/geoiplookup
- /usr/bin/geoipupdate
Lib
- ls /usr/lib64/libGeoIP.so*
Package: GeoIP-data - Snapshot of IPv4 and IPv6 databases for GeoIP (not regularly updated)
Total download size: 25 M, Installed size: 51 M
Files:
/usr/share/GeoIP/GeoIPASNum-initial.dat /usr/share/GeoIP/GeoIPASNumv6-initial.dat /usr/share/GeoIP/GeoIPCity-initial.dat /usr/share/GeoIP/GeoIPCityv6-initial.dat
Package: GeoIP-update - Crontab entry to provide weekly updates of the GeoIP free databases.
/etc/cron.weekly/geoipupdate
Command Usage
geoiplookup 115.160.xxx.xxx
GeoIP Country Edition: HK, Hong Kong GeoIP ASNum Edition: AS9381 Wharf T&T Ltd.
other opts
- -f Specify a custom path to a single GeoIP datafile.
- -d Specify a custom directory containing GeoIP datafile(s).
- -v Lists the date and build number for the GeoIP datafile(s).
Check DB Version
geoiplookup -v 8.8.8.8
GeoIP Country Edition: GEO-106FREE 20160607 Build 1 Copyright (c) 2016 MaxMind
GeoIP City Edition, Rev 1: GEO-533LITE 20160607 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Reser
GeoIP ASNum Edition: GEO-117 20160627 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Reser
GeoIP Country V6 Edition: GEO-106FREE 20160607 Build 1 Copy
GeoIP ASNum V6 Edition: GEO-117 20160627 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Re
GeoIP City Edition V6, Rev 1: GEO-536LITE 20160607 Build 1 Copyright (c) 2016 MaxMind Inc All Rights Reserved
由 Source 安裝 GeoIP
* 如果只是 update DB, 那直接跳到 Step 3 就得.
# Install the MaxMind GeoIP C API
1. GeoIP C libraries
wget http://maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar xzvf GeoIP.tar.gz
cd GeoIP*
./configure && make && make install
/etc/ld.so.conf
2. Install cpan (for call by perl)
Required Modules: Geo::IP or Geo::IP::PurePerl (from Maxmind)
yum install perl-CPAN
CLI
cpan
install Geo::IP install Geo::IP::PurePerl quit
Remark
相當於
perl -MCPAN -e "install Geo::IP"
perl -MCPAN -e "install Geo::IP::PurePerl"
3. Last update GeoIP DB
cd /usr/share/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP....
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
rm GeoIP.dat GeoIPCity.dat -f
gzip -d GeoIP.dat.gz GeoLiteCity.dat.gz
安裝 Perl library
* AWStats 會用它
# REQUIRED MODULES: "Geo::IP" OR "Geo::IP::PurePerl" (from Maxmind)
[方法A]
yum install perl-Geo-IP
[方法B]
perl -MCPAN -e 'install Geo::IP'
Reading '/root/.cpan/Metadata' Database was generated on Fri, 27 Apr 2018 21:54:26 GMT Geo::IP is up to date (1.51).
perl -MCPAN -e 'install Geo::IP::PurePerl'
Reading '/root/.cpan/Metadata' Database was generated on Fri, 27 Apr 2018 21:54:26 GMT Geo::IP::PurePerl is up to date (1.26).
geolite2legacy
It's based on mmutils but it reads new GeoLite2 directly from zip files containings CSV databases.
csv -> legacy .dat format
https://github.com/sherpya/geolite2legacy
pip2 install ipaddr
chmod 700 geolite2legacy.py
# 同 Folder 內要有 geoname2fips.csv 及 pygeoip_const.py
python2 geolite2legacy.py -i GeoLite2-Country-CSV_20240503.zip -o GeoIP.dat
Database type Country - Blocks IPv4 - Encoding: utf-8 wrote 496369-node trie with 485496 networks (252 distinct labels) in 15 seconds
Troubleshoot
# Error 1
Error: Plugin load for plugin 'geoip_city_maxmind' failed with return code: Error: Can't locate Geo/IP.pm in @INC
解決
perl -MCPAN -e 'install Geo::IP'
# Error 2
Your installed version of libgeoip is outdated! Please update to at least version to 1.5.0 and reinstall this module.
解決
perl -MCPAN -e 'install Geo::IP::PurePerl'