반응형
GeoIP 란 MaxMind 에서 제공하는 모듈과 IP정보 DB 를 통해서 웹에 접근하는 IP의 국가별로 확인할 수 있는 오픈 소스 솔루션 입니다.
참고사이트 :https://hoing.io/archives/387
아래 링크에 접속 하여 회원가입을 진행합니다.
(아래 회원가입은 최신DB 정보 다운받기 위해서)
https://www.maxmind.com/en/geolite2/signup
- 도착한 Email에서 패스워드 생성 클릭
- 로그인 후 License Keys 클릭
- Generate new licens key 클릭 (Account ID , License key 메모)
메모해두기
Account ID :
License key :
- 아래 이미지와 같이 3개의 gzip 다운로드
- 다운로드 후 서버로 업로드(SFTP 사용) /usr/share/GeoIP/ 위치에 압축을 해제 합니다
[root@centos6 GeoIP]# ll
-rw-r--r--. 1 root root 8747722 2025-01-05 17:15 GeoLite2-ASN.mmdb
-rw-r--r--. 1 root root 55028046 2025-01-03 21:22 GeoLite2-City.mmdb
-rw-r--r--. 1 root root 7909766 2025-01-03 21:24 GeoLite2-Country.mmdb
- python-ipaddr , maxmind 설치
** python-ipaddr **
# yum install -y python-ipaddr
** libmaxminddb 설치**
# wget https://github.com/maxmind/libmaxminddb/releases/download/1.4.2/libmaxminddb-1.4.2.tar.gz
# tar zxvf libmaxminddb-1.4.2.tar.gz
# ./configure
# make && make install
# echo /usr/local/lib >> /etc/ld.so.conf
# ldconfig
- mod_maxminddb 설치
# wget https://github.com/maxmind/mod_maxminddb/releases/download/1.2.0/mod_maxminddb-1.2.0.tar.gz
# tar zxvf mod_maxminddb-1.2.0.tar.gz
# cd mod_maxminddb-1.2.0
# ./configure --prefix=/usr/local/mod_maxminddb-1.2.0 --with-apxs=/usr/local/apache/bin/apxs (apxs 경로 yum 설치의 경우 usr/sbin/apxs 경로 확인)
# make && make install
- 모듈 확인
# ls -al /usr/local/apache/modules/mod_maxminddb.so
-rwxr-xr-x. 1 root root 49788 2025-01-06 09:53 /usr/local/apache/modules/mod_maxminddb.so
# cat /usr/local/apache/conf/httpd.conf | grep mod_max
LoadModule maxminddb_module modules/mod_maxminddb.so
- Apache에 GeoIP 설정 (원하는 모듈만 설정해도 상관x)
#vi /usr/local/apache/conf/httpd.conf
<IfModule maxminddb_module>
MaxMindDBEnable On
MaxMindDBSetNotes On
MaxMindDBFile COUNTRY_DB /usr/share/GeoIP/GeoLite2-Country.mmdb
MaxMindDBFile CITY_DB /usr/share/GeoIP/GeoLite2-City.mmdb
MaxMindDBFile ASN_DB /usr/share/GeoIP/GeoLite2-ASN.mmdb
MaxMindDBEnv COUNTRY_CODE COUNTRY_DB/country/iso_code
MaxMindDBEnv REGION_CODE CITY_DB/subdivisions/0/iso_code
MaxMindDBEnv MM_COUNTRY_CODE CITY_DB/country/iso_code
MaxMindDBEnv MM_COUNTRY_NAME CITY_DB/country/names/en
MaxMindDBEnv MM_CITY_NAME CITY_DB/city/names/en
MaxMindDBEnv MM_LONGITUDE CITY_DB/location/longitude
MaxMindDBEnv MM_LATITUDE CITY_DB/location/latitude
MaxMindDBEnv MM_ASN ASN_DB/autonomous_system_number
MaxMindDBEnv MM_ASORG ASN_DB/autonomous_system_organization
MaxMindDBNetworkEnv COUNTRY_DB COUNTRY_NETWORK
MaxMindDBNetworkEnv CITY_DB CITY_NETWORK
MaxMindDBNetworkEnv ASN_DB ASN_DB_NETWORK
</IfModule>
- Apache vhost 설정 (KR,US,192.168.x.x 제외 전부 차단)
<Directory "/home/ssenumma/public_html"> (vhost 설정 디렉토리)
MaxMindDBEnable On
MaxMindDBFile DB /usr/share/GeoIP/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(KR|US) AllowCountry
SetEnvIf Remote_Addr ^192\.168\. AllowInternal
Deny from all
Allow from env=AllowCountry
Allow from env=AllowInternal
</Directory>
- DB 업데이트
- Geoipupdate 설치
# wget https://github.com/maxmind/geoipupdate/releases/download/v4.3.0/geoipupdate_4.3.0_linux_amd64.tar.gz
# tar zxvf geoipupdate_4.3.0_linux_amd64.tar.gz
# mv geoipupdate_4.3.0_linux_amd64/ /usr/local
# cd /usr/local/geoipupdate_4.3.0_linux_amd64
# ln -s /usr/local/geoipupdate_4.3.0_linux_amd64/GeoIP.conf /usr/local/etc/GeoIP.conf
# vi /usr/local/etc/GeoIP.conf
# are available from https://www.maxmind.com/en/my_license_key.
AccountID 입력
LicenseKey 입력
# Enter the edition IDs of the databases you would like to update.
# Multiple edition IDs are separated by spaces.
EditionIDs GeoLite2-Country GeoLite2-City
# The remaining settings are OPTIONAL.
# The directory to store the database files. Defaults to /usr/local/share/GeoIP
DatabaseDirectory **경로수정 -> /usr/share/GeoIP
- 업데이트 실행(자동으로 하고싶으면 crontab 등록)
# cd /usr/local/geoipupdate_4.3.0_linux_amd64
./geoipupdate -v
반응형
'리눅스 > APM(Apache,php,mysql)' 카테고리의 다른 글
DB 이중화 작업(Replication 설정) (0) | 2025.01.09 |
---|---|
APM 연동(apache+php+mysql) (0) | 2025.01.09 |
Centos6 Geoip(iptables 설정) (0) | 2025.01.07 |