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

はてなリモートインターンシップ2022 インフラ 講義資料

Hatena
December 19, 2022

はてなリモートインターンシップ2022 インフラ 講義資料

Hatena

December 19, 2022
Tweet

More Decks by Hatena

Other Decks in Programming

Transcript

  1. Web αʔϏε
    Πϯϑϥೖ໳
    #hatenaintern

    View full-size slide

  2. ׆ס铺紶מחַי
    Web

    View full-size slide

  3. 泘域
    !
    Web αʔϏεͷΠϯϑϥͱ͸
    - ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    - αʔόʔઃܭ
    - αʔόʔߏங
    - Ϋϥ΢υαʔϏεͷར༻
    - αʔόʔӡ༻
    - ·ͱΊ

    View full-size slide

  4. ؕ٤نٚכע
    =

    View full-size slide

  5. Web
    Web
    - ΞϓϦέʔγϣϯ
    - ϛυϧ΢ΣΞ
    - OS
    - Ծ૝αʔόʔ
    - ϋʔυ΢ΣΞ(෺ཧαʔόʔͳͲ)
    - ωοτϫʔΫ
    - ϑΝγϦςΟ(ϥοΫɺిݯɺۭௐɺͦΕΒΛઃஔɾӡ༻͢ΔσʔληϯλʔͳͲ)

    View full-size slide

  6. 泘域
    - Web αʔϏεͷΠϯϑϥͱ͸
    !
    ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    - αʔόʔઃܭ
    - αʔόʔߏங
    - Ϋϥ΢υαʔϏεͷར༻
    - αʔόʔӡ༻
    - ·ͱΊ

    View full-size slide

  7. ؕ٤نٚך䙫閁׊יַ׾׆כ
    ( )
    ( )
    ( )
    ( )
    ( )
    כַֹئ٭لت؅䬠❠׌׾ג״מؕ٤نٚ؅㲔杯յ禴䧏׌׾

    View full-size slide

  8. ⺎榫䓪
    ˝ ꤃㲹ֿ颯׀י׵塛ױ׼םַبتطّ؅㲔杯׌׾ג״
    ˝ ַחך׵ئ٭لت؅⮵榫ך׀׾

    View full-size slide

  9. 䦡䍖䓪
    ˝ 靷蕔מ⺬؂׎יقنؚ٭ُ٤ت؅䷉ャ׌׾ג״
    ˝ 䒍鸵מئ٭لت؅⮵榫ך׀׾

    View full-size slide

  10. 㱦⪒䓪
    ˝ ٗ٭ا٭ס车Ⳃ׷ظ٭ذ؅⟊閾׌׾ג״
    ˝ 㱦䑏׊יئ٭لت؅⮵榫ך׀׾
    

    View full-size slide

  11. Ⲗ曍䓪
    ˝ ꄋꊤ氳յ☔氳յ侇ꝴ氳ؤتع؅⯡峎׌׾ג״
    ˝ ׈׼ם׾ئ٭لتס䡗Ꝏמחםֿ׾
    

    View full-size slide

  12. 刎鬁䓪
    ˝ ئ٭لت䡗Ꝏמכ׵םֹ邾ꥭ䓪ס㘃㛻כ梪㗞ס㚺⴫׫㵚䑴׌׾
    ג״
    ˝ ئ٭لت׫ס釐僶מ碛企ׂ䑴ֻ׾׆כֿך׀׾
    

    View full-size slide

  13. 泘域
    - Web αʔϏεͷΠϯϑϥͱ͸
    - ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    !
    αʔόʔઃܭ
    - αʔόʔߏங
    - Ϋϥ΢υαʔϏεͷར༻
    - αʔόʔӡ༻
    - ·ͱΊ
    

    View full-size slide

  14. ئ٭ف٭錃銶
    Web
    

    View full-size slide

  15. N
    ( ) Web3 ૚ΞʔΩςΫνϟ
    ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
    │ │ │ │ │ │
    │ Proxy Server ├───►│ App Server ├───►│ DB Server │
    │ │ │ │ │ │
    └──────────────┘ └──────────────┘ └──────────────┘
    

    View full-size slide

  16. Web
    ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
    │ │ │ │ │ │
    │ Proxy Server ├───►│ App Server ├───►│ DB Server │
    │ │ │ │ │ │
    └──────────────┘ └──────────────┘ └──────────────┘
    Proxy
    Apache
    nginx
    

    View full-size slide

  17. تآ٭ٚلٛطؔס澬⟊
    1
    ( )
    ( )
    

    View full-size slide

  18. ( )
    App
    

    View full-size slide

  19. ⫛Ꝏ⴫
    1.
    2.
    

    View full-size slide

  20. ⫛Ꝏ⴫סقذ٭٤
    /
    

    View full-size slide

  21. /
    ( )
    keepalived VIP DNS
    DB
    /
    VIP FQDN
    

    View full-size slide

  22. VIP
    ┌────────────────┐
    │ │
    ┌───►│ Active Server │
    │ │ │
    │ └────────────────┘
    ┌────────────────┐ │ ▲
    │ │ VIP │ │
    │ Client ├───────┘ │ VRRP
    │ │ │
    └────────────────┘ ▼
    ┌────────────────┐
    │ │
    │ Standby Server │
    │ │
    └────────────────┘
    

    View full-size slide

  23. ٝوٛ؜قذ٭٤
    DNS
    App
    

    View full-size slide

  24. ٞ٭غفٚ٤ئ٭؅✳榫׌׾㕙⺬
    ┌────────────────┐
    │ │
    ┌──►│ Server A │
    │ │ │
    │ └────────────────┘


    ┌──────────┐ ┌───────────────────────────┐ │ ┌────────────────┐
    │ │ │ │ │ │ │
    │ Client ├─────────►│ Server-side load balancer ├────┼──►│ Server B │
    │ │ │ │ │ │ │
    └──────────┘ └───────────────────────────┘ │ └────────────────┘


    │ ┌────────────────┐
    │ │ │
    └──►│ Server C │
    │ │
    └────────────────┘
    

    View full-size slide

  25. ٞ٭غفٚ٤ب٤ء
    2
    

    View full-size slide

  26. ئ٭ف٭ئؕغٞ٭غفٚ٤ب٤ء
    DNS
    SPOF
    

    View full-size slide

  27. ٞ٭غفٚ٤ئ٭
    ˝ 刎鬁ם⮆丆亠䌋
    ˝ ىٜتزؘشؠמ׻׾⺎榫䓪ס䥵⟊
    

    View full-size slide

  28. ٞ٭غفٚ٤ئ٭
    ┌────────────────┐
    │ │
    ┌──►│ Server A │
    │ │ │
    │ └────────────────┘


    ┌──────────┐ ┌───────────────────────────┐ │ ┌────────────────┐
    │ │ │ │ │ │ │
    │ Client ├─────────►│ Server-side load balancer ├────┼──►│ Server B │
    │ │ │ │ │ │ │
    └──────────┘ └───────────────────────────┘ │ └────────────────┘


    │ ┌────────────────┐
    │ │ │
    └──►│ Server C │
    │ │
    └────────────────┘
    

    View full-size slide

  29. DNS
    DNS FQDN IP 1
    DNS
    

    View full-size slide

  30. DNS
    Q1: server.example.com
    A1: 192.0.2.1
    ┌─────────────────┐ ┌────────────────┐ ┌────────────────┐
    │ │ │ │ │ │
    │ DNS Server │◄────────────►│ Client A ├────────►│ Server X │
    │ │ │ │ │ 192.0.2.1 │
    │ │ │ │ ┌────►│ │
    └─────────────────┘ └────────────────┘ │ └────────────────┘
    ▲ ▲ ▲ │
    │ │ │ ┌────────────────┐ │ ┌────────────────┐
    │ │ │ │ │ │ │ │
    │ │ │ │ Client B ├───┼────►│ Server Y │
    │ │ └────────────────►│ │ │ │ 192.0.2.2 │
    │ │ Q2: server.example.com│ │ │ │ │
    │ │ A2: 192.0.2.2 └────────────────┘ │ └────────────────┘
    │ │ │
    │ │ ┌────────────────┐ │ ┌────────────────┐
    │ │ │ │ │ │ │
    │ │ │ Client C ├───┼────►│ Server Z │
    │ └──────────────────────►│ │ │ │ 192.0.2.3 │
    │ Q3: server.example.com│ │ │ │ │
    │ A3: 192.0.2.3 └────────────────┘ │ └────────────────┘
    │ │
    │ ┌────────────────┐ │
    │ │ │ │
    │ │ Client D │ │
    └────────────────────────────►│ ├───┘
    Q4: server.example.com│ │
    A4: 192.0.2.1 └────────────────┘
    

    View full-size slide

  31. ؠٚؕؓ٤عئؕغٞ٭غفٚ٤ب٤ء
    SPOF
    

    View full-size slide

  32. ؞ٔشبٖ
    ˝ 鵭䈱⺸┕յ靷蕔鬭峎յعٚنؔشؠꄈס⯡峎ֿ泘氳
    ˝ Ⲗ冽ע냕ַֿبتطّס邾ꥭ⴫׷ꝧ氦յ鷞榫ؤتعֿ㘃ⱶ׌׾
    ⺎耆䓪ֵֿ׾
    ˝ ؞ٔشبֿٖⲖ׀׷׌ַ׻ֹמؓوٛآ٭ب٘٤؅錃銶׌׾
    

    View full-size slide

  33. ؞ٔشبٖס❆
    Proxy લஈͷΩϟογϡ ProxyʙApp ؒͷΩϟογϡ AppʙDB ؒͷΩϟογϡ
    │ │ │
    │ │ ▼
    │ │ ┌───────┐
    │ │ │ │
    │ ▼ ┌►│ Redis │
    │ ┌───────┐ ┌─────────┐ ┌───────┐ │ │ │ ┌───────┐
    ▼ │ │ │ │ │ │ │ └───────┘ │ │
    ┌────────┐ ┌─────┐ ┌────┤ │ ┌────┤ │ ┌────┤ │ │ │ │
    │ │ │ │ │ │ │ │ │ │ │ │ ├─┘ │ │
    │ Client ├────►│ CDN ├─────►│ LB │ Proxy ├────►│ LB │ Varnish ├────►│ LB │ App │ │ DB │
    │ │ │ │ │ │ │ │ │ │ │ │ ├──────────────►│ │
    └────────┘ └─────┘ └────┤ │ └────┤ │ └────┤ │ │ │
    │ │ │ │ │ │ │ │
    └───────┘ └─────────┘ └───────┘ └───────┘
    

    View full-size slide

  34. Proxy
    CDN (Content Delivery Network)
    Web
    DDoS
    Akamai, CloudFront, Fastly, Cloud are
    

    View full-size slide

  35. Proxy App
    HTTP
    Varnish, nginx
    

    View full-size slide

  36. App DB
    KVS (Key-Value Store)
    Redis, memcached
    

    View full-size slide

  37. 泘域
    - Web αʔϏεͷΠϯϑϥͱ͸
    - ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    - αʔόʔઃܭ
    !
    αʔόʔߏங
    - Ϋϥ΢υαʔϏεͷར༻
    - αʔόʔӡ༻
    - ·ͱΊ
    

    View full-size slide

  38. ئ٭ف٭啶疣
    ˝ 擻杼ئ٭ف٭
    ˝ ♞䘶ئ٭ف٭
    ˝ ؤ٤طػ
    ˝ ؤ٤طػ؛٭آتعٝ٭ب٘٤
    

    View full-size slide

  39. ئ٭ف٭סٚؕنئؕؠٜ
    - ܭը
    - ௐୡ
    - ಋೖ
    - ߏங
    - ӡ༻ɾอक
    - ഇغ
    

    View full-size slide

  40. 擻杼ئ٭ف٭
    ˝ 榫鵍מ⺬؂׎ג刎鬁םـ٭غؘؗؓ啶䡗
    ˝ ـ٭غؘؗؓס䓪耆؅نٜמ孨榫ך׀׾
    ˝ ٍعٜؾشؠ؅꣘չױךؤ٤عٞ٭ٜך׀׾
    

    View full-size slide

  41. 擻杼ئ٭ف٭ס鐐갭
    ˝ ׌ף׷ׂتآ٭ٜך׀םַ
    ˝ 鐧鷼յ㵵⪌מ侇ꝴ氳յ☔氳ؤتعֿ־־׾
    ˝ ـ٭غؘؗؓٛخ٭تס⛷Ⱍֿ⭳י׊ױַⲖ曍䓪ֿ䖾ַ
    1
    

    View full-size slide

  42. ♞䘶ئ٭ف٭
    Web ( )
    - ΞϓϦέʔγϣϯ
    - ϛυϧ΢ΣΞ
    - OS
    - Ծ૝αʔόʔ
    - ϋʔυ΢ΣΞ(෺ཧαʔόʔͳͲ)
    - ωοτϫʔΫ
    - ϑΝγϦςΟ
    1
    

    View full-size slide

  43. ♞䘶⴫䤗软
    CPU
    Xen, KVM
    

    View full-size slide

  44. ♞䘶ئ٭ف٭סْٛشع
    /
    ( )
    

    View full-size slide

  45. ...
    /OS
    

    View full-size slide

  46. ؤ٤طػ
    Docker
    !
    

    View full-size slide

  47. ؤ٤طػכ♞䘶ئ٭ف٭כס鷿ַ
    OS
    OS
    OS
    CPU
    

    View full-size slide

  48. ؤ٤طػ؛٭آتعٝ٭ب٘٤
    Kubernetes, ECS
    

    View full-size slide

  49. Kubernetes
    EKS, GKE, AKS Kubernetes
    !
    Kubernetes
    

    View full-size slide

  50. ًشع־׼㳃槹յאס⩝׫
    ˝ 擻杼ئ٭ف٭
    ˝ ל׿דׄꝎׂ㱦㲊׊י牧⥸׈׎׾־ֿꄆ釐ն㛻⮉מْ٤طػ٤ت׌׾
    ˝ ♞䘶ئ٭ف٭
    ˝ ֹױׂⳂ־םׄ׿ף⛼׽泡׌
    ˝ ؤ٤طػ
    ˝ ꥗⺬כ׊י僿䏨׊ג敯䛜מם׾׻ֹמ禴䧏٬⹜兠׈׿׾
    

    View full-size slide

  51. 泘域
    - Web αʔϏεͷΠϯϑϥͱ͸
    - ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    - αʔόʔઃܭ
    - αʔόʔߏங
    !
    Ϋϥ΢υαʔϏεͷར༻
    - αʔόʔӡ༻
    - ·ͱΊ
    

    View full-size slide

  52. ئ٭لتס䡗Ꝏמכ׵םֹ鐐갭
    /
    

    View full-size slide

  53. ؓوٛآ٭ب٘٤ס邾ꥭ⴫
    ˝ ٓؿٛبشؠؓ٭؞طؠزٔ
    ˝ 㚺催ס䏅ꮶֿ㛻׀ׂם׽յꝧ氦鵭䈱ֿ⛥┖׌׾
    ˝ لٜغ׷ظوٞؕמ侇ꝴֿ־־׽յ׌ף׷ׂٛٛ٭تך׀ם
    ַ
    

    View full-size slide

  54. ُؕؠٞئ٭لتؓ٭؞طؠزٔס䫑榫
    !
    

    View full-size slide

  55. /
    ˝ 鷞榫٬⟊㱤ס☔氳յ侇ꝴ氳ؤتعֿ㘃ֻ׾
    ˝ 敯䛜ס䤧䭂כ禴䧏ֿꦘ׊ׂם׾
    ˝ 㵚䑴ֿ鷐׿׾כج؞ٖٛطؔؕ٤بظ٤عמ氦㷣׌׾⺎耆䓪
    ׵냕ׂם׾
    

    View full-size slide

  56. ؠٚؗغئ٭لتס⮵榫
    Amazon Web Services Google Cloud
    

    View full-size slide

  57. XaaS
    IaaS
    PaaS
    SaaS
    

    View full-size slide

  58. 鞊♳⪦僗ٓظٜ
    IaaS PaaS SaaS
    OS OS OS OS
    

    View full-size slide

  59. /
    ˝ ْٛشع
    ˝ ُؾ٭ةغئ٭لتמ׻׾ꝧ氦ؤتعյ鷞榫ؤتعס⯡峎
    ˝ Ⳃ氳םٛخ٭ت澬⟊מ׻׾䦡䍖䓪ס⺸┕
    ˝ 䏼ꄈ鐐ꄋמ׻׾ؤتع僃鸵⴫
    ˝ ┩槡╈מ㰆㏇׌׾ظ٭ذج٤ذ٭؅⮵榫׌׾׆כך愤㲹㵚瓀ֿ⺎耆
    ˝ ظْٛشع
    ˝ بتطّסؤ٤عٞ٭ٜ׷؜تذُؕثס⯆꡾
    ˝ ئ٭لتס犉哕氳ם孨榫מ׻׾بتطّ⪒⛮ס邾ꥭ⴫
    ˝ ي٤ر٭ٞشؠؕ٤
    

    View full-size slide

  60. 泘域
    - Web αʔϏεͷΠϯϑϥͱ͸
    - ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    - αʔόʔઃܭ
    - αʔόʔߏங
    - Ϋϥ΢υαʔϏεͷར༻
    !
    αʔόʔӡ༻
    - ·ͱΊ
    

    View full-size slide

  61. ئ٭ف٭鷞榫
    ˝ ظ٭ذס畘杼
    ˝ 泃釱
    ˝ ꤃㲹㵚䑴
    

    View full-size slide

  62. ظ٭ذס畘杼
    ˝ ظ٭ذס㱦⪒䓪յ⺎榫䓪؅䥵⟊׌׾׆כֿ泘氳
    ˝ ظ٭ذס䮇㜊׷بتطّ꤃㲹מ⤓ֻ׾
    ˝ 嫎氳紶ⳉ׷ؤ٤وٚؕؓ٤ت㵚瓀׫ס㵚䑴׵䑒釐
    ˝ 泘氳מ䑴׋י僃鸵ם䣆嫎؅鹟䥃׌׾
    ˝ فشؠؓشوյؓ٭؜ؕهյٝوٛآ٭ب٘٤
    e- J-SOX
    

    View full-size slide

  63. فشؠؓشو
    ˝ 䳩⛼ِت׷بتطّ꤃㲹յٜؗؔت䚉刌םלס꤀מظ٭ذ؅䐝
    仾׌׾ג״מ
    ˝ ظ٭ذ⪒⛮׷㚺催䄐⮆؅ظؔتؠ׷ط٭وםלյ擻杼氳מ樟ם
    ׾㕙䢥מ㲊僿氳מ⟊㰆׌׾
    ˝ 䐝仾وٞجت؅乃傴⴫׊י㲊僿氳מ澬鏀׌׾׆כֿꄆ釐
    

    View full-size slide

  64. ؓ٭؜ؕه
    ˝ ꄆ釐䗯㕔؅Ꝏ僿ꝴמ؂גזי⟊㰆٬孨榫׌׾
    ˝ Ꝏ僿⟊㰆ֿ䑒釐םظ٭ذ؅ط٭و׷ظؔتؠյْظؔؓ׫鋗ꎰ
    ׊י⟊畘׊յ泃削׷䗯㕔ꝧ炐םלյ䑒釐םכ׀מꞦ鈋⺎耆מ׌
    ׾
    ˝ ⟊㰆僿ꝴס畘杼յ䷉׉؆׷寕⸻סꡔ塛յꞦ鈋ٞءס畘杼םלס
    㱦⪒䓪׵姲״׼׿׾
    

    View full-size slide

  65. ٝوٛآ٭ب٘٤
    ˝ ؾشع٠٭ؠ؅鵟׋יٜٛؓذّؕמظ٭ذ؅邾邮׌׾
    ˝ 䐝仾⛼哅ס䑒釐ֿםׂյ⮉׽僀ֻ׾׆כך泘氳؅鷼䡗ך׀׾
    ˝ فشؠؓشوכ⛍יַ׾ֿظ٭ذס䷉׉؆׷滭䮇׫סⲖ冽עם
    ַ׆כמ嫰䙫
    

    View full-size slide

  66. 泃釱
    /
    

    View full-size slide

  67. ؓوٛآ٭ب٘٤泃釱
    ˝ ꞊䑏ׇכ
    ˝ قنؚ٭ُ٤تעⶇ⮆־յ꤃㲹⸉㍔ע⛰־յ塜׊ׂ嚀耆׊י
    ַ׾־
    ˝ 泃釱׌׾䧗嘅
    ˝ ⭚杼侇ꝴյٞءյىٜتزؘؠؙ٤غَؕ٤عםל
    

    View full-size slide

  68. ئ٭لت泃釱
    ˝ ꞊䑏ׇכ
    ˝ ئ٭لت؅䬠❠ך׀יַ׾־յ䒍鸵מ✳ֻיַ׾־
    ˝ 泃釱׌׾䧗嘅
    ˝ ٝتَ٤تؤ٭غյٝؕط٤بםל
    

    View full-size slide

  69. ج؞ٖٛطؔ泃釱
    ˝ ꞊䑏ׇכ
    ˝ ┘塜מ⮵榫׈׿יַםַ־յ耗䍏םبتطّךעםַ־
    ˝ 泃釱׌׾䧗嘅
    ˝ 泃削ٞءյِغؘٜؗؓ٬ٚؕهٚٛס耗䍏䓪䗯㕔םל
    

    View full-size slide

  70. لةؾت泃釱
    ˝ ꞊䑏ׇכ
    ˝ ئ٭لتע䡗Ꝏ׊יַ׾־յ⮵沟ע⭳יַ׾־
    ˝ 泃釱׌׾䧗嘅
    ˝ ئ٭لت⮵榫縖丗ס㘃峎յؤتعםל
    

    View full-size slide

  71. ꝧ氦قنؚ٭ُ٤ت泃釱
    ˝ ꞊䑏ׇכ
    ˝ ꝧ氦յظوٞؕ׊׷׌ַ梪㗞؅禴䧏ך׀יַ׾־
    ˝ 泃釱׌׾䧗嘅
    ˝ ٛٛ٭ت값䈱յلٜغ٬ظوٞؕסٛ٭غذّؕםל
    

    View full-size slide

  72. ꤃㲹㵚䑴
    &&
    

    View full-size slide

  73. 泘域
    - Web αʔϏεͷΠϯϑϥͱ͸
    - ΠϯϑϥͰҙ͍ࣝͯ͠Δ͜ͱ
    - αʔόʔઃܭ
    - αʔόʔߏங
    - Ϋϥ΢υαʔϏεͷར༻
    - αʔόʔӡ༻
    !
    ·ͱΊ
    

    View full-size slide

  74. ױכ״
    Web
    

    View full-size slide