Maxmind 简介

Maxmind 官方网址:https://www.maxmind.com/en/home

Maxmind是一家总部位于美国的公司,专门从事IP地理定位和在线欺诈检测服务。该公司拥有全球最大的IP地理位置数据库,并持续更新维护。

Maxmind的主打产品是GeoIP2。GeoIP2是一款基于IP地址的地理定位和数据enrichment工具。它可以准确识别IP地址的物理位置、ISP(互联网服务提供商)、连接类型、代理类型等。GeoIP2数据包括国家、州、城市、坐标、邮政编码等位置信息,以及ISP、匿名IP、移动连接等网络信息。

GeoIP2为许多企业提供了有价值的位置数据服务,应用场景包括数字广告投放、内容个性化、网络分析、合规性和安全监控等。凭借先进的IP智能技术和庞大的数据库资源,Maxmind已成为全球地理定位数据和服务的领先提供商。

总的来说,GeoIP2是Maxmind公司旗下的核心产品,为全球企业客户提供了准确可靠的IP地理定位和数据enrichment解决方案。

GeoIP2 下载

1.点击这里 进入 GeoIP2 数据下载页面;

2.点击右侧页面的 Accessing GeoLite2 Free Geolocation Data 下的 Download Files,如图:

3.进入 Sign In 页面后,输入你的邮箱账号,没有的话点击下面的 How to create one 去看如何创建,如图:

4.然后在跳转的 Password 页面输入你账号密码,如图:

5.如果你开启了两步验证功能,则在 Two-Factor Authentication 页面输入你邮箱账号里面的验证码进行登陆:

6.进入之后,找到并点击左侧导航栏 GeoIP2/GeoLite2 下面的 Download Files 菜单,然后在右边找到 GeoLite2 CityGeoLite2 Country 进行下载,如图:

GeoIP2 使用

1.安装 mmdb 数据解析工具 mmdb-bin

1
$ sudo apt install -y mmdb-bin

2.将上面下载好的 GeoLite2 CityGeoLite2 Country 数据文件解压到指定的目录

3.执行 mmdblokup 命令获取数据,比如查看指定 IP 是哪个城市:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
root@ubuntu2204-004:/usr/local/nginx# mmdblookup --file /usr/local/nginx/geoip2/GeoLite2-City_20240507/GeoLite2-City.mmdb --ip 111.181.0.184

{
"city":
{
"geoname_id":
1791247 <uint32>
"names":
{
"de":
"Wuhan" <utf8_string>
"en":
"Wuhan" <utf8_string>
"es":
"Wuhan" <utf8_string>
"fr":
"Wuhan" <utf8_string>
"ja":
"武漢市" <utf8_string>
"pt-BR":
"Wuhan" <utf8_string>
"ru":
"Ухань" <utf8_string>
"zh-CN":
"武汉" <utf8_string>
}
}
"continent":
{
"code":
"AS" <utf8_string>
"geoname_id":
6255147 <uint32>
"names":
{
"de":
"Asien" <utf8_string>
"en":
"Asia" <utf8_string>
"es":
"Asia" <utf8_string>
"fr":
"Asie" <utf8_string>
"ja":
"アジア" <utf8_string>
"pt-BR":
"Ásia" <utf8_string>
"ru":
"Азия" <utf8_string>
"zh-CN":
"亚洲" <utf8_string>
}
}
"country":
{
"geoname_id":
1814991 <uint32>
"iso_code":
"CN" <utf8_string>
"names":
{
"de":
"China" <utf8_string>
"en":
"China" <utf8_string>
"es":
"China" <utf8_string>
"fr":
"Chine" <utf8_string>
"ja":
"中国" <utf8_string>
"pt-BR":
"China" <utf8_string>
"ru":
"Китай" <utf8_string>
"zh-CN":
"中国" <utf8_string>
}
}
"location":
{
"accuracy_radius":
50 <uint16>
"latitude":
30.589000 <double>
"longitude":
114.268100 <double>
"time_zone":
"Asia/Shanghai" <utf8_string>
}
"registered_country":
{
"geoname_id":
1814991 <uint32>
"iso_code":
"CN" <utf8_string>
"names":
{
"de":
"China" <utf8_string>
"en":
"China" <utf8_string>
"es":
"China" <utf8_string>
"fr":
"Chine" <utf8_string>
"ja":
"中国" <utf8_string>
"pt-BR":
"China" <utf8_string>
"ru":
"Китай" <utf8_string>
"zh-CN":
"中国" <utf8_string>
}
}
"subdivisions":
[
{
"geoname_id":
1806949 <uint32>
"iso_code":
"HB" <utf8_string>
"names":
{
"de":
"Hubei" <utf8_string>
"en":
"Hubei" <utf8_string>
"es":
"Hubei" <utf8_string>
"fr":
"Province de Hubei" <utf8_string>
"ja":
"湖北省" <utf8_string>
"pt-BR":
"Hubei" <utf8_string>
"ru":
"Хубэй" <utf8_string>
"zh-CN":
"湖北省" <utf8_string>
}
}
]
}

所以,我们在 nginx 主配置文件 http {...} 中就可以做如下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# GEOIP 国家代码解析
geoip2 /usr/local/nginx/geoip2/GeoLite2-Country_20240507/GeoLite2-Country.mmdb {
$geoip2_data_continent_code default=AS continent code;
$geoip2_data_continent_names continent names en;
$geoip2_data_country_code default=CN country iso_code;
$geoip2_data_country_name country names en;
}
fastcgi_param CONTINENT_CODE $geoip2_data_continent_code;
fastcgi_param CONTINENT_NAMES $geoip2_data_continent_names;
fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;

# GEOIP 城市代码解析
geoip2 /usr/local/nginx/geoip2/GeoLite2-City_20240507/GeoLite2-City.mmdb {
$geoip2_data_subdivisions_names subdivisions names en;
$geoip2_data_city_names default=Xiamen city names en;
}
fastcgi_param SUBDIVISIONS_NAMES $geoip2_data_subdivisions_names;
fastcgi_param CITY_NAMES $geoip2_data_city_names;