ä»æ¥ã¯ãIPã¢ãã¬ã¹ã«ããå°çäœçœ®æ
å ±ã«é¢ããããå€ããããã¯ãšããããã°ã©ãã³ã°èšèªãã䜿çšããªãé«éWebãµãŒãã¹ã«é¢ããæ°ãããããã¯ãåãäžããŸãã ã ãŸãããã®ãããªWebãµãŒãã¹ã5åã§ãããã€ã§ããããã«ãã³ã³ãããŒã®æ¢è£œã®ã€ã¡ãŒãžãå
¬éããŸãã
åœç€Ÿã¯ç¬èªã®SaaSãã©ãããã©ãŒã ïŒ ABCP.RU ïŒã§ãªã³ã©ã€ã³ããŒãã¹ãã¢ãäœæããŠããŸãããŸãã 4MyCar.ruã¹ãã¢ããŒãæ€çŽ¢ãµãŒãã¹ãªã©ãããã€ãã®é¢é£ãããžã§ã¯ãããããŸãã
ä»ã®å€ãã®Webãããžã§ã¯ããšåæ§ã«ãIPã¢ãã¬ã¹ã«ããå°çäœçœ®æ
å ±ã®å¿
èŠæ§ãç解ããããã«ãªããŸããã ããšãã°ã 4MyCar.ruã§å°åã決å®ããããã«äœ¿çšãããããã«ãªããŸããïŒæåã«ãµã€ãã«ã¢ã¯ã»ã¹ãããšãå°åã¯èªåçã«ãã®ããã«èšå®ãããŸãïŒã
åæ§ã«ã顧客ã«æãè¿ãåºèæ¯åºã®éžæã¯ãABCPãã©ãããã©ãŒã ã®é¡§å®¢ã®Webãµã€ãã§è¡ãããŸãã
ãžãªãã±ãŒã·ã§ã³ã®åé¡ãæåã«çŸãããšããç§ãã¡ã¯ãã®åé¡ã®ç 究ãå§ããã°ããã§ããã å®éã®ãšãããåœæã MaxMindããŒã¿ããŒã¹ä»¥å€ã«ã¯ç¹å¥ãªä»£æ¿æ段ã¯ãããŸããã§ããã ç§ãã¡ã¯è©Šããéã³ãèŠæšãŠãŸããã å®éã®äœæ¥ã§ã¯ã顧客ã®ãµã€ããç©ã¿éããããšããç¹ã«è¿·æãªããããé€å€ããããã«ãMaxMind GeoLiteãæ°å䜿çšããŸããã
ïŒnginxã§åœå¥ã«ãã£ã«ã¿ãªã³ã°ããã ãã§ååã§ãããåºæ¬çãªãã§ãã¯ã€ã³ã®å Žåã¯ãããã¥ã¡ã³ãngx_http_geoip_moduleãåç
§ããŠãã ããïŒã ç¡æã®ããŒã¿ããŒã¹ã§ã¯ãRUã§ååãªç²ŸåºŠãåŸããããã©ãã³ã¢ã«ãã¡ãããã®éœåžåãå«ãŸããŠãããããä»ã®ç®çã«ã¯ããŸãé©ããŠããŸããã§ããã
ãã°ããããŠãåŸæ¥å¡ã®1人ãåªãããµã€ãipgeobase.ruãèŠã€ããŸãããããã«ããããã·ã¢ãšãŠã¯ã©ã€ãã®å°çäœçœ®æ
å ±ããŒã¿ããŒã¹ããããŠã³ããŒããããç°¡åãªhttpãªã¯ãšã¹ãã§ãã®XML WebãµãŒãã¹ã䜿çšã§ããŸãã ããšãã°ã察å¿ããéœåžããããŠãªã¥ãã³ã¹ã¯ã§ãªã€ã«ãã£ã«ã¿ãŒã賌å
¥ããããšãããã¬ãŒãºãå«ã4mycar.ru Webãµã€ãã«åãæ¿ãããšãWebãµãŒãã¹http://ipgeobase.ru:7020/geo?ip=217.149.183.4ãžã®ã»ãŒæ¬¡ã®ãªã¯ãšã¹ããçºçããŸããã çµæã«ã¯ããã·ã¢èªã§ã®éœåžãšå°åã®ååãå«ãŸããŠãããéåžžã«äŸ¿å©ã§ããã éåžžã«çãæéã§ãæãè¿ãåºèã®æ¯åºãèå¥ããã³ãŒãã«WebãµãŒãã¹ã®äœæ¥ãé¢äžããŸããã ãã ããå®çšŒåç°å¢ã§ã®èµ·ååŸãããã€ãã®åé¡ãæããã«ãªããŸããã
1ïŒéåžžãWebãµãŒãã¹ãžã®ãªã¯ãšã¹ãã«ã¯å°ãæéãããããŸããïŒã¢ã¹ã¯ã¯ã®ããŒã¿ã»ã³ã¿ãŒããã®éåžžã®ç¶æ
ã§ã¯100åã®1ç§ïŒããå°åã®éçºãªãã£ã¹ããã®é
延ã¯ãã§ã«å€§ããã£ãïŒçŽ0.5ç§ïŒã
2ïŒææïŒãããŒã¯æéãã®èŠ³å¯ã«ãããšïŒãã®æéã¯èããé·ããªãã顧客ãžã®å¯Ÿå¿ã«ãã§ã«äžå¿«ãªé
ããçããŸããã
3ïŒããŸããŸåãã¯ã©ã€ã¢ã³ãã§ãžãªãã±ãŒã·ã§ã³ãå®è¡ããå¿
èŠãäœåºŠããã£ãããããžãªããŒã¿ã®ãã£ãã·ã³ã°ã«ã€ããŠçåãçããŸããã
4ïŒæé©ã§ãªããªã¯ãšã¹ãã§ãipgeobase WebãµãŒãã¹ã«è² è·ããããŸããããããã¯ãµãŒãã¹ææè
ã«ãšã£ãŠã¯æªãããšã§ããã
5ïŒä»ã®åœïŒRUã§ãUAã§ããªãïŒã§ã¯ããžãªãã±ãŒã·ã§ã³ã¯æ©èœããŸããã§ããã
ãããã®åé¡ã解決ããããã«ãç§ãã¡ã¯ããã«ãäŒè°ããŸãšããã
2ã€ã®äž»ãªãœãªã¥ãŒã·ã§ã³ãªãã·ã§ã³ããããŸããããŒã¿ããŒã¹ãååŸããŠWebãµãŒãã¹ãäœæããŸãïŒå®æçã«ipgeobaseããŒã¿ããŒã¹ãããŠã³ããŒãããããŒã¿ããŒã¹ã«ã€ã³ããŒãããããšãã°memcachedã«ãã£ãã·ã³ã°ã§httpçµç±ã§éä¿¡ããŸãïŒãŸãã¯memcachedãŸãã¯redisã§ãžãªããŒã¿ãã£ãã·ã³ã°ãè¡ããŸãïŒããŒã¿ããªã¯ãšã¹ãããŸãïŒ ipgeobaseããã³ãã£ãã·ã³ã°ïŒã ãªããã³ãã§ã¯ãäž¡æ¹ã®ãªãã·ã§ã³ã«éåžžã«å€ãã®éçºè
ã®éåžžã«å°ãªãå·¥æ°ãå¿
èŠã§ããããã®çµæã3çªç®ã®ãªãã·ã§ã³ãèŠã€ãããŸããïŒç²ŸåºŠããããã«äœäžããŸãïŒIPã¢ãã¬ã¹ã®æåŸã®ãªã¯ãããã0ã«çœ®ãæãããããã€ããŒãç°ãªãéœåžã«1/24ãµãããããæã£ãŠãããšä»®å®ããŸãããŸãã«ãé »ç¹ã«ïŒãããŠãé·ããã£ãã·ã¥æéãšipgeobaseãžã®ãªã¯ãšã¹ãã®çãã¿ã€ã ã¢ãŠãã§ãnginxã§ãã£ãã·ã¥ãããã·ãå®è¡ããŸãã ãã®ãªãã·ã§ã³ã¯éåžžã«å¹æçã§ããããšãå€æããæã«ã¯ipgeobaseã®è² è·ãšãžãªãã±ãŒã·ã§ã³æéãåæžããŸããã ç¬èªã®WebãµãŒãã¹ã®ãªãã·ã§ã³ã¯ç¡æéã«å»¶æãããŸããã
ãã°ããããŠãåã³nginxã§ãžãªãã±ãŒã·ã§ã³ãå¿
èŠã«ãªããŸããïŒããããããã®ãããã§ãããçŸåšã¯RUããããªãå€ããªã£ãŠããŸãïŒããããã£ãŠãMaxMindããŒã¿ããŒã¹ã«åŸã£ãŠåœå¥ã«ãã£ã«ã¿ãªã³ã°ããã ãã§ã¯ååã§ã¯ãããŸããã
ç·æ¥ã«å¿
èŠã ã£ããããå¥ã®ãžãªã¢ãžã¥ãŒã«ïŒ ngx_http_geo_module ïŒã䜿çšããipgeobaseããŒã¿ããŒã¹ããå°åçªå·ãå€æ°ã«å°ããŸããã ããã¯ãç©Žãå¡ããã®ã«ååã§ããã
ããã«ipgeobase2nginx.phpã¹ã¯ãªããã«ééããŸããããã®ã¹ã¯ãªããã¯nginxã®ããŒã¹ãäœæãããã®çµæãéœåžã«ã€ããŠã®äººéãèªã¿åããæ
å ±ãå€æ°ã§åãåããŸããã ãã®ããŒã¿ã¯ãMaxMindããŒã¿ãšåæ§ã«ããã§ã«ãã°ã«åºåãããŠããããããã¯ãšã³ãã®ããããŒã«æž¡ãããŠããå¯èœæ§ããããååãšããŠèª°ã«ãšã£ãŠã䟿å©ã§ããã
ãã®éãã£ãšãç§ãã¡ã¯å®æçã«ãããªãéçºã«ã€ããŠèããŸããã ç¬èªã®WebãµãŒãã¹ãäœæããããã®èšç»ã¯ãTODOãªã¹ãã«ã»ãããéãããããããä»å€ããã§python / erlang / haskell /ãªã©ãå匷ããŠããHello worldãã®æ¬¡ã®èšäºãæžãããã§ããïŒããšãã圢ã§æã
çŸããŸãããããããã¯å
ã«é²ã¿ãŸããã§ããã
çªç¶ãåè«ã®åœ¢ã§ïŒæ¥œãã¿ã®ããã ãã«ïŒãnginxã®çµéšã«åºã¥ããŠãipgeobaseã«äŒŒãWebãµãŒãã¹ãäœæãããšããã¢ã€ãã¢ãçãŸããŸããããããŒã¿ããŒã¹ãšã³ãžã³ãšã¹ã¯ãªããèšèªã¯äœ¿çšããŠããŸããã
ãã®çµæãåŸãããããšã®ç°¡åãªåæïŒ
1ïŒãããªãã¯ãã¡ã€ã³ã§ã¯ãããã¹ãã«csvããã³ipgeobaseã«GeoLiteããŒã¿ããŒã¹ããããŸãã
2ïŒ ngx_http_geo_moduleã¢ãžã¥ãŒã«ã¯ãå€æ°ã®å€ãIPã¢ãã¬ã¹ã§èšå®ã§ããŸãããŸããéåžžã«é«éã§ãïŒãã€ããªãžãªã¬ã³ãžããŒã¹ã䜿çšããŠé«éåããŸãïŒã
3ïŒRUããã³UAã«ã€ããŠã¯ãipgeobaseãä¿¡é ŒããŸãããå¯èœã§ããã°ãMaxMindããŒã¿ã衚瀺ããå¿
èŠããããŸãã
4ïŒnginxã¯ssiïŒ ngx_http_ssi_module ïŒãå®å
šã«å®è£
ããŸããããã¯ãããã¹ã/ htmlã ãã§ãªããä»ã®ãã¡ã€ã«ã¿ã€ãã«å¯ŸããŠãåæ§ã§ãã
5ïŒnginxã¯ãªã¯ãšã¹ãããããŒããIPã¢ãã¬ã¹ãååŸãããããã¯ã©ã€ã¢ã³ãã®IPã¢ãã¬ã¹ïŒ ngx_http_realip_module ïŒã§ãããšæ³å®ã§ããŸããããã¯ãgeoã¢ãžã¥ãŒã«ã«æž¡ãããšãæå³ããŸãã
csvãã¡ã€ã«ãšipgeobaseãã¡ã€ã«ããnginxã«å¿
èŠãªèšå®ãäœæããããã€ãã®ãããŒãã€ãã¹ã¯ãªãããè¿œå ããããšã¯æ®ã£ãŠããŸãã
ååŸãããã®ã¯æ¬¡ã®ãšããã§ãã
https://yadi.sk/d/QsNN87nMesXo8-æ§æãšã¹ã¯ãªããã
åäœäžã®WebãµãŒãã¹ã衚瀺ããããã«ã httpïŒ//muxgeo-demo.4mycar.ruïŒ 6280 / muxgeo /ã§å©çšå¯èœãªVDSã«äžæçã«å±éããŸããã
ãã®ãããªãµãŒãã¹ãèªåã§ãã°ããèµ·åããã«ã¯ãå®æããLXCã€ã¡ãŒãžïŒ https://yadi.sk/d/1WrvV2RyesYFM ïŒãã°ã€ã³ïŒãã¹ã¯ãŒã-ubuntuïŒubuntuïŒïŒãããŠã³ããŒãã§ããŸãã
ã¹ã¯ãªããã®åäœã®ç°¡åãªèª¬æã以äžã«ç€ºããŸããLXCã§ã¯ãã¹ã¯ãªããã/ opt / scriptsã«é
眮ããŸãã
ãµããã£ã¬ã¯ããªã®/ opt / scripts /ã«ãMaxMindãšipgeobaseããåãåã£ããã¡ã€ã«ãå
¥ããŠãå°ãåŠçããå¿
èŠããããŸãïŒæ¬¡ã®ãããªãã®ã§ãïŒã
iconv -f latin1 GeoLiteCity-Location.csv | iconv -t ascii // translit> GeoLiteCity-Location-translit.csv
åäœããã«ã¯ãMaxMindããè¿œå ã®ãã¡ã€ã«ãšé åã®ååãå¿
èŠã§ãã
dev.maxmind.com/static/csv/codes/maxmind/region.csv
ããã§ãã¹ã¯ãªããèªäœïŒ
GeoLite2nginx.pl-ãã¡ã€ã«ãçæããŸã/ nginx_geoip_ *
ipgeobase2nginx.pl-out / nginx_ipgeobase_ *ãã¡ã€ã«ãçæããŸã
geoipãšipgeobaseã§IPç¯å²ããªãŒããŒã¬ã€ããå¿
èŠããããŸãã ãããè¡ãã«ã¯ãæåã®2ã€ã®ã¹ã¯ãªãããå®è¡ãããšãIPã¢ãã¬ã¹ã®æŽæ°è¡šçŸïŒout / nginx_geoip_num.txtããã³out / nginx_ipgeobase_num.txtïŒã§ãã¡ã€ã«ãäœæãããŸããã /nginx_localip_num.txtã«ãã¡ã€ã«ãæåã§äœæããããã«äºçŽç¯å²ïŒããŒã«ã«ãããã¯ãŒã¯ãªã©ïŒã®ãªã¹ããé
眮ããŸããã ããã«ãçµæãªã¹ããããã«ããã£ã¹ãã¢ãã¬ã¹ã®ç¯å²ãé€å€ããŸãã
æ¹æ³ïŒ
make-dup-ranges.plã¹ã¯ãªããã¯ãªã¹ãã調ã¹ãŠãå¶æ°IPïŒæ°ããç¯å²ã®éå§ïŒããšã«åã®ïŒåã®ç¯å²ã®çµããïŒããªã¹ãã«è¿œå ããå¥æ°ããšã«æ¬¡ã®ãã®ãè¿œå ããŸãã 次ã«ããªã¹ãã䞊ã¹æ¿ããéè€ãåé€ããŸãã
make-ranges.plã¹ã¯ãªããã¯ãnginxã®ç¯å²ãæã€ãã®ãããªæ§æãäœæããŸãã
nginxã®èšå®ãã§ããŸããã®ã§ãããããæ¥ç¶ããå¿
èŠããããŸãã
ç§ãã¡ã®ã¹ããŒã ã¯ãããã³ããšã³ããšããã¯ãšã³ãã§æ§æãããŸãïŒããã³ããšã³ãã¯ããããŒå€æãšãã£ãã·ã³ã°ã䌎ãããã¯ãšã³ãèŠæ±ãéä¿¡ããŸãïŒã ããã¯ãã¹ãŠãLXCã³ã³ããã®ubuntu 14.04ã§è¡ããŸããå
¬åŒãµã€ãããnginxãååŸããŸãã
ããã«ã³ã³ãã³ããæ²èŒããŸãã
/ etc / nginx / muxgeo /ããŒã¿/
å¿
èŠãªå€æ°ãèšå®ããããã€ã³ãã£ã³ã°ããäœæããŸãããã
/etc/nginx/muxgeo/muxgeo.conf
/etc/nginx/muxgeo/muxgeo-geoip.conf
/etc/nginx/muxgeo/muxgeo-ipgeobase.conf
ãŸããããã¯ãšã³ãã®ããªããã£ãããžãã¯ïŒ
/etc/nginx/muxgeo/muxgeo_site.conf
ããã³ããšã³ããšããã¯ãšã³ãã®æ§æã¯æ¬¡ã®ãšããã§ãã
/etc/nginx/conf.d/muxgeo-frontend.confïŒããŒã6280ã§åŸ
æ©ïŒ
/etc/nginx/conf.d/muxgeo-backend.confïŒããŒã6299ïŒ
ãŸããindex.htmlãªã©ã®ãã¡ã€ã«ãå¿
èŠã§ãããã®ãã¡ã€ã«ã§ã¯ãnginxã®SSIã䜿çšããŠå¿
èŠãªåœ¢åŒã§ããŒã¿ãåºåããŸãã ãã£ã¬ã¯ããªã«é
眮ããŸã
/ opt / muxgeo / muxgeo-backend / muxgeo
ã ãããžã®èŠæ±
http://muxgeo-demo.4mycar.ru:6280/muxgeo/?ip=217.149.183.4
ããã¯ã217.149.183.4ãIPã¢ãã¬ã¹ã«çœ®ãæããŠããã¯ãšã³ãã§ãããŒããã£ã¹ããããããã¯ãšã³ãã¯HTMLããã¹ãã®é©åãªå Žæã«æ
å ±ãæ¿å
¥ããŸãã
ããããhtmlããŒãžã¯ç§ãã¡ãæãã§ãããã®ã§ã¯ãªããipgeobaseã®ããã«xmlãå¿
èŠã§ãã ãã³ãã¬ãŒãã«å¯Ÿå¿ãããã£ãŒã«ãã®åºåãå
¥åããã ãã§ããmuxgeo.xmlãã¡ã€ã«ã®äŸãåç
§ããŠãã ãã
ãªã³ã¯ã§
http://muxgeo-demo.4mycar.ru:6280/muxgeo/muxgeo.xml?ip=217.149.183.4
ipgeobaseã®xmlåºåãšutf-8ã§ããåãããããããè¯ããçµæãåŸãããŸã
JSONãå¿
èŠ-åé¡ãããŸããã åæ§ã«ããã³ãã¬ãŒãã¯æ¬¡ã®ããã«å®è¡ãããŸãã
http://muxgeo-demo.4mycar.ru:6280/muxgeo/muxgeo.json?ip=217.149.183.4
ãšããŸããã¯ã«ããã-iniãã¡ã€ã«ãšããŠåºåããŸãããïŒ
http://muxgeo-demo.4mycar.ru:6280/muxgeo/muxgeo.ini?ip=217.149.183.4
äœæ¥ããã¹ãããããã«ãããšãã°ãäžèšã®çµæïŒ ipgeobase2nginx.php ïŒã®çµæãšåæ§ã®åœ¢åŒã§ããã¹ãŠã®åœã®äœæã«ãžãªããŒã¿ããŒã¹ãäœæã§ããŸãã ãã³ãã¬ãŒãïŒmuxgeo_fullstr.txtïŒãšäœ¿çšå¯èœãªãã¹ãŠã®ç¯å²ã®ããŒã¿ãèªã¿åãåçŽãªã¹ã¯ãªãããå«ãããã¹ããã¡ã€ã«ãäœæããŸãã
å°ããªçºèšã äŸã§ã¯ãããã³ããšã³ããšããã¯ãšã³ãã¯åãnginxã§åäœããŸãã éãè² è·ã®å Žåãgeodataã§ã®ããã¯ãšã³ãã®äœæ¥ã¯proxy_cacheã§ã®æå°ã®nginxãããå€ãã®ã¡ã¢ãªãæ¶è²»ãããããããããç°ãªãnginxã«åå²ããããšã¯çã«ããªã£ãŠããŸãã
ãã®ãããžã§ã¯ãã®ãããªãçºå±ã¯äœã§ããïŒ ããšãã°ãä»ã®ããŒã¿ãœãŒã¹ãè¿œå ããŠãæ§æãå°ãè€éã«ãããä¿¡é Œã§ãããœãŒã¹ããååŸããæŽç·Ž::ããé
眮ã§ãããžãªããŒã¹ãæ¥ç¶ããããšãã§ããŸãã