Slide 1

Slide 1 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ECS/Fargateͷ׆༻ࣄྫ (CakePHPฤ) ϥϯαʔζגࣜձࣾ SRE/҆ୡ ྋ ίωώτϚϧγΣΦϯϥΠϯ ʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2

Slide 2

Slide 2 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ΞδΣϯμ ɾࣗݾ঺հ ɾݱࡏऔΓ૊ΜͰ͍Δ͜ͱ ɾECS/FargateͷϝϦοτσϝϦοτ ɾ։ൃ؀ڥΛ࡞ΔϙΠϯτ ɾStg/ຊ൪؀ڥͷߏ੒ʹ͍ͭͯ ɾSSH/࡞ۀ༻ίϯςφʮdevopsʯʹ͍ͭͯ ɾCircleCIʹΑΔίϯςφσϓϩΠ ɾECS Scheduled TasksʹΑΔόον࣮૷ʹ͍ͭͯ ɾϩά/ίϯςφ؂ࢹʹ͍ͭͯ ɾ·ͱΊ

Slide 3

Slide 3 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ࣗݾ঺հ

Slide 4

Slide 4 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ࣗݾ঺հ ɾ҆ୡ ྋ(adachin) ɾLancers SRE 2018~ ɾ@adachin0817 ɾRVIRUS0817 ɾblog.adachin.me ɾwiki.adachin.me ɾOSS : ɾCakePHPͰݸਓαʔϏε։ൃத

Slide 5

Slide 5 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ݱࡏऔΓ૊ΜͰ͍Δ͜ͱ

Slide 6

Slide 6 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ݱࡏऔΓ૊ΜͰ͍Δ͜ͱ ɾڈ೥ळ ɾάϧʔϓձࣾ(γΫϩϚʔέςΟϯά) ɾॳΊͯECS/FargateʹҠߦνϟϨϯδ ɾRuby on Rails ɾࠓ೥4݄ʹҠߦ׬ྃ ɾݱࡏ (5݄͔Β) ɾάϧʔϓձࣾ(Lancers Agency)ɹ ɾECS/FargateͰҠߦத(90%) ɹɾࠓճ͸ͪ͜Βͷ࿩Λ͠·͢!!

Slide 7

Slide 7 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ϥϯαʔζΤʔδΣϯγʔͷ αʔϏεʹ͍ͭͯ

Slide 8

Slide 8 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ϥϯαʔζΤʔδΣϯγʔͷαʔϏεʹ͍ͭͯ ɾPROsheetɺLancers Agent ɾ͘͞ΒͷΫϥ΢υ ɹɾPHP5.4 CakePHP2.5.4 ɹɾApache,MySQL5.7 ɾ։ൃ؀ڥ ɹɾVagrant,AnsibleͰ؅ཧ ɾίʔϙϨʔταΠτ ɹɾPHP5.5,MySQL5.7 ɾϝσΟΞαΠτ(WordPress) ɹɾPHP5.5,MySQL5.7

Slide 9

Slide 9 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ։ൃ؀ڥΛ࡞Δ ϙΠϯτ

Slide 10

Slide 10 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ։ൃ؀ڥΛ࡞ΔϙΠϯτ ɾຊ൪؀ڥͱಉ౳ͷߏ੒Λ࠶ݱ ɾELB(H2O)ίϯςφ(ϦόʔεϓϩΩγ) ɾAppίϯςφ ɹɾPHP5.5-alpine/CakePHP2.5.4/Nginx ɾMySQLίϯςφ ɾSendGridίϯςφ ɾphpMyAdminίϯςφ ɾWordPressίϯςφ(PHP7.3-alpine/Nginx) ɾ֤ΞϓϦέʔγϣϯͷىಈ͸SupervisorͰ؅ཧ ɾcomposer install͸AppίϯςφͰϩάΠϯ࣌ʹ࣮ߦ ɹɾsupervisorctlͰΞϓϦΛrestart͢ΔΑ͏ʹ

Slide 11

Slide 11 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 Stg/ຊ൪؀ڥͷ ߏ੒ʹ͍ͭͯ

Slide 12

Slide 12 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 Stg/ຊ൪؀ڥͷߏ੒ʹ͍ͭͯ ɾTerraformͰશϦιʔείʔυԽ ɾStg؀ڥ͸ۃྗίετΛ཈͑λεΫ਺͸1ͭ ɾdevopsίϯςφͷར༻ ɾDB͸RDS AuroraʹҠߦ ɾϝʔϧૹ৴͸Postfix͔ΒSendGridԽ ɾίʔϙϨʔταΠτ͸WordPressԽ ɾը૾౳S3Խ ɾWordPressͷը૾ ɹɾWP Offload Media LiteϓϥάΠϯͰS3ʹ ɾϩά͸CloudWatch Logs ɾόον͸ECS Scheduled Tasks ɾ಺෦؂ࠪ(ϩάͷू໿) ɹɾAmazon Kinesis ɾσϓϩΠ͸CircleCIͷΈͰ࣮૷ ɾ؂ࢹ͸Datadog

Slide 13

Slide 13 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 SSH/࡞ۀ༻ίϯςφ ʮdevopsʯʹ͍ͭͯ

Slide 14

Slide 14 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 SSH/࡞ۀ༻ίϯςφʮdevopsʯʹ͍ͭͯ ɾAppʹ͸SSH͠ͳ͍ ɾSSH/࡞ۀ༻ίϯςφ(Appͱಉ౳) ɹɾdevopsͱ໋໊ ɾίϚϯυͰRDS΁઀ଓ ɹɾdump΍restore ɾaws cliͷར༻ ɾSSMͷSession Manager ΋͋Δ͕ ɹɾखܰʹ౿Έ୆͔ΒSSHΛ͍ͨͨ͠Ί ɾVPC PeeringͰϥϯαʔζͷωοτϫʔΫ͔ΒSSHϩάΠϯ

Slide 15

Slide 15 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 CircleCIʹΑΔ ίϯςφσϓϩΠʹ͍ͭͯ

Slide 16

Slide 16 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 APIܦ༝ͰͷStg؀ڥͷσϓϩΠ ɾStg؀ڥͷσϓϩΠ ɹɾgithub flow ɹɾγΣϧεΫϦϓτ ɹɹɾ೚ҙͷϒϥϯνΛࢦఆ ɾૉૣ͘σϓϩΠ͕Մೳ ɹɾ։ൃޮ཰͕Ξοϓ ɾMasterϚʔδͰຊ൪؀ڥϦϦʔε ɾTerraform CI؀ڥΛ࣮૷ $ sh deploy.sh ԼهͷΑ͏ʹϒϥϯνΛࢦఆ࣮ͯ͠ߦ͍ͯͩ͘͠͞ɻ (ྫ) sh deploy.sh ϒϥϯν໊ $ sh deploy.sh fix-nginx { "number" : 74, "state" : "pending", "id" : "xxxxxx-xxxxx-xxxxx-xxx-xxxxxxxx", "created_at" : "2020-08-27T06:14:43.973Z" } ϒϥϯν໊/ fix-nginx ͷStgσϓϩΠΛ։࢝͠·ͨ͠!

Slide 17

Slide 17 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 όονͷ࣮૷ʹ͍ͭͯ

Slide 18

Slide 18 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ECS Scheduled TasksʹΑΔόον࣮૷ʹ͍ͭͯ ɾࠓ·Ͱ ɹɾCron ɾݱࡏ ɹɾECS Scheduled Tasks ɹɹɾCloudWatchͷΠϕϯτϧʔϧ ɹɹɾTerraformԽ { "containerOverrides": [ { "name": "prosheet-app", "command": [ "php", "/var/www/prosheet/cake/app/Console/cake.php", "-app", "/var/www/prosheet/cake/app", "mail", "exec" ] } ]

Slide 19

Slide 19 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ϩάʗίϯςφ؂ࢹ ʹ͍ͭͯ

Slide 20

Slide 20 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ϩά/ίϯςφ؂ࢹʹ͍ͭͯ ɾΞΫηε/ΞϓϦϩάɺRDS؂ࠪ/Τϥʔϩά ɹɾCloudWatch Logsʹ ɹɾࠓ·Ͱ ɹɹɾLambdaͰS3ʹγϯΫɹɹ ɹɹɾPythonͰ࣮૷͍ͯͨͨ͠Ίӡ༻ίετΞοϓ ɹɾࠓճ ɹɹɾAmazon Kinesis Data FirehoseͰS3ʹू໿ ɹɹɾTerraformԽ ɾ؂ࢹ ɹɾMackerel→DatadogʹҠߦ ɹɾλεΫఆٛʹdatadog-agentΛಈ࡞ͤ͞ΔΑ͏ʹ ɹɾcpu:10ɺmemory:256 TerraformԽ

Slide 21

Slide 21 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ·ͱΊ

Slide 22

Slide 22 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ·ͱΊ ɾImmutableͳαʔόʔͷӡ༻ ɹɾ҆ఆӡ༻ɺӡ༻ޮ཰ͷΞοϓ ɾϗετΠϯελϯεͷ؅ཧ͕ল͚Δ ɾλεΫ୯ҐͰࣗ༝ʹϦιʔεมߋՄೳ ɾॳΊͯίϯςφຊ൪ӡ༻͢Δʹ͸͔ͳΓϋϚΔ ɹɾϔϧενΣοΫ͕௨Βͳ͍ͱίϯςφ͕མͪΔ ɹɾLinuxྗ͕ࢼ͞ΕΔ ɹɾσϓϩΠͷ࣮૷͕େม͕ͩલͷܦݧ͕͋ͬͨ ɹɹɾ͙͢ʹ࣮૷Ͱ͖ͨ ɾσόοά͕ͮ͠Β͍ ɾλεΫͷىಈ଎౓͕஗Ί ɹɾόον࣮ߦ΋਺෼஗͘ͳΔ ɾྉ͕͓ۚߴΊ ɹɾEC2ΑΓׂߴʢ1ׂʙ2ׂʣ ɾࠓޙ ɹɾ·ͣ͸དྷ݄தʹҠߦ ɹɾPHP/CakePHPͷόʔδϣϯΞοϓ ɹɾίϯςφͷ੬ऑੑݕ஌ (Trivy) ɹɾDatadogͰϩά࿈ܞ ɹɾChatOpsʹΑΔσϓϩΠ ɹɾPHP CI؀ڥͷ࣮૷ ɹɾϥϯαʔζຊՈ΋ίϯςφҠߦʹνϟϨϯδ

Slide 23

Slide 23 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 SREٻΉʂʂ

Slide 24

Slide 24 text

2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2