1. MaxMind 회원가입 https://www.maxmind.com/en/geolite2/signup 
 * 계정 가입 후 로그인 -> 라이센스키 발급 
  ※ 발급반은 라이센스 정보는 1회만 확인가능 별도 저장 필수 
 
2. libmaxminddb 설치 # yum install epel-release 
# yum install libmaxminddb libmaxminddb-devel  
 
3. mod_maxminddb 설치 ※ mod_maxminddb 모듈은 Apache 2.2 이상에서 사용 가능 
 
# cd /usr/local/src 
# wget https://github.com/maxmind/mod_maxminddb/releases/download/1.2.0/mod_maxminddb-1.2.0.tar.gz 
# tar xvfz mod_maxminddb-1.2.0.tar.gz 
# cd mod_maxminddb-1.2.0 
# ./configure --with-apxs=/usr/local/httpd2/bin/apxs 
# make; make install 
 
※ 설치한 모듈 확인 
# ls -lh /usr/local/httpd2/modules/ 
-rwxr-xr-x 1 root root  50K 2022-07-08 11:37 mod_maxminddb.so 
# cat /usr/local/httpd2/conf/httpd.conf 
LoadModule maxminddb_module   modules/mod_maxminddb.so 
 
4. geoipupdate 설치 # cd /usr/local/src 
# wget https://github.com/maxmind/geoipupdate/releases/download/v3.1.1/geoipupdate-3.1.1.tar.gz 
# tar zxvf geoipupdate-3.1.1.tar.gz  
# cd geoipupdate-3.1.1  
# ./configure  
---------------------------------------------------------------------------------------------------------------------------------------------- 
※ 아래 오류 발생시 조치방법 
configure: error: curl header (curl/curl.h) not found. You may need to install a curl development package. 
-> curl-devel 설치  
# yum install curl-devel 
---------------------------------------------------------------------------------------------------------------------------------------------- 
# make; make install 
 
5. geoip 설정파일 설정 1) Geoip.conf (라이센스) 파일 등록 # cd /usr/local/etc; mv GeoIP.conf GeoIP.conf_org 
# vi GeoIP.conf 
--------------------------------------------------------- 
AccountID [MaxMind Account ID]  LicenseKey [MaxMind 회원가입시 제공하는 LicenseKey] EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country 
--------------------------------------------------------- 
 
2) GeoIP DB 파일 업데이트 진행 # /usr/local/bin/geoipupdate 
# ll /usr/local/share/GeoIP 
-rw-r--r-- 1 root root  7775027 2022-07-08 11:47 GeoLite2-ASN.mmdb  -rw-r--r-- 1 root root 67837494 2022-07-08 11:47 GeoLite2-City.mmdb  -rw-r--r-- 1 root root  5503746 2022-07-08 11:47 GeoLite2-Country.mmdb  
 
3) Geoipupdate 스케쥴 crontab 등록 ※ 원하는 업데이트 시간 조정하여 등록 
# cat <<EEE>> /etc/crontab 
00 06 * * 3 root /usr/local/bin/geoipudate 
EEE 
 
6. 특정 국가의 접근 차단 - 적용 예시로 서버환경에 맞게 변경필요 
1) 한국, 미국에서의 접근만 허용 ※ httpd.conf 에서 설정 
<IfModule maxminddb_module>          MaxMindDBEnable On          MaxMindDBFile COUNTRY_DB /usr/local/share/GeoIP/GeoLite2-Country.mmdb          MaxMindDBFile CITY_DB /usr/local/share/GeoIP/GeoLite2-City.mmdb          MaxMindDBFile ASN_DB /usr/local/share/GeoIP/GeoLite2-ASN.mmdb          MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code          SetEnvIf MM_COUNTRY_CODE ^(KR|US) AllowCountry          <Location />                  Deny from all                  Allow from env=AllowCountry          </Location>  </IfModule> 
 
2) 중국에서의 접근 차단 ※ httpd.conf 에서 설정 
<IfModule maxminddb_module>  MaxMindDBEnable On  MaxMindDBFile COUNTRY_DB /usr/local/share/GeoIP/GeoLite2-Country.mmdb  MaxMindDBFile CITY_DB /usr/local/share/GeoIP/GeoLite2-City.mmdb  MaxMindDBFile ASN_DB /usr/local/share/GeoIP/GeoLite2-ASN.mmdb  MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code  SetEnvIf MM_COUNTRY_CODE ^(CN) BlockCountry  <Location />  Deny from env=BlockCountry  </Location>  </IfModule> 
 
3) 도메인별 설정 ※ httpd.conf 에서 설정 
<ifmodule maxminddb_module> MaxMindDBEnable On MaxMindDBFile COUNTRY_DB /usr/local/share/GeoIP/GeoLite2-Country.mmdb MaxMindDBFile CITY_DB /usr/local/share/GeoIP/GeoLite2-City.mmdb MaxMindDBFile ASN_DB /usr/local/share/GeoIP/GeoLite2-ASN.mmdb MaxMindDBEnv MM_COUNTRY_CODE COUNTRY_DB/country/iso_code 
</IfModule> 
 
※ vhosts.conf 에서 설정 
<VirtualHost *:80>  DocumentRoot /home/test/docs  ServerName test.com CustomLog logs/test.com-log geoip   <IfModule maxminddb_module>  SetEnvIf MM_COUNTRY_CODE ^(US) AllowCountry  <Location />  Deny From all  Allow from env=AllowCountry  </Location>  </IfModule>  </VirtualHost> 
 
4) 로그 설정 ※ httpd.conf 에서 수정 
 - 접근하는 IP의 국가확인이 가능 
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %{MM_COUNTRY_CODE}e" geoip  "GET / HTTP/1.1" 200 16157 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36" KR