企业运维实践-Nginx利用geoip2模块并利用MaxMind的GeoIP2数据库实现处理不 ...

鼠扑  论坛元老 | 2024-7-25 18:02:01 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1050|帖子 1050|积分 3150

为了做好运维口试路上的助攻手,特整理了上百道 【运维技术栈口试题集锦】 ,让你口试不慌心不跳,高薪offer怀里抱!
这次整理的口试题,小到shell、MySQL,大到K8s等云原生技术栈,不仅适合运维新人入行口试需要,还适用于想提升进阶跳槽加薪的运维朋友。

本份口试集锦涵盖了


  • 174 道运维工程师口试题
  • 128道k8s口试题
  • 108道shell脚本口试题
  • 200道Linux口试题
  • 51道docker口试题
  • 35道Jenkis口试题
  • 78道MongoDB口试题
  • 17道ansible口试题
  • 60道dubbo口试题
  • 53道kafka口试
  • 18道mysql口试题
  • 40道nginx口试题
  • 77道redis口试题
  • 28道zookeeper
总计 1000+ 道口试题, 内容 又全含金量又高


  • 174道运维工程师口试题
   1、什么是运维?
    2、在工作中,运维职员经常需要跟运营职员打交道,请问运营职员是做什么工作的?
    3、如今给你三百台服务器,你怎么对他们进行管理?
    4、简述raid0 raid1raid5二种工作模式的工作原理及特点
    5、LVS、Nginx、HAproxy有什么区别?工作中你怎么选择?
    6、Squid、Varinsh和Nginx有什么区别,工作中你怎么选择?
    7、Tomcat和Resin有什么区别,工作中你怎么选择?
    8、什么是中间件?什么是jdk?
    9、讲述一下Tomcat8005、8009、8080三个端口的寄义?
    10、什么叫CDN?
    11、什么叫网站灰度发布?
    12、简述DNS进行域名解析的过程?
    13、RabbitMQ是什么东西?
    14、讲一下Keepalived的工作原理?
    15、讲述一下LVS三种模式的工作过程?
    16、mysql的innodb如何定位锁题目,mysql如何减少主从复制延长?
    17、如何重置mysql root密码?
  网上学习资料一大堆,但假如学到的知识不成体系,遇到题目时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份体系化的资料的朋友,可以点击这里获取!
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、口试辅导),让我们一起学习成长!
关注「WeiyiGeek」公众号
设为「特别关注」每天带你玩转网络安全运维、应用开辟、物联网IOT学习!


本章目次:


  • 0x00 前言简述
  • 0x01 安装摆设

    • 情况说明
    • libmaxminddb 下载
    • ngx_http_geoip2_module 下载
    • Geoip2 模块编译动态链接库
    • GeoLite2 数据库下载
    • GeoLite2 数据库自动更新

  • 0x02 实践利用

    • 1.利用GeoIP2模块请求客户端的IP地点国家省份经纬度展示
    • 2.利用GeoIP2模块静止某一国家地区的IP地点访问网站
    • 3.利用GeoIP2模块实现不同国家访问进入不同目次页面

  • 0x0n 入坑出坑

    • 题目1.非二进制方式安装Nginx GeoIP过程中大概会出现的错误题目如下,也帮各人列举出办理办法。
    • 题目2: 假如在进行Nginx编译时出现 ./configure: error: the GeoIP module requires the GeoIP library.You can either do not enable the module or install the library. 题目提示时办理方法。


原文地点: https://blog.weiyigeek.top
首发地点:  企业运维实践-Nginx利用geoip2模块并利用MaxMind的GeoIP2数据库实现处理不同国家或都会的访问最佳实践指南为了实现根据访问者访问我们的网站时根据其IP表现其所属地,也为获取不同地区访问者的IP地点等相关信息为目的,所以在搜索引擎中查找办理方案,在网络上查询到如Nginx+GeoIP2模块+都会数据库,然后颠末多方面讲求,终极照旧利用该办理方案。
https://mp.weixin.qq.com/s/PPUaSsBhS5Kv1SLiVjc4Gw

0x00 前言简述
形貌: 为了实现根据访问者访问我们的网站时根据其IP表现其所属地,也为获取不同地区访问者的IP地点等相关信息为目的,所以在搜索引擎中查找办理方案,在网络上查询到如下几种方案Nginx+GeoIP2、利用收费 IP 辨认接口、DNS 根据地区解析,然后颠末多方面讲求,终极照旧利用Nginx+GeoIP2办理方案。
三种办理方案优缺点


  • Nginx + GeoIP2
    可以拿到请求 IP 的国家和都会信息然后进行各种个性化 Nginx 配置
    可以将请求 IP 的地理位置通过 php-fpm 通报 php 程序
    定时更新 MaxMind 免费数据库(GeoLite2-Country.mmdb + GeoLite2-City.mmdb)完成完美闭环
    maxmind 公司 2002 年成立至今,靠谱
  • 利用 IP 辨认接口:稳固的需要收费(也不能保证 100% 高可用:限频、相应时间、接口异常等因素),免费的无法保证稳固性,接口远远没有将 GeoLite 数据放在本地稳固
  • DNS 根据地区解析:cloudflare 收费略贵,国内 cloudxns 已关闭免费服务(免费的东西说变就变,论 planB 的紧张性)
所有在本章中,我将向您展示如何搭建与配置一个有用的 Nginx 和 Max Mind GeoIP2/GeoLite2 设置。从安装摆设包的下载、编译安装步调以及下令利用、包括安装过程中大概会遇到的坑,在末了博主也通过几个实践例子,展示如何利用 GeoIP2 按国家/地区限定对某些 URL 的访问。
TIPS: MaxMind GeoIP 已经被弃用了一段时间。对于您最新的地理定位需求,请改用 MaxMind GeoIP2(或免费版本的 GeoLite2)。
TIPS: 当前网上大部分Nginx + GeoIP 的教程都是 GeoIP 老版本的已经不适用了当前最新版本的Nginx二进制编译安装,你可参照本章更快的进行实践利用。
TIPS: GeoUP 依赖 MaxMind 的 IP 数据,需要频繁更新,所以我们在安装配置后也实现了利用crontab服务,针对其国家都会数据库进行自动化脚本定时更新配置。
好了,不多说了,下面直接开始实践吧!

0x01 安装摆设

情况说明
情况一览:
  1. # 宿主机系统
  2. $ uname -a
  3. 113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  4. $ cat /etc/issue.net
  5. Ubuntu 20.04.1 LTS
  6. # 应用软件
  7. nginx-1.22.0.tar.gz
  8. libmaxminddb-1.6.0.tar.gz
  9. ngx_http_geoip2_module-3.4.tar.gz
  10. GeoLite2-City_20220802.tar.gz
  11. GeoLite2-Country_20220802.tar.gz
复制代码
温馨提示: 此处利用的是 Ubuntu 20.04 操作体系, 该体系已做安全加固和内核优化符合等保2.0要求【SecOpsDev/Ubuntu-InitializeSecurity.sh at master · WeiyiGeek/SecOpsDev 】, 如你的Linux未进行相应配置情况大概与读者有些许差异, 如需要进行(windows server、Ubuntu、CentOS)安全加固请参照如下加固脚本进行加固, 请各人疯狂的 star 。
加固脚本地点:【 https://github.com/WeiyiGeek/SecOpsDev/blob/master/OS-操作体系/Linux/Ubuntu/Ubuntu-InitializeSecurity.sh 】
为了节省各人的实践时间,我已经把需要用到的源码包上传到空间中,有需要的朋友可以看一下,下载地点: http://share.weiyigeek.top/d/36158960-50338508-7c5982?p=2088(访问密码:2088)
温馨提示: 如提示证书不对,请点击高级继续访问即可.

原文地点: https://blog.weiyigeek.top
libmaxminddb 下载

形貌: 首先安装 libmaxminddb 库,其提供了一个用于读取MaxMind DB文件的C库,包括来自MaxMind的GeoIP2数据库。这是一种自界说二进制格式,旨在促进 IP 地点的快速查找,同时答应在与地点关联的数据类型方面具有极大的灵活性。
项目地点: https://github.com/maxmind/libmaxminddb
下载构建:
  1. wget -c https://github.com/maxmind/libmaxminddb/releases/download/1.6.0/libmaxminddb-1.6.0.tar.gz
  2. tar -zxvf libmaxminddb-1.6.0.tar.gz && cd libmaxminddb-1.6.0
  3. ./configure
  4. make && make install
  5. tee -a /etc/ld.so.conf.d/libc.conf <<'EOF'
  6. # libc default configuration
  7. /usr/local/lib
  8. EOF
  9. sudo ldconfig
复制代码
或利用apt下令进行安装:
  1. $ sudo apt update
  2. $ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin geoipupdate
复制代码
上面安装的软件包是:


  • libmaxminddb0 libmaxminddb-dev – MaxMind 地理定位数据库
  • mmdb-bin – 二进制。从下令行调用的程序。利用此下令手动定位 IP。
  • geoipupdate – 帮助配置和更新 GeoIP2 / GeoLite2 的软件包。
ngx_http_geoip2_module 下载

形貌: 下载 ngx_http_geoip2_module 利用基于客户端 IP(默认)或特定变量(同时支持 IPv4 和 IPv6)的 maxmind geoip2 数据库中的值创建变量,该模块如今支持nginx流,并且可以以与http模块类似的方式利用。
项目地点: https://github.com/leev/ngx_http_geoip2_module/
下载构建:
  1. wget -c https://github.com/leev/ngx_http_geoip2_module/archive/refs/tags/3.4.tar.gz -O /usr/local/src/ngx_http_geoip2_module-3.4.tar.gz
  2. tar -zxf ngx_http_geoip2_module-3.4.tar.gz && ls ngx_http_geoip2_module-3.4/
  3.   # config  LICENSE  ngx_http_geoip2_module.c  ngx_stream_geoip2_module.c  README.md
复制代码
Geoip2 模块语法
语法示例:
  1. # HTTP
  2. http {
  3.   ...
  4.   geoip2 /etc/maxmind-country.mmdb {
  5.     auto_reload 5m;
  6.     $geoip2_data_country_code default=US source=$variable_with_ip country iso_code;
  7. }
  8. }
  9. # Stream
  10. stream {
  11.   ...
  12.   geoip2 /etc/maxmind-country.mmdb {
  13.     auto_reload 5m;
  14.     $geoip2_data_country_code default=US source=$remote_addr country iso_code;
  15.   }
  16.   ...
  17. }
复制代码
参数说明:


  • auto_reload <interval>: 启用自动重新加载将使 nginx 以指定的时间间隔检查数据库的修改时间,假如发生更改则重新加载。
  • $variable_name [default=<value] [source=$variable_with_ip] path ...: 假如没有指定【default】参数,则假如未找到该变量将为空,假如没有指定【source】参数 $remote_addr 将用于执行查找。
从上面语法格式中您是否是一片茫然,不管你是不是反正我第一次看到就茫然了,那 country iso_code 关键字又是从何而来?
为了办理上面这个疑问,我们在来看看如下操作。
mmdblookup 下令
形貌: 在前面编译安装libmaxminddb库后,我们便可以利用 mmdblookup 工具,查找所需数据的路径(例如:国家/地区名称),以JSON格式返回的,此中continent(洲) 、country (国家) 、registered_country(已注册的国家)对象包含了code/geoname_id/names键:
GeoLite2-Country.mmdb 库只带有 country 相关数据样本输出
  1. $ mmdblookup --file ./GeoLite2-Country.mmdb --ip 223.6.6.6
  2. {
  3.   "continent":
  4.     {
  5.       "code":
  6.         "AS" <utf8_string>
  7.       "geoname_id":
  8.         6255147 <uint32>
  9.       "names":
  10.         {
  11.           "de":
  12.             "Asien" <utf8_string>
  13.           "en":
  14.             "Asia" <utf8_string>
  15.           "es":
  16.             "Asia" <utf8_string>
  17.           "fr":
  18.             "Asie" <utf8_string>
  19.           "ja":
  20.             "アジア" <utf8_string>
  21.           "pt-BR":
  22.             "Ásia" <utf8_string>
  23.           "ru":
  24.             "Азия" <utf8_string>
  25.           "zh-CN":
  26.             "亚洲" <utf8_string>
  27.         }
  28.     }
  29.   "country":
  30.     {
  31.       "geoname_id":
  32.         1814991 <uint32>
  33.       "iso_code":
  34.         "CN" <utf8_string>
  35.       "names":
  36.         {
  37.           "de":
  38.             "China" <utf8_string>
  39.           "en":
  40.             "China" <utf8_string>
  41.           "es":
  42.             "China" <utf8_string>
  43.           "fr":
  44.             "Chine" <utf8_string>
  45.           "ja":
  46.             "中国" <utf8_string>
  47.           "pt-BR":
  48.             "China" <utf8_string>
  49.           "ru":
  50.             "Китай" <utf8_string>
  51.           "zh-CN":
  52.             "中国" <utf8_string>
  53.         }
  54.     }
  55.   "registered_country":
  56.     {
  57.       "geoname_id":
  58.         1814991 <uint32>
  59.       "iso_code":
  60.         "CN" <utf8_string>
  61.       "names":
  62.         {
  63.           "de":
  64.             "China" <utf8_string>
  65.           "en":
  66.             "China" <utf8_string>
  67.           "es":
  68.             "China" <utf8_string>
  69.           "fr":
  70.             "Chine" <utf8_string>
  71.           "ja":
  72.             "中国" <utf8_string>
  73.           "pt-BR":
  74.             "China" <utf8_string>
  75.           "ru":
  76.             "Китай" <utf8_string>
  77.           "zh-CN":
  78.             "中国" <utf8_string>
  79.         }
  80.     }
  81. }
复制代码
GeoLite2-City.mmdb 库带有 country City 相关数据样本输出 (一般推荐利用该库)
  1. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6
  2. {
  3.     "city":
  4.       {
  5.         "geoname_id":
  6.           1808926 <uint32>
  7.         "names":
  8.           {
  9.             "de":
  10.               "Hangzhou" <utf8_string>
  11.             "en":
  12.               "Hangzhou" <utf8_string>
  13.             "es":
  14.               "Hangzhou" <utf8_string>
  15.             "fr":
  16.               "Hangzhou" <utf8_string>
  17.             "ja":
  18.               "杭州市" <utf8_string>
  19.             "pt-BR":
  20.               "Hangzhou" <utf8_string>
  21.             "ru":
  22.               "Ханчжоу" <utf8_string>
  23.             "zh-CN":
  24.               "杭州" <utf8_string>
  25.           }
  26.       }
  27.     "continent":
  28.       {
  29.         "code":
  30.           "AS" <utf8_string>
  31.         "geoname_id":
  32.           6255147 <uint32>
  33.         "names":
  34.           {
  35.             "de":
  36.               "Asien" <utf8_string>
  37.             "en":
  38.               "Asia" <utf8_string>
  39.             "es":
  40.               "Asia" <utf8_string>
  41.             "fr":
  42.               "Asie" <utf8_string>
  43.             "ja":
  44.               "アジア" <utf8_string>
  45.             "pt-BR":
  46.               "Ásia" <utf8_string>
  47.             "ru":
  48.               "Азия" <utf8_string>
  49.             "zh-CN":
  50.               "亚洲" <utf8_string>
  51.           }
  52.       }
  53.     "country":
  54.       {
  55.         "geoname_id":
  56.           1814991 <uint32>
  57.         "iso_code":
  58.           "CN" <utf8_string>
  59.         "names":
  60.           {
  61.             "de":
  62.               "China" <utf8_string>
  63.             "en":
  64.               "China" <utf8_string>
  65.             "es":
  66.               "China" <utf8_string>
  67.             "fr":
  68.               "Chine" <utf8_string>
  69.             "ja":
  70.               "中国" <utf8_string>
  71.             "pt-BR":
  72.               "China" <utf8_string>
  73.             "ru":
  74.               "Китай" <utf8_string>
  75.             "zh-CN":
  76.               "中国" <utf8_string>
  77.           }
  78.       }
  79.     "location":
  80.       {
  81.         "accuracy_radius":
  82.           1000 <uint16>
  83.         "latitude":
  84.           30.299400 <double>
  85.         "longitude":
  86.           120.161200 <double>
  87.         "time_zone":
  88.           "Asia/Shanghai" <utf8_string>
  89.       }
  90.     "registered_country":
  91.       {
  92.         "geoname_id":
  93.           1814991 <uint32>
  94.         "iso_code":
  95.           "CN" <utf8_string>
  96.         "names":
  97.           {
  98.             "de":
  99.               "China" <utf8_string>
  100.             "en":
  101.               "China" <utf8_string>
  102.             "es":
  103.               "China" <utf8_string>
  104.             "fr":
  105.               "Chine" <utf8_string>
  106.             "ja":
  107.               "中国" <utf8_string>
  108.             "pt-BR":
  109.               "China" <utf8_string>
  110.             "ru":
  111.               "Китай" <utf8_string>
  112.             "zh-CN":
  113.               "中国" <utf8_string>
  114.           }
  115.       }
  116.     "subdivisions":
  117.       [
  118.         {
  119.           "geoname_id":
  120.             1784764 <uint32>
  121.           "iso_code":
  122.             "ZJ" <utf8_string>
  123.           "names":
  124.             {
  125.               "en":
  126.                 "Zhejiang" <utf8_string>
  127.               "fr":
  128.                 "Province de Zhejiang" <utf8_string>
  129.               "zh-CN":
  130.                 "浙江省" <utf8_string>
  131.             }
  132.         }
  133.       ]
  134.   }
复制代码
GeoLite2-Country.mmdb 与 GeoLite2-Country.mmdb 对比。
  1. # - 国家 ./GeoLite2-Country.mmdb 库
  2. # 如果此时我只想获取 country 的名称可以这样。
  3. $ mmdblookup --file ./GeoLite2-Country.mmdb --ip 223.6.6.6 country names zh-CN
  4.   "中国" <utf8_string>
  5. # 当然如果你想获取国家的 iso_code 也是同样的。
  6. $ mmdblookup --file ./GeoLite2-Country.mmdb --ip 223.6.6.6 country iso_code
  7.   "CN" <utf8_string>
  8. # - 国家、城市库 ./GeoLite2-Country.mmdb 库
  9. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 country names zh-CN
  10.   "中国" <utf8_string>
  11. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 country iso_code
  12.   "CN" <utf8_string>
  13. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 continent names zh-CN
  14.   "亚洲" <utf8_string>
  15. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 subdivisions 0 names zh-CN
  16.   "浙江省" <utf8_string>
  17. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 subdivisions 0 names iso_code
  18.   "ZJ" <utf8_string>
  19. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 city names zh-CN
  20.   "杭州" <utf8_string>
  21. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 location longitude # 经度  
  22.   120.161200 <double>
  23. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 location latitude  # 纬度
  24.   30.299400  <double>
  25. $ mmdblookup --file ./GeoLite2-City.mmdb --ip 223.6.6.6 location time_zone # 时区
  26.   "Asia/Shanghai" <utf8_string>
复制代码

上述的两个示例我们可以将其转换为 geoip2 模块界说的nginx变量。
  1. # 如只需要国家信息建议使用该库
  2. geoip2 /usr/local/GeoIP2/GeoLite2-Country.mmdb {
  3.   $geoip2_data_country "default=China" source=$remote_addr country names en
  4. }
  5. # 如需要获取国家以及省份信息建议使用该库,此处暂不演示使用,在后续实践中再进行介绍和使用。
  6. geoip2 /usr/local/GeoIP2/GeoLite2-City.mmdb {
  7.   $geoip2_data_country "default=中国" source=$remote_addr country names zh-CN;  # 中国
  8.   $geoip2_data_country_code country iso_code;                  # CN
  9.   $geoip2_data_country_continent continent names zh-CN;        # 亚洲
  10.   $geoip2_data_country_continent_code continent code;          # AS
  11.   $geoip2_data_province_name subdivisions 0 names zh-CN;       # 浙江省
  12.   $geoip2_data_province_isocode subdivisions 0 names iso_code; # "ZJ"
  13.   $geoip2_data_city city names zh-CN;                         # 杭州
  14.   $geoip2_data_city_longitude location longitude;              # 120.161200
  15.   $geoip2_data_city_latitude location latitude;                # 30.299400
  16.   $geoip2_data_city_time_zone location time_zone;             # "Asia/Shanghai"
  17. }
复制代码
温馨提示: 当请求来自受信托的地点时,将利用“X-Forwarded-For”请求标头字段中的地点, 并且设置 geoip2_proxy_recursive < on | off > 指令。


  • 假如递归搜索被禁用,那么将利用“X-Forwarded-For”中发送的末了一个地点,而不是与一个受信托地点匹配的原始客户端地点。
  • 假如启用了递归搜索,那么将利用“X-Forwarded-For”中发送的末了一个非信托地点,而不是与可信地点之一匹配的原始客户端地点。
模块利用参考地点:https://github.com/leev/ngx_http_geoip2_module/#example-usage
Geoip2 模块编译动态链接库

形貌: 有大概此时你通过源码编译方式安装 Nginx 了 ,那如何加入新的Nginx模块呢?
答: 那就是重新编译 Nginx 即可,我们不需要执行make install重新安装 Nginx 具体操作如下所示。
温馨提示: 假如你没有Nginx二进制安装情况,可以访问【运维实践-最新Nginx二进制构建编译lua-nginx-module动态链接Lua脚本访问Redis数据库读取静态资源隐式展现】文章,并按照其流程进行二进制编译构建Nginx当前最新的稳固版本 1.22.0
Step 1.执行nginx -v获取原编译构建的参数。
  1. nginx version: nginx/1.22.0
  2. built by gcc 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  3. built with OpenSSL 1.1.1q  5 Jul 2022
  4. TLS SNI support enabled
  5. configure arguments: --prefix=/usr/local/nginx --with-pcre=../pcre-8.45 ......  --with-ld-opt=-Wl,--as-needed,-O1,--sort-common
复制代码
Step 2.此处补充一点,你完全可按照自身需求利用--add-module进行静态链接库安装,或者利用--add-dynamic-module进办法态链接库安装。
  1. # 动态链接库安装模块 (绝对或者相对路径)
  2. --add-dynamic-module=../ngx_http_geoip2_module-3.4
  3. --add-dynamic-module=/usr/local/src/ngx_http_geoip2_module-3.4
  4. # 静态链接库生成模块
  5. --add-module=../ngx_http_geoip2_module-3.4
复制代码
Step 3.将步调1获取的参数加入到./configure, 并在末端添加上--add-dynamic-module=/usr/local/src/ngx_http_geoip2_module-3.4, 以重新构建支持 geoip2 模块的 nginx 二进制文件。
  1. cd /usr/local/src/nginx-1.22.0/
  2. # 预编译参数
  3. ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre=../pcre-8.45 --with-zlib=../zlib-1.2.12 --with-openssl=../openssl-1.1.1q --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --lock-path=/var/run/nginx.lock --modules-path=/usr/local/nginx/modules --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-threads --with-http_sub_module --with-http_v2_module --with-http_auth_request_module --with-http_realip_module --with-http_secure_link_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_ssl_module --with-http_slice_module --with-http_stub_status_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_geoip_module --with-mail --with-mail_ssl_module --with-http_addition_module --with-http_random_index_module --with-compat --with-file-aio --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib,--as-needed,-O1,--sort-common --add-module=/usr/local/src/ngx_devel_kit-0.3.1 --add-module=/usr/local/src/lua-nginx-module-0.10.21 --add-dynamic-module=/usr/local/src/echo-nginx-module-0.62 --add-dynamic-module=/usr/local/src/ngx_http_geoip2_module-3.4
  4. # 编译构建
  5. make
  6. # 编译后将会在objs目录生成动态链接库,我们需复制到 /usr/local/nginx/modules
  7. $ ls objs/*.so
  8.   objs/ngx_http_geoip2_module.so  objs/ngx_stream_geoip2_module.so
  9. $ cp -a objs/*.so /usr/local/nginx/modules
  10. $ ls /usr/local/nginx/modules
  11. ngx_http_echo_module.so  ngx_http_geoip2_module.so  ngx_stream_geoip2_module.so
  12. # 然后使用objs目录中生成的 nginx 二进制文件覆盖 /usr/sbin/nginx
  13. $ cp -a objs/nginx /usr/sbin/nginx
  14. $ make upgrade
  15. # 最后执行此命令验证安装是否成功
  16. nginx -V
复制代码
GeoLite2 数据库下载

形貌: Nginx 的 ngx_*_geoip2_module 模块依赖于 GeoLite2 数据库, 免费的 GeoLite2 数据库可从 Maxminds 网站得到(需要注册),GeoLite2 数据库基于 IP 地点的数据库和 Web 服务,提供有关地理位置、生齿统计和用户以及匿名者的数据。
假如你想下载与更新 GeoLite2 数据库,您需要拥有 MaxMind 帐户 ID 和允许证密钥, 并且当我们在 nginx 中利用则该 GeoIP2 模块,在我们请求时Nginx时根据IP地点来辨认来源国家都会,但是我们需要提前下载载该数据库.
简单流程: 首先访问 Maxminds 官网,然后注册登岸到用户背景,创建并获取 License Key, 末了下载 GeoLite2 数据库该压缩包,内里包含的是二进制mmdb格式的库文件。
Maxminds 官网地点: https://maxmind.com
GeoIP2 Web 服务演示(每天25次限额):https://www.maxmind.com/en/geoip2-precision-demo?ip_address=223.6.6.6
Locate My IP Address : https://www.maxmind.com/en/locate-my-ip-address
假如无法登录官网或者你不想注册登岸,也可以下载博主已经从官网下载好的 GeoIP2 数据库。
GeoLite2 数据库下载地点: http://share.weiyigeek.top/d/36158960-50280983-746907 (访问密码: 2088)
温馨提示: 如提示证书不对,请点击高级继续访问即可.
实践流程
Step 1.访问并登岸maxmind.com官网,此处我已经注册了账号,就不在演示如何注册了,假如没有注册的朋友可以安装如下提示进行注册(https://support.maxmind.com/hc/en-us/articles/4407099783707-Create-an-Account),相信各人都没题目。

Step 2.登岸后点击 Account 用户-> Manage License Keys 管理允许 -> 生成允许,然后将会瞥见 New license key successfully created 提示,此中请记录号 Account/User ID 与 License key ,以备后续利用。

Step 3.随后点击右边的GeoIP2选项卡中的 Download Files, 你可安装需要下载 Country 国家 或者 City 都会的数据,上述下载连接中我们已经下载了如图中的两个压缩包。
官方下载地点: https://www.maxmind.com/en/accounts/<your user account id>/geoip/downloads

Step 4.下载后上传到Nginx服务器并解压到 /usr/local/GeoIP2 目次之中。
  1. # 若不存在该目录请创建
  2. mkdir -vp /usr/local/GeoIP2
  3. # 解压数据库
  4. ls ~
  5. GeoLite2-City_20220802.tar.gz  GeoLite2-Country_20220802.tar.gz
  6. tar -zxf GeoLite2-City_20220802.tar.gz
  7. tar -zxf GeoLite2-Country_20220802.tar.gz
  8. # 将 mmdb 文件复制到 /usr/local/GeoIP2 目录下
  9. mv GeoLite2-City_20220802/GeoLite2-City.mmdb /usr/local/GeoIP2/
  10. mv GeoLite2-Country_20220802/GeoLite2-Country.mmdb /usr/local/GeoIP2/
  11. rm -rf GeoLite2-City_20220802/ GeoLite2-Country_20220802/
  12. # 查看解压到 /usr/local/GeoIP2/ 后的 GeoIP2 数据库
  13. $ tree /usr/local/GeoIP2/
  14. /usr/local/GeoIP2/
  15. ├── GeoLite2-City.mmdb
  16. └── GeoLite2-Country.mmdb
复制代码
Step 5.验证GeoIP模块摆设情况,我们需要针对nginx相关配置文件进行如下配置:
  1. # 1.在 nginx.conf 中进行如下几个关键部分配置。
  2. $ vim nginx.conf
  3. worker_processes  auto;
  4. # -- 关键点: 加载 geoip2 模块动态链接库
  5. load_module modules/ngx_http_geoip2_module.so;
  6. load_module modules/ngx_stream_geoip2_module.so;
  7. ....
  8. http {
  9.     ...
  10.     # -- 关键点: 日志格式
  11.     log_format demo '$remote_addr - [ $geoip2_country_code $geoip2_data_city_name ] - $remote_user [$time_local] "$request" '
  12.                 '$status $body_bytes_sent "$http_referer" '
  13.                 '"$http_user_agent" "$http_x_forwarded_for" rt=$request_time urt=$upstream_response_time';
  14. ![](https://img-blog.csdnimg.cn/img_convert/9a8cb5f8c0ec69e6499adead0da6e95b.png)
  15. 最全的Linux教程,Linux从入门到精通
  16. ======================
  17. 1.  **linux从入门到精通(第2版)**
  18. 2.  **Linux系统移植**
  19. 3.  **Linux驱动开发入门与实战**
  20. 4.  **LINUX 系统移植 第2版**
  21. 5.  **Linux开源网络全栈详解 从DPDK到OpenFlow**
  22. ![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/59742364bb1338737fe2d315a9e2ec54.png)
  23. 第一份《Linux从入门到精通》466页
  24. ====================
  25. 内容简介
  26. ====
  27. 本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。
  28. ![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/9d4aefb6a92edea27b825e59aa1f2c54.png)
  29. **本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。**
  30. > 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论
  31. **网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
  32. **[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
  33. **一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
  34. ==================
  35. 内容简介
  36. ====
  37. 本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。
  38. ![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/9d4aefb6a92edea27b825e59aa1f2c54.png)
  39. **本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。**
  40. > 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论
  41. **网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
  42. **[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**
  43. **一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

鼠扑

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表