AWSでサーバ運用してみる

 AWSでサーバ運用してみる

C5c16982f213ea8fd9f7fb3f5a7157ca?s=128

Junpei Kuriyama

November 22, 2019
Tweet

Transcript

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

  2. • Name: ܀ࢁ ७ฏ • Belong: ۚ୔޻ۀେֶ • Twitter: @_Iruk_

    • Skill: Ruby, Elixir, TypeScript, Go, • CLIπʔϧ΍WebΞϓϦέʔγϣϯΛ޷ΜͰ࡞Γ·͢ɻ • Πϯϑϥ͸৯Θͣݏ͍ͳٕज़෼໺ͩͬͨɻ $ whoami
  3. None
  4. App

  5. None
  6. App

  7. App

  8. App

  9. App

  10. App

  11. App

  12. App

  13. App

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

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

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

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

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

  19. AWSͰαʔόӡ༻Λͯ͠ΈΔ ۚ୔޻ۀେֶ ৘ใ޻ֶՊ ܀ࢁ७ฏ
 JAWS –UG ۚ୔ | 2019 KANAZAWA

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

  21. None
  22. Internet gateway Amazon EC2

  23. Internet gateway Amazon RDS Amazon EC2

  24. Internet gateway Amazon RDS Amazon S3 Amazon EC2 Amazon RDS

    Amazon EC2
  25. Internet gateway Amazon RDS Amazon S3 Amazon EC2 Amazon RDS

    Amazon EC2 ΞϕΠϥϏϦςΟκʔϯ - B ΞϕΠϥϏϦςΟκʔϯ - C
  26. ʮAWSͷαʔόӡ༻Λͯ͠ΈΔʯ • ӡ༻͍ͯͨ͠όοΫΤϯυͷΠϯϑϥΛAWSʹҠ؅ͨ͠ɻ • ಉ࣌ʹߏஙʹ৑௕ੑΛ࣋ͨͤͨɻ

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

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

  29. Ϧʔδϣϯ

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

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

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

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

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

    OS(AMI)΋બ୒Մೳ
  35. AMIͷબ୒

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

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

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

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

  40. Amazon VPCͷઃఆ

  41. Amazon VPCͱ͸ • CIDRϒϩοΫͷઃఆ • ΞϕΠϥϏϦςΟκʔϯͷઃఆ • AZ͕ҧ͏ͱσʔληϯλʔࣗମҧ͏ͷͰɺ
 ہॴతͳࡂ֐ͳͲʹඋ͑ͨ৑௕ߏ੒͕࡞ΕΔ

  42. αϒωοτͷ࡞੒

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

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

  45. ηΩϡϦςΟάϧʔϓ • ϑΝΠΞ΢ΥʔϧͷઃఆͷΑ͏ͳ΋ͷ • ࠓճ͸
 ssh: 22
 http: 80
 https:

    443
 pumaͷsocket: 3000
 Λ։͚͓ͯ͘
  46. ࡞੒ʂ

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

  48. EC2Πϯελϯεͷ׬੒ • άϩʔόϧIPͱήʔτ΢ΣΠͷ४උ͞Εͨαʔό͕׬੒ • ηΩϡϦςΟάϧʔϓͰsshͷϙʔτΛ։͚ͨͷͰ
 ssh ec2-user@IPv4public -i key.pem ͰsshͰ͖Δ

  49. EC2Πϯελϯεͷ׬੒ • άϩʔόϧIPͱήʔτ΢ΣΠͷ४උ͞Εͨαʔό͕׬੒ • ηΩϡϦςΟάϧʔϓͰsshͷϙʔτΛ։͚ͨͷͰ
 ssh ec2-user@public -i key.pem ͰsshͰ͖Δ

    • ϙʔτΛ։͚ͨαʔό͕׬੒͍ͯ͠ΔͷͰ
 MySQLͳͲϛυϧ΢ΣΞΛೖΕͯΞϓϦӡ༻͕Մೳ
  50. EC2Πϯελϯεͷ׬੒ Internet gateway Amazon EC2

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

  52. ࣮ࡍʹڍಈΛݟΔ • Ruby, RailsपΓͷ؀ڥߏஙΛ͢Δ
 (DockerFileΛ༻ҙͯ͋͠ΔͷͰͦͷ··ίϯςφΛ࡞੒

  53. ࣮ࡍʹڍಈΛݟΔ • Ruby, RailsपΓͷ؀ڥߏஙΛ͢Δ
 (DockerFileΛ༻ҙͯ͋͠ΔͷͰͦͷ··ίϯςφΛ࡞੒ • ΞΫηε͕དྷͨࡍͷϑΥϫʔσΟϯάʹnginxΛॻ͘
 • puma(rubyͷwebαʔό)ͷsocketΛnginxʹରԠͤ͞Δɻ

  54. VQTUSFBNQVNB\  TFSWFSVOJYIPNFFDVTFS&$EFQUNQTPDLFUTQVNBTPDL ^ TFSWFS\ MJTUFO TFSWFS@OBNFBEESFTT JODMVEFFUDOHJOYEFGBVMUE DPOG 


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

  55. ࣮ࡍʹڍಈΛݟΔ

  56. Internet gateway Amazon RDS Amazon EC2

  57. RDBʹ͍ͭͯ

  58. RDBʹ͍ͭͯ • EC2ΠϯελϯεʹRDB(MySQL, PostgreSQL)
 ΛೖΕΔ • Amazon RDSΛ࢖͏

  59. RDBʹ͍ͭͯ • EC2ΠϯελϯεʹRDB(MySQL, PostgreSQL)
 ΛೖΕΔ • Amazon RDSΛ࢖͏

  60. • Amazon Relational Database Servise • RDBʹ͍ͭͯ

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

    RDBʹ͍ͭͯ
  62. RDSΠϯελϯεͷ࡞੒

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

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

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

  66. Internet gateway Amazon RDS Amazon EC2

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

  68. ·ͱΊ • ܦݧͷগͳ͍ٕज़ऀ໨ઢͰ΋
 GUIϕʔεͰαʔόΛߏஙͰ͖Δ • අ༻͸͔͔Δ΋ͷͷɺAmazonͷαʔϏεʹ ґଘ͢Δ͜ͱͰීஈ؅ཧͷ೉͍͠ྖҬΛҕ೚ Ͱ͖Δ • Πϯϑϥ͕ਏ͍ਓʹͦͥ͜ͻ৮ͬͯཉ͍͠ɻ

  69. None
  70. AWSͰαʔόӡ༻Λͯ͠ΈΔ ۚ୔޻ۀେֶ ৘ใ޻ֶՊ ܀ࢁ७ฏ
 JAWS –UG ۚ୔ | 2019 KANAZAWA