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

はてなのインフラ環境を自宅で再現する

masayoshi
December 10, 2016

 はてなのインフラ環境を自宅で再現する

YAPC::Hokkaido 2016 SAPPOROでの発表資料です。
今後ネットワーク図とか色々ブログの方に公開していきたいと思っています。

masayoshi

December 10, 2016
Tweet

More Decks by masayoshi

Other Decks in Technology

Transcript

  1. ͸ͯͳͷΠϯϑϥ؀ڥ
    Λࣗ୐Ͱ࠶ݱ͢Δ
    :"1$)PLLBJEP

    View full-size slide

  2. ࣗ୐ͷ༷ࢠ

    View full-size slide

  3. ෺ཧαʔό: 3୆ (+1୆)
    Ծ૝αʔό: 40୆
    L3εΠον: 1୆ (+1୆)
    Քಇதͷ୆਺
    ()಺͸ઃఆதͷ୆਺

    View full-size slide

  4. YAPC::Hokkaidoͷൃදه೦ʹ
    αʔόΛ૿ڧ͠·ͨ͠
    (10ສ)

    View full-size slide

  5. ࣗݾ঺հ
    • id:masayoshi (yoyogidesaiz)
    • גࣜձࣾ͸ͯͳ (2016೥4݄ೖࣾ)
    • YAPC ॳࢀՃͰ͢
    • ֶੜ࣌୅͸αʔό؂ࢹͷΞϧόΠτ
    • ݱࡏ͸WebΦϖϨʔγϣϯΤϯδχΞͷج൫νʔϜ

    View full-size slide

  6. ΞδΣϯμ
    • ॳΊʹ
    • ࢲͳΓͷߟ͑ํͱษڧํ๏
    • ࣗ୐αʔόͷߏ੒঺հ
    • ·ͱΊ

    View full-size slide

  7. ৽ଔ࠷ॳͷ3ϲ݄

    View full-size slide

  8. • 4݄ ݚम

    http://developer.hatenastaff.com/entry/2016-newbie-training-of-web-operation
    • 5݄ ࣾ಺ͷωοτϫʔΫ֮͑·͔ͨ͠?

    ֎෦τϥϑΟοΫͷଳҬ૿΍͍ͯͩ͘͠͞
    • 6݄ ωοτϫʔΫઃܭ͍͍ײ͡ʹ͓ئ͍͠·͢
    • ͦͷޙɺج൫νʔϜ͕ൃ଍͠ϝϯόʔʹ

    View full-size slide

  9. ج൫νʔϜ(3໊)
    • ࣗࣾͷΠϯϑϥಛੑΛ೺Ѳ͍͍ͯ͠ײ͡ʹ͢Δ
    • αʔϏε਺͕ଟ͍(10αʔϏεҎ্)
    • DC + AWS + ͘͞Βͷઐ༻αʔό
    • 5,10೥ར༻͞ΕΔαʔϏε
    • ෺ཧ,Ծ૝αʔό͸1000୆Ҏ্

    View full-size slide

  10. ࠓҎ্ʹษڧ͠ͳ͍ͱϚζΠ

    View full-size slide

  11. ͱ͍͏͜ͱͰ

    View full-size slide

  12. ΋͏͜Ε͸
    ࣗ୐ͰձࣾͷΠϯϑϥΛ
    ਅࣅͯΈΔ͔͠ͳ͍ʂ

    View full-size slide

  13. ͱ͍͏͜ͱʹͳͬͨ

    View full-size slide

  14. 2
    ࢲͳΓͷ
    ߟ͑ํͱษڧํ๏

    View full-size slide

  15. ษڧ͸టष͘
    ࢓ࣄ͸εϚʔτʹ
    (΍Γ͍ͨͱࢥ͍ͬͯΔ)

    View full-size slide

  16. ࢓ࣄ͸…
    • ॏཁͳ͜ͱ
    • ϢʔβʹαʔϏε(Ձ஋)Λಧ͚Δ͜ͱ
    • ࣌ؒత੍໿
    • ௅ઓͱ҆ఆͷόϥϯε
    • ͍࣋ͬͯΔٕज़ɺ஌ࣝͰΨϯΨϯԥΔ
    • ศརɺར༻͞Ε͍ͯΔ΋ͷΛੵۃతʹ࢖͏

    View full-size slide

  17. ษڧ͸…
    • ࣌ؒΛֶ͔͚ͯΜͰྑ͍
    • Ұͭͷ͜ͱΛஸೡʹਂ۷Γ
    • ۚ͸ͳ͍ɺ࣌ؒ͸͔͚ͯ΋Α͍
    • ஍ཕ͸౿Μͩ਺͚ͩڧ͘ͳΔ
    • ͋ɺʙͰݟͨ͜ͱ͋Δ΍ͭͩ
    • ஍ཕௐࠪ͸ਂ۷Γ͢Δ͍͍νϟϯε

    View full-size slide

  18. ࣌ؒΛ͔͚ͯਂ۷Γ

    View full-size slide

  19. ࡞ΔਅࣅΔ৮Δฉ͘ ಡΉ
    ೉͍͠
    ͔͔࣌ؒΔ
    Α͘Θ͔Δ
    ؆୯
    ͙͢ग़དྷΔ
    Α͘Θ͔ΒΜ

    View full-size slide

  20. ֶ෦3೥ͷࠒͷษڧํ๏
    • ਓ͔Βฉ͘ɺٕज़ϒϩάͱ͔ಡΉ
    • LinuxͷίϚϯυͱ͔
    • શવ֮͑ΒΕͳ͍͠ɺΘ͔ΒΜ
    • ͱΓ͋͑ͣܰ͘৮ͬͯΈΔ
    • ՈͷϊʔτPCΛLinuxʹ͢Δ
    • wordpressͱ͔Λߏஙͯ͠ΈͨΓ

    View full-size slide

  21. ৮Δ͚ͩͷݶք
    • ߏஙखॱΛ֮͑Δ͜ͱ͕ٕज़ྗ?
    • εΫϦϓτͱ͔ChefͰࣗಈԽग़དྷΔΒ͍͠
    • ઃఆ߲໨Λ֮͑Δ͜ͱ͕ॏཁ?
    • Ͳ͏ͯͦ͠ͷઃఆΛ͢Δͱ଎͘ͳΔͷ͔͕ॏཁ
    • ϛυϧ΢ΣΞ͸Ͳ͏΍ͬͯબ΂͹ྑ͍?
    • ಓ۩ͷ࢖͍ํ΋ॏཁ͚ͩͲબͼํ΋௒ॏཁ

    View full-size slide

  22. ܰ͘৮ͬͨΓɺ
    ฉ͘ɺಡΉఔ౓Ͱ͸
    ৽͍͠΋ͷΛ࡞੒ɺઃܭ͸೉͍͠
    ౰ͨΓલ͕ͩ

    View full-size slide

  23. ֶ෦4೥Ҏ߱ͷษڧํ๏
    • αʔό؂ࢹͷΞϧόΠτ
    • ϛυϧ΢ΣΞɺෛՙ෼ࢄɺ৑௕ԽͳͲͷߏ੒ྫ
    • ਅࣅΔͨΊͷ࣮ྫ
    • ݚڀ
    • ιϑτ΢ΣΞϧʔλ࡞੒ɺϓϩτίϧͷௐࠪͳͲ
    • ඞཁͳجૅ஌ࣝͷษڧͱ࣮૷

    View full-size slide

  24. ਅࣅͯ࡞ͬͨΓมߋͨ͠Γ
    • ߏ੒ྫͷߏஙࣗಈԽνϟϨϯδ
    • ৚݅ΛՃ͑ͯɺͦΕʹ͋͏Α͏ʹߏ੒ྫΛมߋ͢Δ
    • ݸਓతʹ͸”റΓϓϨΠ”ͱݺΜͰ͍Δ (ແఀࢭറΓͱ͔)
    • େม͚ͩͲҰ͔Β࡞ͬͯΈΔ
    • ϥΠϒϥϦͷ࠶࣮૷ͱ͔
    • ϛυϧ΢ΣΞͳͲͷҰ෦Λ؆қ࣮૷
    • ιέοτϓϩάϥϛϯάͰpreforkܕͱeventܕͱ͔

    View full-size slide

  25. ಘΒΕΔ΋ͷ(ͦͷ1)
    • ఆੴͷϝϦοτɺσϝϦοτֶ͕΂Δ
    • બ୒ࢶΛ૿΍ͤΔɺ൑அج४͕ग़དྷΔ
    • ҰͭԼͷϨΠϠʔֶ͕΂Δ (syscall, OS, Network,..)
    • ҧ͏ϛυϧ΢ΣΞͷཧղʹ໾ཱͭ
    • ஌͕ࣝ޿͕Δ
    • ෼͔ͬͨ”ͭ΋Γ”෦෼ͷ೺Ѳ
    • ͳΜ͔ٕज़ϒϩάɺຊͱ͔Ͱ஌ͬͨؾʹͳͬͯͨ
    • צҧ͍ɺࢥͬͨΑΓ~ͩͬͨ

    View full-size slide

  26. ಘΒΕΔ΋ͷ(ͦͷ2)
    • ײ૝ͱٙ໰఺ (ෳࡶ,γϯϓϧ, ଎͍, ஗͍, ָ, ͭΒ
    ͍, …)
    • ΈΜͳͲ͏͍ͯ͠ΔΜͩΖ͏?
    • ͭΒ͍ͷ͸૝ఆ͞Εͨ࢖ΘΕํ͡Όͳ͍͔Β͔
    ΋
    • ͔ͩΒ͜͏͍͏࣮૷ͳͷ͔~
    • ݁ہ͕͜͜໰୊ͳΜͩΑͳ͊
    • ଞʹ΋ͬͱద࣮ͨ͠૷͕͋ΔͷͰ͸?
    • ͳ͍ͳΒ࡞Δ͔(ͱݴ͑Δͱ͔͍͍ͬ͜)

    View full-size slide

  27. ྫ͑͹
    ιϑτ΢ΣΞϧʔλ࡞੒

    View full-size slide

  28. ࡞Δͱ͖ͷֶͼྫ (checksum)
    • 1ͷิ਺? 2ͷิ਺ͳΒΑ͘࢖͏͚Ͳͳ͊
    • L2Ͱ΋L3Ͱ΋L4Ͱ΋νΣοΫαϜܭࢉ͢Μͷ͔Α
    • ٙࣅϔομΛ͚ͭͯܭࢉ? IPΞυϨε͕͋Δ

    ͱ͍͏͜ͱ͸IPΞυϨεॻ͖׵͑ͨΒL4ܭࢉ͠௚͠?
    • ͳΜ͔஗͍….γϑτԋࢉͱ͔Ͱ΍ͬͯΔͷʹͳ͊
    • kernelͲ͏΍ͬͯΜͩ? ΞηϯϒϦ͔Α…
    • νΣοΫαϜΦϑϩʔυ? ଎͍! ϋʔυ΢ΣΞ࠷ߴ!
    • Μ? Ծ૝Ϛγϯ͸ԿʹΦϑϩʔυͯ͠Μͷ?
    • xenͩͬͨΒxen-netbackͱ͔ʹͦΕͬΆ͍ͷ͋Δͳ͊ʔ

    View full-size slide

  29. ࡞Δͱ͖ͷֶͼྫ (ͦͷଞ)
    • ͏΁͐…౸ணύέοτͷฒͼସ͑ΊͬͪΌ஗͍…
    • TCPͷΦϓγϣϯϑΟʔϧυ?

    Linux͸σϑΥϧτͰtimestamp࢖͍ͬͯΔͷ͔…
    • ωοτϫʔΫͷ଎౓ײͩͱϝϞϦίϐʔ͸஗͍…
    • CPU͕1ίΞʹுΓ෇͘~ͱ͜ΖͰsoftirqͬͯͳʹ?
    • kernelͷωοτϫʔΫελοΫ͕ϘτϧωοΫ?͑?
    • DPDKࢯ~ པΉ~

    View full-size slide

  30. ࿩Λ໭ͯ͠

    View full-size slide

  31. ં֯ࣾ಺ͷΠϯϑϥͷத਎͕ݟΕΔͷͰ
    ՈͰਅࣅͯΈΑ͏

    View full-size slide

  32. 3
    ࣗ୐αʔόͷߏ੒঺հ

    View full-size slide

  33. ࣾ಺ͷΠϯϑϥΛਅࣅΔϝϦοτ
    • WebαʔϏεܥͷΠϯϑϥج൫ͷఆੴΛֶ΂Δ
    • ࠓͰ΋௨༻͢Δےͷྑ͍ઃܭ
    • ࠓͰ͸ݹ͍ɺطʹഁ୼ͨ͠Ξϯνύλʔϯ
    • ͪΐ͏ͲΑ͍ن໛ײ
    • খن໛Ϋϥ΢υ, ࣮૷͕௥͍͖ΕΔ
    • ౰࣌ͷઃܭऀͷҙਤɺؾ͕࣋ͪ෼͔Δ
    • ࣾ಺ݻ༗ͷࣄ৘(ن໛, ίετ)Λ഑ྀͨ͠ઃܭ
    • ؆୯ͦ͏Ͱ೉͍͠, ౰࣌͸࢖͑ͳ͔ͬͨ

    View full-size slide

  34. ਅࣅΔͱ͜Ζ͸ਅࣅ͍͍ͯײ͡ʹ
    • ศརͳͱ͜Ζ͸ਅࣅ͍ͯ͘
    • ҧ͏΋ͷࢼ͍ͨ͠ͱ͜Ζ͸ม͑Δ
    • ґଘؔ܎ʹ͸஫ҙ͠ͳ͕Βߏங͍ͯ͘͠
    • Ոͱձࣾͷن໛ײΛҙࣝ͢Δ
    • ՄೳͳݶΓ৽͍͠όʔδϣϯͰ࡞Δ
    • ͍͍ײ͡ʹͳͬͨΒࣾ಺ಋೖ
    • ָ͠Ήʂ

    View full-size slide

  35. ͱ͍͏͜ͱͰ࣌ؒ͋Δ͔͗Γ঺հ
    • ωοτϫʔΫߏ੒
    • ෺ཧαʔόͷηοτΞοϓ
    • Ծ૝αʔόͷηοτΞοϓ
    • ϓϩϏδϣχϯά
    • ෛՙ෼ࢄɺ৑௕Խ
    • WebΞϓϦέʔγϣϯ

    View full-size slide

  36. ωοτϫʔΫߏ੒
    %PN
    &BTU )PNF 0QF
    0QFSBUJPO
    CS CS
    %PN6
    %PN6
    %PN
    %PN6
    %PN6
    %PN
    %PN6
    %PN6
    CS
    8FTU &9 +VOPT

    CS
    CS CS CS CS
    394
    %FCJBOYFO

    594 7Z04

    $PSF

    View full-size slide

  37. ෺ཧαʔόͷηοτΞοϓ
    • Debian Stretch + Xen4.6
    • ஌Βͳ͍͏ͪʹ࠶ىಈ
    • Φϑϩʔυ༗ޮʹ͢Δͱ1࣌ؒޙ͙Β͍ʹigb͕Τϥʔ
    • vif͕4ͭ·Ͱ͔͠࡞Εͳ͍
    • ηοτΞοϓ͸PXEϒʔτ+Preseed
    • ϒʔτબ୒ͨ͠ΒࣗಈͰOSΠϯετʔϧ
    • ࡉ͔͍ͷ͸ىಈޙʹAnsibleͰ੔͑Δ

    View full-size slide

  38. Ծ૝αʔόͷηοτΞοϓ
    • ࣾ಺
    • Ծ૝CPU਺ɺϝϞϦɺσΟεΫαΠζΛਓ͕ࢦఆ
    • IP, ϗετ໊؅ཧ͸ߏ੒؅ཧπʔϧ, Mackerelʹొ࿥
    • ࣗ୐
    • NUMAΛҙࣝͨ͠ΠϯελϯελΠϓͷఆٛͱಋೖ
    • xen 4.5͔Β͍͍ײ͡ͷεέδϡʔϥ
    • IP,ϗετ໊؅ཧ͸Mackerel
    • ໊લղܾ͸consul(0.7)ͱPowerDNS(4.0.1)

    View full-size slide

  39. ϓϩϏδϣχϯάͱ͔
    • ࣾ಺
    • Chef + Capistrano + Jenkins
    • ࣗ୐
    • Ansible + Fabric + Rundeck

    View full-size slide

  40. ෛՙ෼ࢄɺ৑௕Խ
    • ࣾ಺
    • LVS+keepalived, HAProxy
    • ࣗ୐
    • LVS+keepalivedͱconsul
    • Seesawͱ͔ࢼͯ͠Έ͍ͨ
    • ࣗ࡞

    View full-size slide

  41. WebΞϓϦέʔγϣϯ
    • ISUCONͷ໰୊Λ࢖༻
    • ؆қ࣮૷ͳͷͰ৭ʑ֬ೝ͠΍͍͢
    • ϕϯνϚʔΫ͕͋Δ
    • ଞͷํͱൺֱɺ࿩͕ग़དྷΔ
    • ·ͩ࡞Ε͍ͯͳ͍͕ࣗ࡞͍ͨ͠
    • PerlͰҰͭԿ͔࡞Γ͍ͨ

    View full-size slide

  42. ࣗ୐αʔόͷྑ͞
    • ؾܰʹෛՙ͔͚ΒΕΔ
    • ωοτϫʔΫ·ͰݟΕΔ
    • ୆਺ؾʹ͠ͳ͍ͰݐͯΒΕΔ
    • 10୆Ҏ্ͳΒίετ҆͘ͳΔ?
    • ෺ཧɺԾ૝ɺίϯςφͳΜͰ΋બ΂Δ
    • ϋΠύʔόΠβʔͷϩάݟΕΔ
    • ਂ۷Γ͢Δʹ͸࠷దʂ

    View full-size slide

  43. ࣗ୐αʔόָ͍͠ʂ

    View full-size slide

  44. ·ͱΊ
    • ͸͊ʙࣗ୐αʔόͨͷ͌͠ʙ
    • ؆қͳ΋ͷͰ΋ࣗ෼Ͱ࡞Δͷେࣄ
    • ΤϯδχΞ͸ϥΠτϢʔβ͡Όବ໨
    • ΍Γ͜Έॏཁ
    • ษڧํ๏͸ΞϓϦέʔγϣϯΤϯδχΞͱ͞΄Ͳม
    ΘΒͳ͍
    • ͱʹ͔ࣗ͘෼Ͱ࡞ͬͯΈΑ͏ʂ

    View full-size slide