±×·¸´Ù. ¶Ç ¹Ù²î¾ú´Ù ¡®¤µ¡¯¡¦.
GeoIP database ÆÄÀÏÀ» ´Ù¿î ¹Þ´Âµ¥ ¸µÅ© ÁÖ¼Ò°¡ º¯°æ µÇ¾ú´Ù
¸Æ½º¸¶ÀÎµå »çÀÌÆ®ÀÇ È¸¿ø °¡ÀÔ ÀÌÈÄ ¶óÀ̼±½º Å°¸¦ ¹Þ¾Æ¾ß ´Ù¿î·Îµå¸¦ ¹ÞÀ» ¼ö ÀÖµµ·Ï º¯°æ µÇ¾ú´Ù.
crontab ¿¡ ¾Æ·¡¿Í °°ÀÌ geoipupdate ¸í·É¾î¸¦ ÁÖ±âÀûÀ¸·Î ½ÇÇà ÇÔÀ¸·Î¼ ¾÷µ¥ÀÌÆ®¸¦ ½ÇÇàÇÒ ¼ö ÀÖ´Ù.
1 2 3 4 5 | ~]# crontab -e ------------------------------------------------------ 00 06 * * 5 /bin/geoipupdate # GeoIP database update. ------------------------------------------------------ |
´ÜÁö À§ ¸í·É¾î¸¦ ½ÇÇà Çϱâ À§ÇØ ¸Æ½º¸¶Àεå»çÀÇ È¸¿ø °¡ÀÔ °ú ¶óÀ̼±½º Å°¸¦ ¹ß±Þ ¹Þ¾Æ¾ß ÇÑ´Ù.
±×¸®°í /etc/GeoIP.conf ÆÄÀÏ¿¡¼ ¶óÀ̼±½ºÅ° µî·ÏÀ» ÁøÇàÇØ¾ß ÇÑ´Ù.
1 2 | AccountID 123456 LicenseKey ABCDEFGHIJKL |
ÀÌÈÄ geoipupdate¸í·É¾î¸¦ ÅëÇؼ ¾÷µ¥ÀÌÆ®°¡ Àß µÇ³ª ½ÇÇàÇغ¸¸é µÈ´Ù.
1 | ~]# geoipupdate |
Ãâó : https://dev.maxmind.com/geoip/geoipupdate/
´Ù¸¥ ¹æ¹ýÀ¸·Î´Â ±âÁ¸ ó·³ ½ºÅ©¸³Æ®¸¦ ÀÌ¿ë ÇÏ¿© ¹Ù²ï URL ¿¡ ÆĶó¸ÞÅÍ·Î ¶óÀ̼±½º Å°¸¦ ³Ö¾î¼ È£ÃâÇÏ´Â ¹æ¹ýÀÌ ÀÖ´Ù.
°³ÀÎ ÀûÀ¸·Î ³²ÀÌ ¸¸µç ÇÁ·Î±×·¥ º¸´Ü Á÷Á¢ ÇÏ´Â ½ºÅ©¸³Æ®¸¦ ¼±È£ÇÏ´Â ÆíÀ̶ó.. (OS ÀÇÁ¸¼ºµµ ¾ø´Â ÆíÀÌ°í Çؼ ¡® ¤µ¡¯a)
½ºÅ©¸³Æ® 3 ¹ø° ÁÙ¿¡ À§ ¹æ¹ýÀ» µû¶ó ¸¸µç maxmind ¶óÀ̼±½º Å°¸¦ ÀÔ·ÂÇØ¾ß ÇÑ´Ù.
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 | #!/bin/bash ################################# Maxmind_Licensekey="ABCDEFGHIJKL" ################################# CITYDATA="N" ### config - DISABLE city it'll be need free memory 2GB ### geoip set GEOIPDIR="/usr/share/GeoIP" DATALINK="/usr/share/xt_geoip /var/lib/GeoIP" ### avoid overlap lockfile=/var/lock/$(basename $0) if [ -f $lockfile ];then P=$(cat $lockfile) if [ -n "$(ps --no-headers -f $P)" ];then exit 1 fi fi echo $$ > $lockfile trap 'rm -f "$lockfile"' EXIT ### define server are primary or secandary. ### install dependances if [[ -z $(which git) ]];then sudo yum -y install git > /dev/null 2>&1 ;fi if [[ -z $(which pip) ]];then sudo yum -y install python2-pip > /dev/null 2>&1;fi if [[ -z $(pip list|grep pygeoip) ]];then sudo pip install pygeoip > /dev/null 2>&1 ;fi if [[ -z $(pip list|grep ipaddr) ]];then sudo pip install ipaddr > /dev/null 2>&1 ;fi ### link path if [[ ! -d $GEOIPDIR ]];then mkdir -p $GEOIPDIR fi for a in $DATALINK do if [[ ! -d $a ]];then if [[ $(readlink $a) != $GEOIPDIR ]];then rm -rf $a;ln -s $GEOIPDIR $a fi;fi done ### https://github.com/sherpya/geolite2legacy - csv to data file. cd $GEOIPDIR if [ ! -e $GEOIPDIR/geolite2legacy/geolite2legacy.py ];then cd $GEOIPDIR git clone https://github.com/sherpya/geolite2legacy.git fi ### make GeoIP.dat files from GeoLite2 CSV file. if [ -d $GEOIPDIR/geolite2legacy ];then cd $GEOIPDIR/geolite2legacy EXT="zip" CIF="GeoLite2-City-CSV" COF="GeoLite2-Country-CSV" BASEURL="https://download.maxmind.com/app/geoip_download?edition_id" COF_URL="$BASEURL=$COF&license_key=$Maxmind_Licensekey&suffix=$EXT" ORI_DATE=$(date +"%Y%m%d%H%M.%S" -d "$(curl -sI $COF_URL|grep ^Last-Modified:|cut -d, -f2)") CSV_DATE=$(date +"%Y%m%d%H%M.%S" -d "$(stat -c %y $COF.$EXT)") if [[ "$ORI_DATE" != "$CSV_DATE" ]];then rm -f $COF.$EXT $CIF.$EXT wget "$COF_URL" -O $COF.$EXT >/dev/null 2>&1 if [ -s $GEOIPDIR/geolite2legacy/$COF.$EXT ];then python geolite2legacy.py --input-file $COF.$EXT --fips-file geoname2fips.csv --output-file GeoIP.dat python geolite2legacy.py --input-file $COF.$EXT -6 --fips-file geoname2fips.csv --output-file GeoIPv6.dat fi if [[ $CITYDATA == "Y" ]];then CIF_URL="$BASEURL=$CIF&license_key=$Maxmind_Licensekey&suffix=$EXT" wget "$CIF_URL" -O $CIF.$EXT >/dev/null 2>&1 python geolite2legacy.py --input-file $CIF.$EXT --fips-file geoname2fips.csv --output-file GeoLiteCity.dat python geolite2legacy.py --input-file $CIF.$EXT -6 --fips-file geoname2fips.csv --output-file GeoLiteCityv6.dat touch -t $ORI_DATE GeoLiteCity.dat GeoLiteCityv6.dat mv -f Geo{LiteCity,LiteCityv6}.dat $GEOIPDIR/ >/dev/null 2>&1 fi touch -t $ORI_DATE GeoIP.dat GeoIPv6.dat $COF.$EXT mv -f Geo{IP,IPv6}.dat $GEOIPDIR/ >/dev/null 2>&1 fi fi exit 0 |
±âÁ¸ ½ºÅ©¸³Æ®¿¡¼ Ãß°¡ º¯°æµÈ ±â´ÉÀÌ Àִµ¥ DB ¾÷µ¥ÀÌÆ®°¡ ÀÌ·ç¾î Á³´ÂÁö ¹èÆ÷ÁÖ¼ÒÀÇ HEAD üũ¸¦ ÅëÇؼ Last-Modified ¸¦ üũ ÇÑ´Ù.
½±°Ô ¸»ÇÏ¸é ¸Æ½º¸¶Àεå»ç¿¡¼ »õ·Î¿î db¸¦ ¾÷µ¥ÀÌÆ® ÇÒ¶§¸¸ ÀÛµ¿ ÇÑ´Ù´Â ¼Ò¸®´Ù. ( ´õ ½±°Ô: ¸ÅÀÏ µ¹¸®¸é µÈ´Ù. )
¶§¹®¿¡ À§ ½ºÅ©¸³Æ®´Â /etc/cron.daily/ Æú´õ³»¿¡ ³Ö¾îµÎ¸é ÇÊ¿äÇÒ ¶§ ÀÚµ¿ ½ÇÇàÀÌ µÈ´Ù.
Ãâó : https://dev.maxmind.com/geoip/geoip-direct-downloads/#Direct_Downloads