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

AWSでサーバ運用してみる

 AWSでサーバ運用してみる

Junpei Kuriyama

November 22, 2019
Tweet

Other Decks in Technology

Transcript

  1. AWSͰαʔόӡ༻Λͯ͠ΈΔ
    ۚ୔޻ۀେֶ ৘ใ޻ֶՊ ܀ࢁ७ฏ

    JAWS –UG ۚ୔ | 2019
    KANAZAWA

    View full-size slide

  2. • Name: ܀ࢁ ७ฏ
    • Belong: ۚ୔޻ۀେֶ
    • Twitter: @_Iruk_
    • Skill: Ruby, Elixir, TypeScript, Go,
    • CLIπʔϧ΍WebΞϓϦέʔγϣϯΛ޷ΜͰ࡞Γ·͢ɻ
    • Πϯϑϥ͸৯Θͣݏ͍ͳٕज़෼໺ͩͬͨɻ
    $ whoami

    View full-size slide

  3. αʔόߏஙɺਏ͔ͬͨɻ

    View full-size slide

  4. • ܦݧͷͳ͍ྖҬΛCLIͰߦ͏ͷ͸݁ߏਏ͍ɻ

    View full-size slide

  5. • ܦݧͷͳ͍ྖҬΛCLIͰߦ͏ͷ͸݁ߏਏ͍ɻ
    • αʔόߏஙʹ͓͚Δ஌ࣝ͸࠷௿ݶ͋Δ

    View full-size slide

  6. • ܦݧͷͳ͍ྖҬΛCLIͰߦ͏ͷ͸݁ߏਏ͍ɻ
    • αʔόߏஙʹ͓͚Δ஌ࣝ͸࠷௿ݶ͋Δ
    • ͜ͷਏ͞ΛऔΓআ͍ͯ͘ΕΔαʔϏε….

    View full-size slide

  7. • ܦݧͷͳ͍ྖҬΛCLIͰߦ͏ͷ͸݁ߏਏ͍ɻ
    • αʔόߏஙʹ͓͚Δ஌ࣝ͸࠷௿ݶ͋Δ
    • ͜ͷਏ͞ΛऔΓআ͍ͯ͘ΕΔαʔϏε….
    ʂ

    View full-size slide

  8. AWSͰαʔόӡ༻Λͯ͠ΈΔ
    ۚ୔޻ۀେֶ ৘ใ޻ֶՊ ܀ࢁ७ฏ

    JAWS –UG ۚ୔ | 2019
    KANAZAWA

    View full-size slide

  9. ʮAWSͷαʔόӡ༻Λͯ͠ΈΔʯ
    • ӡ༻͍ͯͨ͠όοΫΤϯυͷΠϯϑϥΛAWSʹҠ؅ͨ͠ɻ
    • ݴޠ: Ruby
    • RDB: MySQL

    View full-size slide

  10. Internet gateway Amazon EC2

    View full-size slide

  11. Internet gateway
    Amazon RDS
    Amazon EC2

    View full-size slide

  12. Internet gateway
    Amazon RDS
    Amazon S3
    Amazon EC2
    Amazon RDS
    Amazon EC2

    View full-size slide

  13. Internet gateway
    Amazon RDS
    Amazon S3
    Amazon EC2
    Amazon RDS
    Amazon EC2
    ΞϕΠϥϏϦςΟκʔϯ - B
    ΞϕΠϥϏϦςΟκʔϯ - C

    View full-size slide

  14. ʮAWSͷαʔόӡ༻Λͯ͠ΈΔʯ
    • ӡ༻͍ͯͨ͠όοΫΤϯυͷΠϯϑϥΛAWSʹҠ؅ͨ͠ɻ
    • ಉ࣌ʹߏஙʹ৑௕ੑΛ࣋ͨͤͨɻ

    View full-size slide

  15. ʮAWSͷαʔόӡ༻Λͯ͠ΈΔʯ
    • ӡ༻͍ͯͨ͠όοΫΤϯυͷΠϯϑϥΛAWSʹҠ؅ͨ͠ɻ
    • ಉ࣌ʹߏஙʹ৑௕ੑΛ࣋ͨͤͨɻ
    • => ͦͷࡍͷৄࡉɺ஌ݟΛ࿩͍͖ͯ͠·͢ɻ

    View full-size slide

  16. EC2ΠϯελϯεΛ࡞੒͢Δ
    Amazon EC2

    View full-size slide

  17. Ϧʔδϣϯ
    • αʔόͷ෺ཧతॴࡏҐஔ

    View full-size slide

  18. Ϧʔδϣϯ
    • αʔόͷ෺ཧతॴࡏҐஔ
    • ೔ຊϢʔβ͕ଟ͍αʔϏεΛӡӦ͢ΔͳΒɺϢʔβͱͷ෺
    ཧతڑ཭͕͍ۙ౦ژϦʔδϣϯ͕๬·͍͠

    View full-size slide

  19. Ϧʔδϣϯ
    • αʔόͷ෺ཧతॴࡏҐஔ
    • ೔ຊϢʔβ͕ଟ͍αʔϏεΛӡӦ͢ΔͳΒɺϢʔβͱͷ෺
    ཧతڑ཭͕͍ۙ౦ژϦʔδϣϯ͕๬·͍͠
    • ଞͷϦʔδϣϯͷ৘ใ͸දࣔ͞Εͳ͍ͷͰ஫ҙ

    (ex. όʔδχΞ๺෦Λબ୒͍ͯ͠Δͱ౦ژͷ৘ใ͸ݟ͑ͳ͍

    View full-size slide

  20. EC2ΠϯελϯεΛ࡞੒͢Δ

    View full-size slide

  21. EC2ΠϯελϯεΛ࡞੒͢Δ
    • Amazon Elastic Compute
    • ΠϯελϯεͱݺͿαʔόΛ࡞੒͢Δ
    • εϖοΫʹؔͯ͠͸બ୒Մೳ
    • OS(AMI)΋બ୒Մೳ

    View full-size slide

  22. ΠϯελϯελΠϓͷબ୒

    View full-size slide

  23. ΠϯελϯελΠϓͷબ୒
    Amazon EC2 ΠϯελϯελΠϓ - https://aws.amazon.com/jp/ec2/instance-types/

    View full-size slide

  24. VPCͷઃఆΛ͢Δ
    Amazon EC2
    AZ(ΞϕΠϥϏϦςΟκʔϯ)

    View full-size slide

  25. Πϯελϯεৄࡉͷઃఆ

    View full-size slide

  26. Amazon VPCͷઃఆ

    View full-size slide

  27. Amazon VPCͱ͸
    • CIDRϒϩοΫͷઃఆ
    • ΞϕΠϥϏϦςΟκʔϯͷઃఆ
    • AZ͕ҧ͏ͱσʔληϯλʔࣗମҧ͏ͷͰɺ

    ہॴతͳࡂ֐ͳͲʹඋ͑ͨ৑௕ߏ੒͕࡞ΕΔ

    View full-size slide

  28. αϒωοτͷ࡞੒

    View full-size slide

  29. EC2ΠϯελϯεΛ࡞੒͢Δ

    View full-size slide

  30. EC2ΠϯελϯεΛ࡞੒͢Δ

    View full-size slide

  31. ηΩϡϦςΟάϧʔϓ
    • ϑΝΠΞ΢ΥʔϧͷઃఆͷΑ͏ͳ΋ͷ
    • ࠓճ͸

    ssh: 22

    http: 80

    https: 443

    pumaͷsocket: 3000

    Λ։͚͓ͯ͘

    View full-size slide

  32. EC2Πϯελϯεͷ׬੒
    • άϩʔόϧIPͱήʔτ΢ΣΠͷ४උ͞Εͨαʔό͕׬੒

    View full-size slide

  33. EC2Πϯελϯεͷ׬੒
    • άϩʔόϧIPͱήʔτ΢ΣΠͷ४උ͞Εͨαʔό͕׬੒
    • ηΩϡϦςΟάϧʔϓͰsshͷϙʔτΛ։͚ͨͷͰ

    ssh ec2-user@IPv4public -i key.pem ͰsshͰ͖Δ

    View full-size slide

  34. EC2Πϯελϯεͷ׬੒
    • άϩʔόϧIPͱήʔτ΢ΣΠͷ४උ͞Εͨαʔό͕׬੒
    • ηΩϡϦςΟάϧʔϓͰsshͷϙʔτΛ։͚ͨͷͰ

    ssh ec2-user@public -i key.pem ͰsshͰ͖Δ
    • ϙʔτΛ։͚ͨαʔό͕׬੒͍ͯ͠ΔͷͰ

    MySQLͳͲϛυϧ΢ΣΞΛೖΕͯΞϓϦӡ༻͕Մೳ

    View full-size slide

  35. EC2Πϯελϯεͷ׬੒
    Internet gateway Amazon EC2

    View full-size slide

  36. ࣮ࡍʹڍಈΛݟΔ
    • Ruby, RailsपΓͷ؀ڥߏஙΛ͢Δ

    View full-size slide

  37. ࣮ࡍʹڍಈΛݟΔ
    • Ruby, RailsपΓͷ؀ڥߏஙΛ͢Δ

    (DockerFileΛ༻ҙͯ͋͠ΔͷͰͦͷ··ίϯςφΛ࡞੒

    View full-size slide

  38. ࣮ࡍʹڍಈΛݟΔ
    • Ruby, RailsपΓͷ؀ڥߏஙΛ͢Δ

    (DockerFileΛ༻ҙͯ͋͠ΔͷͰͦͷ··ίϯςφΛ࡞੒
    • ΞΫηε͕དྷͨࡍͷϑΥϫʔσΟϯάʹnginxΛॻ͘

    • puma(rubyͷwebαʔό)ͷsocketΛnginxʹରԠͤ͞Δɻ

    View full-size slide

  39. VQTUSFBNQVNB\
    TFSWFSVOJYIPNFFDVTFS&$EFQUNQTPDLFUTQVNBTPDL
    ^
    TFSWFS\
    MJTUFO
    TFSWFS@OBNFBEESFTT
    JODMVEFFUDOHJOYEFGBVMUEDPOG

    MPDBUJPO\
    QSPYZ@TFU@IFBEFS9'PSXBSEFE'PSQSPYZ@BEE@Y@GPSXBSEFE@GPS
    QSPYZ@SFEJSFDUPGG
    QSPYZ@QBTTIUUQQVNB
    ^

    FSSPS@QBHFIUNM
    MPDBUJPOYIUNM\
    ^

    FSSPS@QBHFYIUNM
    MPDBUJPOYIUNM\
    ^
    ^

    View full-size slide

  40. ࣮ࡍʹڍಈΛݟΔ

    View full-size slide

  41. Internet gateway
    Amazon RDS
    Amazon EC2

    View full-size slide

  42. RDBʹ͍ͭͯ
    • EC2ΠϯελϯεʹRDB(MySQL, PostgreSQL)

    ΛೖΕΔ
    • Amazon RDSΛ࢖͏

    View full-size slide

  43. RDBʹ͍ͭͯ
    • EC2ΠϯελϯεʹRDB(MySQL, PostgreSQL)

    ΛೖΕΔ
    • Amazon RDSΛ࢖͏

    View full-size slide

  44. • Amazon Relational Database Servise

    RDBʹ͍ͭͯ

    View full-size slide

  45. • Amazon Relational Database Servise
    • DBͷόοΫΞοϓ΍੬ऑੑʹର͢ΔରԠͳͲ
    ΛAmazonͷαʔϏεʹҰ೚Ͱ͖Δ
    • Τϯδϯ(RDBͷछྨ)͸બ୒Մೳ
    RDBʹ͍ͭͯ

    View full-size slide

  46. RDSΠϯελϯεͷ࡞੒

    View full-size slide

  47. RDSΠϯελϯεͷ࡞੒

    View full-size slide

  48. ηΩϡϦςΟάϧʔϓͷઃఆ

    View full-size slide

  49. config/database.ymlʹهड़
    socket: /var/lib/mysql/mysql.sock
    ɹ
    host: address.rds.amazonaws.comɹ
    database: appname_developmentɹ

    View full-size slide

  50. Internet gateway
    Amazon RDS
    Amazon EC2

    View full-size slide

  51. ಉ͡ߏ੒ͷΠϯελϯεΛཱͯΔ

    View full-size slide

  52. ·ͱΊ
    • ܦݧͷগͳ͍ٕज़ऀ໨ઢͰ΋

    GUIϕʔεͰαʔόΛߏஙͰ͖Δ
    • අ༻͸͔͔Δ΋ͷͷɺAmazonͷαʔϏεʹ
    ґଘ͢Δ͜ͱͰීஈ؅ཧͷ೉͍͠ྖҬΛҕ೚
    Ͱ͖Δ
    • Πϯϑϥ͕ਏ͍ਓʹͦͥ͜ͻ৮ͬͯཉ͍͠ɻ

    View full-size slide

  53. AWSͰαʔόӡ༻Λͯ͠ΈΔ
    ۚ୔޻ۀେֶ ৘ใ޻ֶՊ ܀ࢁ७ฏ

    JAWS –UG ۚ୔ | 2019
    KANAZAWA

    View full-size slide