安装GeoIP库

1
2
3
4
5
6
7
8
9
10
# 使用yum安装
[root@xadmaster ~]# yum -y install geoip-devel geoip
# 使用编译安装
[root@xadmaster ~]# wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
[root@xadmaster ~]# tar zxvf GeoIP.tar.gz
[root@xadmaster ~]# cd GeoIP-1.4.8/
[root@xadmaster ~]# ./configure
[root@xadmaster ~]# make && make install
[root@xadmaster ~]# echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf
ldconfig

GeoLite免费数据库,下载地址:https://dev.maxmind.com/geoip/legacy/geolite/

1. 国家信息地址库,自治系统号地址库 GeoIP.dat(GeoLiteCountry.dat)

2. 城市地区信息地址库 GeoLiteCity.dat

命令行使用

1
2
3
4
5
6
7
# 默认使用GeoIP.dat(GeoLiteCountry.dat),我测试的不准!!,可能我的库太久了
[root@xadmaster ~]# geoiplookup www.xadocker.cn
GeoIP Country Edition: JP, Japan
# 指定库文件,我测试的依然不准!
[root@xadmaster ~]# geoiplookup www.xadocker.cn -f GeoLiteCity.dat
GeoIP City Edition, Rev 1: JP, 40, Tokyo, Tokyo, 102-0082, 35.685001, 139.751404, 0, 0

nginx使用第三方模块GeoIP

安装nginx

1
2
# 编译Nginx需要添加ngx_http_geoip_module模块
./configure --without-http_empty_gif_module --with-poll_module --with-http_stub_status_module --with-http_ssl_module --with-http_geoip_module