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

Lancersをコンテナへ本番移行する取り組み

 Lancersをコンテナへ本番移行する取り組み

adachin0817

June 29, 2022
Tweet

More Decks by adachin0817

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • ҆ୡ ྋ(adachin) • Lancers/SRE 
 2018/5~ • @adachin0817

    • RVIRUS0817 • blog.adachin.me • wiki.adachin.me • ݸਓαʔϏε։ൃத(ਐḿѱ) ʲLancers x dipʳEngineer Meetup #1
  2. ࠓճ͓࿩͍ͨ͜͠ͱ • 2018೥ͷγεςϜ • TerraformԽਪਐ • Amazon Linux2Խ • ϩάαʔόʔͷഇࢭ

    • ։ൃ؀ڥͷվળ • ϑϩϯτΤϯυͷվળ • چ։ൃ؀ڥɺEC2Ͱͷӡ༻՝୊ • Batch/AppΛίϯςφ΁ • ࣗલσϓϩΠγεςϜΛഇࢭ • ෛՙରࡦͱϨεϙϯε • ·ͱΊ ʲLancers x dipʳEngineer Meetup #1
  3. Ұ෦TerraformԽΛ͍ͯ͠Δ͕׬શͰ͸ͳ͍ • άϧʔϓձࣾ͸શͯTerraformԽ • ຊՈ͸Ұ෦͔͠TerraformԽ͞Ε͍ͯͳ͍ 
 ɾηΩϡϦςΟʔάϧʔϓIDͳͲΛͦͷ··ࢦఆ 
 ɾEC2Ͱͷߏங͸ಠࣗͷAWS CLIͰࣗಈԽ

    
 ɾͦΕҎ֎͸खಈͰઃఆ • શͯΛterraform importΛ͢Δʹ͸ݫ͍͠ 
 ɾϑΣʔζ͝ͱʹऔΓ૊Ή͜ͱʹ ʲLancers x dipʳEngineer Meetup #1
  4. Terraform Phase 1 • VPC 
 ɾαϒωοτ 
 ɾϧʔτςʔϒϧ 


    ɾΠϯλʔωοτήʔτ΢ΣΠ 
 ɾNatήʔτ΢ΣΠ 
 ɾΤϯυϙΠϯτ 
 ɾηΩϡϦςΟάϧʔϓ • ELB 
 ɾλʔήοτάϧʔϓ 
 ɾϦεφʔϧʔϧ ʲLancers x dipʳEngineer Meetup #1 • EC2 • RDS • ACM • εςʔδϯάͱຊ൪؀ڥ߹Θͤͯ 
 ɾ໿1ϲ݄൒ 
 ɾͦΕҎ֎͸ࠓظରԠ
  5. EC2ΛAmazon Linux 2Խ • Amazon Linux1Ͱӡ༻ 
 ɾAppɺ؅ཧը໘(Admin)ɺBatchαʔόʔ 
 ɾ2020೥6݄3೔ʹηΩϡϦςΟΞοϓσʔτͷఏڙ͕ऴྃ

    • άϧʔϓձࣾͷҠߦ͕ॏͳΓରԠͰ͖ͣ • ͞ΒʹArm͕ରԠ͞ΕͯύϑΥʔϚϯε্͕ঢͱίετ࡟ݮ • άϧʔϓձࣾͷίϯςφͷϊ΢ϋ΢͕ߴ·ΓҠߦΛܾҙ 
 ɾಉ࣌ʹMySQL8Խ΋औΓ૊Ή͜ͱʹ 
 ʲLancers x dipʳEngineer Meetup #1
  6. ϩάαʔόʔ͕୯Ұো֐఺ • ෼ੳج൫(Digdag/Embulk/BigQuery/Redash)Λӡ༻ 
 ɾϩάج൫(Fluentd) 
 ɾApp(ΞΫηεϩά/ΞϓϦέʔγϣϯϩά) 
 ɹɾS3ʹू໿ •

    ਖ਼ৗʹಈ࡞͍ͯ͠ͳ͍ঢ়ଶ͕౓ʑݟड͚ΒΕ 
 ɾϒϥοΫϘοΫεԽͱ௕೥ͷ՝୊ʹ… • td-agentͷόʔδϣϯΞοϓΛࢼΈ͕ͨ 
 ɾ͏·͍͔͓ͣ͘ख্͛ঢ়ଶ ʲLancers x dipʳEngineer Meetup #1
  7. Amazon KinesisʹҠߦ • CloudWatch Logs(awslogs)Λ࠾༻ 
 ɾ։ൃϝϯόʔͰ΋ௐࠪͰ͖ΔΑ͏ʹ 
 ɾൺֱతֶशίετ͕௿͍awslogsΛબ୒ •

    ϩάϙϦγʔΛݟ௚͢ 
 ɾΞΫηεϩά͸S3ʹू໿ͷ·· 
 ɾΞϓϦϩά͸෼ੳ༻్ͱͯ͠ར༻͠ͳ͍ • Datadog LogsͰKinesisͷ࿈ܞ 
 ɾΞϓϦνʔϜ΋ॠ࣌ʹରԠՄೳ 
 ɾՄ؍ଌੑΛߴΊΒΕΔΑ͏ʹ • ίϯςφʹҠߦ͢Δ४උ͕੔ͬͨ ʲLancers x dipʳEngineer Meetup #1
  8. ։ൃ؀ڥͷमਖ਼ • ։ൃ؀ڥ͸ຊ൪ಉ౳Λ࠶ݱ 
 ɾAnsibleίϯςφ 
 ɹɾύοέʔδΠϯετʔϧ • มߋ఺ 


    ɾDocker Image͸amazonlinux2 
 ɾsupervisorͰϓϩηε؅ཧ 
 ɾෆཁͳύοέʔδΛચ͍ग़͠࡟আ 
 ɾamazon-linux-extrasʹΑΔPHPΠϯετʔϧ 
 ɾtd-agentͷ࡟আͱawslogsͷΠϯετʔϧ • ؅ཧը໘͸ECS/FargateʹҠߦ͢ΔͨΊ 
 ɾDocker fi leΛҰ͔Βbuild͢ΔΑ͏ʹ ʲLancers x dipʳEngineer Meetup #1
  9. Ҡߦ͢Δʹ͋ͨͬͯ • ؅ཧը໘(Admin)͸ECS/FargateʹҠߦ 
 ɾCakePHP2͸EC2 
 ɾCakePHP4͸ECS/FargateͰಈ࡞ • Batch͸ArmʹҠߦ •

    App͸ArmʹҠߦͰ͖ͣintelͰӡ༻ 
 ɾDatadog 
 ɹɾdd-trace-php͕ArmΛαϙʔτ❌ ʲLancers x dipʳEngineer Meetup #1
  10. ϑϩϯτΤϯυͷωοΫͱվળ • ιʔείʔυ͕5GBҎ্ 
 ɾyarn installͰ30෼Ҏ্͔͔Δ 
 ɾίϯςφσϓϩΠͰ͕࣌ؒ๲େʹ͔͔Δ • ϑϩϯτΤϯυΛ෼ׂ͔ͯ͠ΒҠߦ

    
 ɾιʔεߏ଄্ɺύεʹΑΔॲཧ෼ׂ͕ࠔ೉Ͱ޻਺͕͔͔Δ • ༧ΊϩʔΧϧͰϏϧυͯ͠ੜ੒͞ΕͨϑΝΠϧΛGit؅ཧ͢Δӡ༻ 
 ɾyarn install͸ෆཁʹͳΓɺCI͕࣌ؒେ෯ʹ୹ॖ 
 ɾAppαʔόʔͷίϯςφ΁ҠߦͰ͖Δ৚͕݅੔ͬͨ ʲLancers x dipʳEngineer Meetup #1
  11. ৽։ൃ؀ڥ • Docker fi leʹΑΔҰൠతͳӡ༻ • ผϦϙδτϦ(playbook) 
 ɾLancersຊମͷϦϙδτϦʹ౷Ұ •

    Ansibleίϯςφ͸ഇࢭ • ϩάج൫Ͱར༻ 
 ɾEC2ͱಉ༷awslogsΛΠϯετʔϧ ʲLancers x dipʳEngineer Meetup #1
  12. Batchαʔόʔ͸ECS Scheduled TaskʹҠߦ • όον͸100ݸҎ্ 
 ɾ৑௕ԽͤͣEC2 1୆ͷΈͰӡ༻ 
 ɾαʔόʔμ΢ϯ΍AZো֐͕ى͖Δͱ

    
 ɹɾαʔϏεʹӨڹ͕ग़ͯ͠·͏ঢ়گ • CakePHP4 
 ɾ80ݸͷΈҠߦ 
 ɾ։ൃϝϯόʔ͕TerraformͰ؅ཧͰ͖ΔΑ͏ʹ • CloudWatch LogsɺSNSɺLambdaͰΤϥʔ௨஌ • CakePHP2ͷόον͸QAνʔϜ͕Ҡߦத ʲLancers x dipʳEngineer Meetup #1
  13. ʮDeploy-Sanʯ • 2015~ 
 ɾRuby on RailsͱJenkins 
 ɾಠࣗγΣϧͰrsync •

    Φʔτεέʔϧ࣌ 
 ɾDeploy-san͔Β࠷৽ͷίʔυΛऔಘ 
 ɾ୯Ұো֐఺ • ϦϦʔε࣌ؒ 
 ɾࠩ෼ߋ৽Ͱ1෼Ҏ಺ ʲLancers x dipʳEngineer Meetup #1
  14. CI/CDΛCircleCIʹҠߦ • MasterϚʔδ:ຊ൪ 
 APIܦ༝:εςʔδϯά/ΧφϦΞ • ίϯςφσϓϩΠߴ଎Խ 
 ɾ.dockerignoreʹΑΔෆཁͳϑΝΠϧ͸ল͘ 


    ɾDocker fi leͰෆཁͳύοέʔδͷ୨Է͠ 
 ɾCircleCIͷcheckout_shallowΛར༻ 
 ɹɾ࠷ޙͷίϛοτͷΈcheckout 
 ɾremote-docker-layer-cachingΛ༗ޮԽ • 5෼Ҏ಺·ͰॖΊΔ͜ͱ͕Ͱ͖ͨ ʲLancers x dipʳEngineer Meetup #1
  15. ΧφϦΞ؀ڥͷσϓϩΠΛ੍ݶ • ຊ൪DBΛࢀর 
 ɾΧφϦΞ؀ڥʹ୭Ͱ΋ϦϦʔεͰ͖ͯ͠·͏ • CircleCI 
 ɾcontext 


    ɹɾSecurity Group 
 ɹɾGitHub Teamsͷݖݶ͋ΔਓͷΈঝೝ • https://wiki.adachin.me/archives/1313/ ʲLancers x dipʳEngineer Meetup #1
  16. ෛՙରࡦ • EC2࣌୅ 
 ɾc5ܥΠϯελϯε 
 ɾECSͩͱCPU͸બ୒Ͱ͖ͳ͍ • Fargate Spot

    
 ɾطଘͷ3୆͸Fargate 
 ɾΦʔτεέʔϧ͸Fargate Spot(ίετ࡟ݮ) • Φʔτεέʔϧ 
 ɾ୆਺͸࠷খͰ3୆ɺ࠷େͰ20୆ 
 ɾCPU 20%Ͱ૿Ճ 10%Ͱݮগ • php-fpm΋νϡʔχϯά͠௚ͨ͠ ʲLancers x dipʳEngineer Meetup #1
  17. ·ͱΊ • ໿1೥Ͱ΍Γ͖Δ͜ͱ͕Ͱ͖ͨ 
 ɾάϧʔϓձࣾͰͷϊ΢ϋ΢Λ׆͔ͤͨ • ੜ࢈ੑ޲্͕ظ଴ 
 ɾSREͷτΠϧ࡟ݮ 


    ɾ։ൃ෦શମͷϦϦʔεϑϩʔվળ • ࠓޙ 
 ɾϑϩϯτΤϯυͷϞμϯԽ 
 ɾPHP8.1/CakePHPͷόʔδϣϯΞοϓ ʲLancers x dipʳEngineer Meetup #1