Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TakumaKume_kixs_vol002

Takuma Kume
December 02, 2016

 TakumaKume_kixs_vol002

九州インフラ交流勉強会(Kixs) Vol.002
https://kixs.connpass.com/
ホスティングにおける柔軟かつ軽量なアクセス制御の必要性とその実装
@takumakume

Takuma Kume

December 02, 2016
Tweet

More Decks by Takuma Kume

Other Decks in Technology

Transcript

  1.     ࣌ ࣌ ࣌ ࣌ ࣌ ࣌

    ࣌ ࣌ ࣌ ͋ΔαʔόͷϦιʔεফඅྔ <> 
  2.     ࣌ ࣌ ࣌ ࣌ ࣌ ࣌

    ࣌ ࣌ ࣌ શମ ͋ΔαʔόͷϦιʔεফඅྔ <>  ಛఆͷϑΝΠϧ ಛఆͷ࣌ؒʹେྔʹΞΫηε͕͋Δ
  3.     ࣌ ࣌ ࣌ ࣌ ࣌ ࣌

    ࣌ ࣌ ࣌ શମ ͋ΔαʔόͷϦιʔεফඅྔ <>  ಛఆͷϑΝΠϧ ಛఆͷϑΝΠϧͷॲཧͰϦιʔεͷ΄ͱΜͲΛফඅ͠ ఆظతʹଞͷ͓٬༷΁ͷαʔϏεఏڙʹࢧোΛ͖͍ͨͯͨ͠ɻ
  4.     ࣌ ࣌ ࣌ ࣌ ࣌ ࣌

    ࣌ ࣌ ࣌ શମ ಛఆͷϑΝΠϧ ղܾํ๏ <>  ෛՙͷߴ͍ϑΝΠϧʹରͯ͠ ࣌ؒࢦఆͰ੍ޚ͢Δ
  5. ಈ࡞֓ཁ   ਌ NSVCZ 8PSLFS NSVCZ 8PSLFS NSVCZ IUUQE

    ڞ༗ϝϞϦ global mutex ಉ࣌઀ଓ਺ Χ΢ϯλʔ KVS ಉ࣌઀ଓ਺Χ΢ϯλʔ localmemcacheΛ༻͍ͨ Key-Value-Store Ωʔͱͨ͠ϦΫΤετύϥϝʔ λΛݩʹಉ࣌ΞΫηε਺ΛΧ ΢ϯτ͢Δɻ global mutex ֤Worker͔Βಉ࣌઀ଓ਺Χ ΢ϯλʔΛૢ࡞͢ΔͨΊෆ੔ ߹͕ൃੜ͠ͳ͍Α͏ʹ౎౓ϩο ΫΛߦ͏ɻ KEY /path/to/hoge.php VALUE 1
  6. ಈ࡞֓ཁ   ਌ NSVCZ 8PSLFS NSVCZ 8PSLFS NSVCZ IUUQE

    ڞ༗ϝϞϦ global mutex ಉ࣌઀ଓ਺ Χ΢ϯλʔ KVS  ϦΫΤετ  ϦΫΤετ  NVUFYΛϩοΫ  MPDL  ϦΫΤετύϥϝʔλΛΩʔ ʹΠϯΫϦϝϯτ  ΠϯΫϦϝϯτ KEY /path/to/hoge.php VALUE 1  VOMPDL  NVUFYΛΞϯϩοΫ
  7. ಈ࡞֓ཁ   ਌ NSVCZ 8PSLFS NSVCZ 8PSLFS NSVCZ IUUQE

    ڞ༗ϝϞϦ global mutex ಉ࣌઀ଓ਺ Χ΢ϯλʔ KVS  ίϯςϯπͷॲཧΛߦ͏  NVUFYΛϩοΫ  MPDL  σΫϦϝϯτ  σΫϦϝϯτ  VOMPDL  NVUFYΛΞϯϩοΫ KEY /path/to/hoge.php VALUE 0  ίϯςϯπͷॲཧ
  8. ػೳ௥ՃΠϝʔδ  ਌ NSVCZ 8PSLFS NSVCZ 8PSLFS NSVCZ IUUQE ڞ༗ϝϞϦ

    global mutex ಉ࣌઀ଓ਺ Χ΢ϯλʔ KVS ੍ޚ৚݅ localmemcacheΛ༻͍ͨ Key-Value-Store ϑΝΠϧͷϑϧύε͕Ωʔ ࠷େಉ࣌઀ଓ਺ ੍ݶΛ༗ޮԽ͢Δ࣌ؒଳ KVS ੍ޚ৚݅
  9. ੍ݶ৚݅ͷσʔλ /path/to/hoge.php { "max_clients" : 30, # ࠷େಉ࣌઀ଓ਺ "time_slots" :

    [ # ༗ޮʹ͢Δ࣌ؒଳ { "begin" : 1200, "end" : 1800 }, { "begin" : 2100, "end" : 2200 } ] } KEY VALUE A Aͷؒ͸AQBUIUPIPHFQIQA΁ͷ ࠷େ઀ଓ਺ΛAA·Ͱʹ੍ݶ͢Δɻ 
  10. ػೳ௥Ճޙͷಈ࡞֓ཁ  ਌ NSVCZ 8PSLFS NSVCZ 8PSLFS NSVCZ IUUQE ڞ༗ϝϞϦ

    global mutex ಉ࣌઀ଓ਺ Χ΢ϯλʔ KVS KVS ੍ޚ৚݅  ϦΫΤετ  ϦΫΤετ  ੍ޚ৚݅ Λࢀর  ੍ޚ৚݅Λࢀর ɹɹଘࡏ͠ͳ͚Ε͹ॲཧऴྃ  NVUFYΛϩοΫ  MPDL  ϑΝΠϧͷϑϧύεΛΩʔʹ ΠϯΫϦϝϯτ  ΠϯΫϦϝϯτ  ΋੍͠ݶ͕༗ޮͳ࣌ؒଳͰಉ ࣌઀ଓ਺੍ݶΛ௒ա͍ͯ͠Ε͹ ΤϥʔΛฦ͢
  11. ࢖͍ํ IUUQEDPOG LoadModule mruby_module modules/mod_mruby.so <IfModule mod_mruby.c> # Apacheͷϓϩηε͕ىಈͨ࣌͠ʹϑοΫ͞ΕΔ #

    http-access-limiterͷΫϥεΛఆٛɺ࣍ʹىಈ͢ΔWorker͕ࢀরͰ͖ΔΑ͏ʹ͢Δɻ mrubyPostConfigMiddle /etc/httpd/conf.d/access_limiter/access_limiter_init.rb cache <FilesMatch ^.*\.php$> # ΞΫηε͕ൃੜͨ͠ͱ͖ʹϑοΫ͞ΕΔ # ಉ࣌઀ଓ਺Χ΢ϯλΛΠϯΫϦϝϯτ͢Δ # ͞Βʹɺ࠷େಉ࣌઀ଓ਺Λ௒աͨ͠৔߹ʹ503ΤϥʔΛฦ͢ͳͲͷΞΫγϣϯΛهड़͢Δɻ mrubyAccessCheckerMiddle /etc/httpd/conf.d/access_limiter/access_limiter.rb cache # ίϯςϯπͷॲཧ͕ऴΘͬͨͱ͖ʹϑοΫ͞ΕΔ # ಉ࣌઀ଓ਺Χ΢ϯλΛσΫϦϝϯτ͢Δ mrubyLogTransactionMiddle /etc/httpd/conf.d/access_limiter/access_limiter_end.rb cache </FilesMatch> </IfModule> 
  12. ύϑΥʔϚϯεςετ݁Ռ abΛ࢖ͬͯύϑΥʔϚϯεΛଌఆ͠·ͨ͠ɻ ςετύλʔϯ ྼԽ཰ httpd 0% httpd + http-access-limiter 3%

    httpd + http-access-limiter (੍ݶର৅) 5% WordPress΁ͷΞΫηε 10ສϦΫΤετ100ଟॏ / CPU24ίΞɾRAM32GB ςετύλʔϯ ྼԽ཰ httpd 0% httpd + http-access-limiter 3% httpd + http-access-limiter (੍ݶର৅) 30% phpinfo()΁ͷΞΫηε  ࢀߟࢿྉ