Slide 1

Slide 1 text

AWSͷΦʔτεέʔϧͱ ͳ͔Α͘෇͖߹͏ YAP(achimon)C::Asia Hachioji 2016 mid 2016-07-02 @fujiwara

Slide 2

Slide 2 text

@fujiwara github.com/fujiwara sfujiwara.hatenablog.com ٕज़෦

Slide 3

Slide 3 text

Agenda • ΦʔτεέʔϧͬͯԿ • ͳͥΦʔτεέʔϧ͢Δͷ͔ • ͦ΋ͦ΋Φʔτεέʔϧ͢Δ΂͖? • Ͳ͏͍͏৚݅ͰΦʔτεέʔϧΛൃಈ͢Δ͔ • ຊ౰ʹى͖ͨා͍࿩

Slide 4

Slide 4 text

Φʔτεέʔϧͱ͸

Slide 5

Slide 5 text

AWSͷΦʔτεέʔϧ ΞϓϦέʔγϣϯͷෛՙΛॲཧ͢ΔͨΊʹ ద੾ͳ਺ͷEC2ΠϯελϯεΛىಈ͢Δ࢓૊Έ

Slide 6

Slide 6 text

ͳͥΦʔτεέʔϧ͢Δͷ͔

Slide 7

Slide 7 text

ͳͥΦʔτεέʔϧ͢Δͷ͔ ΞΫηε਺(≒ෛՙ)͸1೔ͷதͰมಈ͢Δ

Slide 8

Slide 8 text

ͳͥΦʔτεέʔϧ͢Δͷ͔ min : avg : max = 200 : 1000 : 3000 ϐʔΫ࣌ͷෛՙ͸1೔ฏۉͷ3ഒ ϐʔΫΛ૝ఆͨ͠ΠϯελϯεΛৗ࣌ىಈ͢Δͱ ! ෛՙʹԠͯ͡Πϯελϯε୆਺Λௐ੔͢Ε͹અ໿Ͱ͖Δ

Slide 9

Slide 9 text

ͳͥΦʔτεέʔϧ͢Δͷ͔ ʰಥൃతͳෛՙʹ΋ରԠͰ͖Δʱ • ͋Δఔ౓·Ͱԣʹ૿΍ͤΔ΋ͷͰ͋Ε͹ ⭕ • ྫ͑͹RDS͕ϘτϧωοΫʹͳΔͱ… ❓ • ෛՙͷ૿େ͕଎͗͢Δͱؒʹ߹Θͳ͍

Slide 10

Slide 10 text

ͳͥΦʔτεέʔϧ͢Δͷ͔ ͦͷଞʹ΋خ͍͠(ؾΛ͚ͭΔ)͜ͱ • ো֐͕ൃੜͨ͠Πϯελϯε͸ࣗಈͰ࡟আ(terminate) • ৽͍͠Πϯελϯε͕ࣗಈͰىಈ • ઃఆ͞Εͨ୆਺Λอͱ͏ͱͯ͘͠ΕΔ ! Πϯελϯεো֐Ͱ࠶ىಈෆཁ " ࡟আ͞ΕͨΠϯελϯεͷEBS͸ফ໓

Slide 11

Slide 11 text

ͦ΋ͦ΋Φʔτεέʔϧ͢Δ΂͖ʁ

Slide 12

Slide 12 text

ͦ΋ͦ΋Φʔτεέʔϧ͢Δ΂͖ʁ 16ίΞϚγϯ͕ϐʔΫͰ30୆ඞཁͳγεςϜ ! c4.4xlarge(16 cores) $776.66/month • avg: × 10 = $7,766 / month • max: x 30 = $23,299 / month ฏۉ10୆ʹ཈͑ΒΕΕ͹ֹࠩ͸20୆෼ $15,533 ≒ 150ສԁ ͋Δఔ౓ͷن໛͕͋Ε͹࡟ݮֹ͕େ͖͍

Slide 13

Slide 13 text

ن໛͕ͦΕ΄ͲͰ΋ͳ͍৔߹ 4ίΞϚγϯ͕ϐʔΫͰ6୆ඞཁͳγεςϜ ! c4.xlarge(4 cores) $193.98/month • avg: × 4 = $776 / month • max: x 6 = $1,164 / month ࠷௿3୆͸ಈ͔͍ͨ͠ͷͰavg = max / 3 ʹ͸ͳΒͳ͍ ֹࠩ͸2୆෼ $387 ఔ౓ɺݻఆඅͱൺ΂Δͱ…

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

ͦ΋ͦ΋Φʔτεέʔϧ͢Δ΂͖ʁ·ͱΊ ΦʔτεέʔϧΛߟྀ͍ͯ͠ͳ͍γεςϜʹޙ͔Βಋೖ͢Δʹ ͸͍Ζ͍Ζඞཁ ӡ༻த΋҆ఆ͢Δ·Ͱ͸͍Ζ͍Ζ͋Δ ಋೖɺӡ༻ίετ͕࡟ݮίετʹݟ߹͏͔Ͳ͏͔൑அ

Slide 16

Slide 16 text

Auto Scaling ུ֓

Slide 17

Slide 17 text

Auto Scaling Group Πϯελϯεͷ·ͱ·Γ͝ͱʹ Auto Scaling GroupΛఆٛ • ୆਺ͷ࠷খ(min)ɺ࠷େ(max)ɺر๬ (desired) • ؔ࿈͚ͮΔ ELB • ىಈઃఆ (Launch Configuration) • εέʔϦϯάϙϦγʔ

Slide 18

Slide 18 text

࠷খ୆਺ (min) ❌ ͜ͷ୆਺ҎԼʹ͸ݮΒͳ͍ ⭕ ͜ͷ୆਺Λ࠷௿ݶҡ࣋͠Α͏ͱ͢Δ min: 3, ݱࡏ3୆ͷঢ়ଶͰ1୆͕ϔϧενΣοΫࣦഊ → ৽͍͠Πϯελϯε͕ىಈ͞ΕΔ → ࣦഊͨ͠Πϯελϯε͕࡟আ͞ΕΔ Ұ࣌తʹ͸minΛԼճΔ͜ͱ͕͋Δ

Slide 19

Slide 19 text

ر๬୆਺ (desired) ͜ͷ୆਺Λҡ࣋͠Α͏ͱ͢Δ εέʔϦϯάϙϦγʔʹΑͬͯ desired ͕มߋ͞ΕΔ → Πϯελϯε͕ىಈ/࡟আ͞ΕΔ → desiredΛຬͨͨ͠Β׬ྃ ىಈࣦഊͨ͠৔߹͸ɺdesiredΛຬͨ͢·ͰϦτϥΠ ͏·͘ىಈ͠ͳ͍AMIΛ࡞ͬͯ͠·͏ͱӬԕʹ…!

Slide 20

Slide 20 text

࠷େ୆਺ (max) ͜ͷ୆਺Ҏ্͸ىಈ͠ͳ͍ ઃఆϛεͰͷىಈ͗͢͠Λ๷ࢭͰ͖Δ ෛՙ૿େ࣌ʹఱҪʹ౰ͨΔՄೳੑ͕͋ΔͷͰؾΛ͚͓ͭͯ͘

Slide 21

Slide 21 text

εέʔϦϯάϙϦγʔ Ͳ͏͍͏৚݅ͰdesiredΛ૿Ճɺݮগͤ͞Δ͔ɺͱ͍͏ఆٛ CloudWatchͷϝτϦΫεΛݩʹͨ͠ΞϥʔϜΛτϦΨʹ͢Δ • Auto Scaling Group಺ͷEC2 CPU࢖༻཰ • ओʹWebΞϓϦέʔγϣϯ޲͚ • Amazon SQS ͷΩϡʔʹཷ·͍ͬͯΔ਺ • ඇಉظδϣϒॲཧαʔό(ಈըม׵ͳͲ)޲͚

Slide 22

Slide 22 text

spot or on demand? ΦϯσϚϯυΠϯελϯε͔εϙοτΠϯελϯε͔ Φʔτεέʔϧʹ͸ͲͪΒͰ΋ར༻Մೳ(LaunchConfigͰࢦఆ) ΦϯσϚϯυΠϯελϯε ͍ͭͰ΋ಉҰՁ֨ͰىಈͰ͖Δ (εϙοτͱൺ΂Δͱ)ߴ͍ WebΞϓϦέʔγϣϯαʔό޲͖

Slide 23

Slide 23 text

spot or on demand? εϙοτΠϯελϯε ಈ࡞தͷεϙοτՁ֨ (धཁͱڙڅͰܾఆ)Ͱֹ͕ܾۚ·Δ ͍҆ (͍͍ͨͯͷ৔߹ΦϯσϚϯυͷ1/5ʙ1/10) ߴಅ͢Δ͜ͱ͕͋Δ (ΦϯσϚϯυՁ֨ͷ਺ഒ΋) ೖࡳՁ֨ΛεϙοτՁ্͕֨ճΔͱΠϯελϯε࡟আ → શ໓͢ΔՄೳੑ͕͋Δ ଟগͷॲཧ஗Ԇ͕ڐ͞ΕΔδϣϒϫʔΧʔ޲͖

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

γεςϜΛΦʔτεέʔϧʹ ରԠͤ͞Δ

Slide 26

Slide 26 text

γεςϜΛΦʔτεέʔϧʹରԠͤ͞Δ ʮAMI͔Βىಈ͢Δ͚ͩͰɺਖ਼ৗʹՔಇ͢Δঢ়ଶʹͳΔʯ ͜ͷঢ়ଶΛ࡞Βͳ͍ͱΦʔτεέʔϧʹରԠͰ͖ͳ͍ • ϓϩϏδϣχϯά/σϓϩΠ • ؂ࢹ • ϩάసૹ

Slide 27

Slide 27 text

ϓϩϏδϣχϯάɺσϓϩΠख๏ ❌ σϓϩΠ͍ͨ͠λΠϛϯάͰ push ⭕ ىಈͨ͠Πϯελϯε͕ pull ΠϯελϯεΛىಈͨ࣌͠఺Ͱͷਓؒͷ࡞ۀΛෆཁʹ͢Δ

Slide 28

Slide 28 text

AMIΛຖճ࡞Δ ϓϩϏδϣχϯάɺΞϓϦέʔγϣϯͷσϓϩΠ͕׬ྃͨ͠ঢ় ଶͰAMIΛ࡞Γ௚͢ˠ ىಈ͢Δ͚ͩͰOK ϝϦοτ • ىಈ͢Δ͚ͩɺىಈޙʹ͸Կ΋ඞཁͳ͍ σϝϦοτ • ઃఆมߋɺΞϓϦέʔγϣϯमਖ਼ͰຖճAMIΛ࡞Γ௚͢खؒ • มߋ͝ͱʹΠϯελϯεΛશ෦ೖΕସ͑

Slide 29

Slide 29 text

AMIΛຖճ࡞Δ • σϓϩΠස౓͕ଟ͘ͳ͍αʔϏεͳΒՄೳ (10ճ/೔͸೉͍͔͠΋…) • ݻఆͷΠϯελϯε͕͋Δ৔߹͸Ͳ͏͢Δ…ʁ (σʔλετΞͳͲ͕ϚωʔδυαʔϏεͰ͸ͳ͍৔߹)

Slide 30

Slide 30 text

ϓϧܕͷϓϩϏδϣχϯάɺσϓϩΠख๏ S3ͳͲʹΞʔΧΠϒΛอଘɺ֤ΠϯελϯεͰऔಘɺల։͢Δ AWS CodeDeploy Mamiya github.com/sorah/mamiya Stretcher github.com/fujiwara/stretcher

Slide 31

Slide 31 text

ϓϧܕͷϓϩϏδϣχϯάɺσϓϩΠख๏ Πϯελϯε͕ىಈ࣌ʹࣗΒ࠷৽ͷ΋ͷΛऔಘɺ࣮ߦ S3ΛόοΫΤϯυʹ͢Ε͹Մ༻ੑ΋ ⭕ σϓϩΠ΋଎͍

Slide 32

Slide 32 text

⾠ rsyncͳͲͰϓϧܕσϓϩΠΛࣗ࡞͢Δ build్தͷத్൒୺ͳঢ়ଶ͕औಘ͞Εͳ͍Α͏஫ҙ → Πϯελϯεىಈத͸σϓϩΠ࡞ۀΛ͠ͳ͍(ͱ͔) औಘݩΛߴՄ༻/ߴੑೳʹ͢Δඞཁ͕͋Δ

Slide 33

Slide 33 text

⾠ Git͔Βऔಘͯ͠σϓϩΠ͢Δ ʮGit͸σϓϩΠπʔϧͰ͸͋Γ·ͤΜʯ খن໛ͳΒ໰୊ͳ͍ ن໛͕େ͖͘ͳΔͱGitαʔόͷෛՙ͕ਂࠁ ৄ͘͠͸ YAPC::Asia 2015 ੈքల։͢Δେن໛΢ΣϒαʔϏεͷσϓϩΠΛࢧ͑Δٕज़ https://speakerdeck.com/hatena/yapc-asia-tokyo-2015

Slide 34

Slide 34 text

γεςϜΛΦʔτεέʔϧʹରԠͤ͞Δ ·ͱΊ ىಈͨ͠Πϯελϯε͕ࣗ཯͢Δ ͋Δϗετ͔Βશ୆ʹ˓˓(ssh)ɺͱ͍͏ൃ૝Λ΍ΊΔ

Slide 35

Slide 35 text

؂ࢹ

Slide 36

Slide 36 text

؂ࢹͰඞཁͳ͜ͱ ಈతʹ؂ࢹର৅Λ૿ݮͰ͖ΔπʔϧΛ࢖͏ agentΛىಈ͢Δ͚ͩͰ؂ࢹର৅ʹ௥Ճ agentىಈΛܖػʹࣗಈొ࿥ઃఆ͕Մೳ APIͰϗετొ࿥΋Մೳ

Slide 37

Slide 37 text

؂ࢹͰඞཁͳ͜ͱ ΦʔτεέʔϦϯάάϧʔϓશ୆Λू໿ͨ͠ϝτϦΫεΛΈΔ • CPU࢖༻཰ͳͲ

Slide 38

Slide 38 text

؂ࢹͰඞཁͳ͜ͱ 1୆མ͙ͪͨΒ͍Ͱ͘Α͘Α͠ͳ͍ େྔʹىಈ͢Ε͹མͪΔ΍ͭ΋͍Δ Πϯελϯεఀࢭ࣌ʹ؂ࢹఀࢭʹࣦഊ͢Δ͜ͱ΋͋Δ ZabbixͰͷτϦΨͷྫ grpavg["AutoScale","icmpping[]",last,0].last(0)<0.7 ʮϗετάϧʔϓ಺Ͱping੒ޭׂͨ͠߹͕70%ΛԼճͬͨΒʯ

Slide 39

Slide 39 text

؂ࢹͰඞཁͳ͜ͱ ELBͷ UnHealthyHostCount ͕Ͳ͏ͯ͠΋্͕Δ ʰʮUnHealthyHostCount > 0ʯ͕7෼ؒܧଓͨ͠Βܯࠂʱ

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

ϩάΛ଎΍͔ʹΠϯελϯε֎ʹసૹ͢Δ ΦʔτεέʔϧͷΠϯελϯε͕࡟আ(terminate)͞ΕΔͱ ʮEBS΋ফ͑·͢ʯ

Slide 42

Slide 42 text

؂ࢹͱϩάʹ͍ͭͯ ·ͱΊ γεςϜશମͱ݈ͯ͠શ͔Ͳ͏͔ΛΈΔ ݸผͷΠϯεϯλϯεʹͩ͜ΘΓ͗͢ͳ͍ → ϓϩηεΈ͍ͨͳ ΋ͷ ΠϯελϯεʹӬଓ෺Λ࢒͞ͳ͍ → ϝϞϦΈ͍ͨͳ΋ͷ

Slide 43

Slide 43 text

Ͳ͏͍͏৚݅Ͱ ΦʔτεέʔϧΛൃಈ͢Δ͔

Slide 44

Slide 44 text

εέʔϦϯάϙϦγʔ ΞϓϦέʔγϣϯαʔόͷ৔߹ͷྫ • ௚ۙ5෼ؒͷʮฏۉʯCPU࢖༻཰͕50%Λ௒͑ͨΒ → ݱࡏͷ୆਺ͷ40%ͷ୆਺Λىಈ → 7෼ͳʹ΋͠ͳ͍(ΠϯελϯεىಈΛ଴ͭ) • ௚ۙ1࣌ؒͷʮ࠷ߴʯCPU࢖༻཰͕25%Λ੾ͬͨΒ → 1୆ఀࢭ → 3෼ͳʹ΋͠ͳ͍(Ұؾʹམͪ͗͢ͳ͍Α͏ʹ)

Slide 45

Slide 45 text

CPU࢖༻཰(ੵΈ্͛), CPU idle(ฏۉ), ϨεϙϯελΠϜ෼෍

Slide 46

Slide 46 text

ΠϯελϯεΛ૿΍͢ͱ͖ͷίπ CPU 40ʙ50%͙Β͍Ͱىಈ͢Δ • CPU࢖༻཰্͕͕Δͱॲཧೳྗ͕ઢܗൺྫ͠ͳ͘ͳΔ 100%Ͱ50%ͷ2ഒॲཧͰ͖ΔΘ͚Ͱ͸ͳ͍ • Πϯελϯεىಈ·ͰͷϥάΛߟྀ͢Δ 3ʙ5෼ఔ౓͸଱͑ΒΕΔ͏ͪʹൃಈ͓ͯ͘͠

Slide 47

Slide 47 text

ΠϯελϯεΛ૿΍͢ͱ͖ͷίπ ݱࡏͷ40%ͷ୆਺ɺ࠷௿2୆ىಈ͢Δ • 10୆͋Δͱ͖ʹ1୆૿΍ͯ͠΋ॲཧೳྗ͸ʴ10%͚ͩ +40%͕2ճൃಈ͢Ε͹໿2ഒʹͳΔ • Πϯελϯε͸ৗʹىಈ੒ޭ͢Δͱ͸ݶΒͳ͍ AWSଆͷ໰୊ɺϓϩϏδϣχϯά΍σϓϩΠࣦഊ

Slide 48

Slide 48 text

ΠϯελϯεΛݮΒ͢ͱ͖ͷίπ ௚ۙ1࣌ؒͷʮ࠷ߴʯCPU࢖༻཰͕25%ҎԼ 1୆ͣͭམͱͯ͠3෼଴ͭ • ʮ୹͍࣌ؒʯͷʮฏۉʯͰམͱ͞ͳ͍ ૿͑Δͱ༨༟͕Ͱ͖ΔˠམͪΔˠෛՙ্͕Δˠىಈ! ༨༟͕े෼͋Δঢ়ଶ͕௕࣌ؒଓ͍ͨΒམͱ͢ • Ұؾʹམͱ͢ˠෛՙ্͕͕Δˠىಈ!

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

εέʔϦϯάϙϦγʔ·ͱΊ ૿΍͢ͱ͖͸େ୾ʹ → ଍Γͳ͚Ε͹ো֐ ݮΒ͢ͱ͖͸ண࣮ʹ → ݮΒ͗ͨ͢͠Βো֐ ᮢ஋Λ߈Ί͗͢ͳ͍

Slide 51

Slide 51 text

ϔϧενΣοΫ

Slide 52

Slide 52 text

ELBʹ૊ΈࠐΉͨΊʹ͸ϔϧενΣοΫ͕ඞཁ 1. EC2Πϯελϯε͕ੜ͖͍ͯΔ 2. (ELB͔Β)TCPͰ઀ଓͰ͖Δ 3. (ELB͔Β)HTTPͰԠ౴Λ200Ͱฦ͢ ԿΛ࣋ͬͯਖ਼ৗͱ൑அ͢Δ͔

Slide 53

Slide 53 text

ELBʹ૊ΈࠐΉͨΊʹ͸ϔϧενΣοΫ͕ඞཁ 1. ❌ EC2Πϯελϯε͕ੜ͖͍ͯΔ → Πϯελϯεىಈ ≠ ΞϓϦέʔγϣϯͷ४උ 2. ❌ TCPͰ઀ଓͰ͖Δ → Webαʔόىಈ ≠ ΞϓϦέʔγϣϯαʔόͷ४උ 3. ⭕ HTTPͰԠ౴Λ200Ͱฦ͢ GET /ping HTTP/1.0 ΞϓϦέʔγϣϯαʔόͰDB઀ଓͳͲ΋νΣοΫ͢Δ

Slide 54

Slide 54 text

ELBʹ૊ΈࠐΉͨΊʹ͸ϔϧενΣοΫ͕ඞཁ Πϯελϯε͸ىಈ࣌ͷࣄނ͕ଟ͍ ! ΞϓϦέʔγϣϯαʔό͕DB΍ͦͷଞʹ઀ଓͰ͖Δ →ΞϓϦέʔγϣϯΑΓԼͷ૚ͷ໰୊͸ͳ͍͸ͣ !

Slide 55

Slide 55 text

ϔϧενΣοΫ·ͱΊ ࣮֬ʹΞϓϦέʔγϣϯͷ४උ͕Ͱ͖͔ͯΒ੒ޭͤ͞Δ ΞϓϦέʔγϣϯαʔόʹࢮ׆؂ࢹΤϯυϙΠϯτΛ༻ҙ

Slide 56

Slide 56 text

ຊ౰ʹ͋ͬͨා͍࿩

Slide 57

Slide 57 text

ຊ౰ʹ͋ͬͨා͍࿩(1) ىಈޙʹϔϧενΣοΫ͕௨Βͳ͍ Πϯελϯε

Slide 58

Slide 58 text

ϔϧενΣοΫ͕௨Βͳ͍Πϯελϯε͕ൃੜ શ୆Ͱ͸ͳ͍ ىಈޙͷϓϩϏδϣχϯάɺσϓϩΠ͸໰୊ͳ͍ ͳ͔ͥElasticacheRedisʹܨ͕Βͳ͍ →ΞϓϦέʔγϣϯϨϕϧͰͷϔϧενΣοΫʹࣦഊ

Slide 59

Slide 59 text

ϔϧενΣοΫ͕௨Βͳ͍Πϯελϯε͕ൃੜ ىಈˠ࡟আˠىಈˠ࡟আ !!! ͩΜͩΜࣦഊ֬཰্͕͕ΔΑ͏ͳ…

Slide 60

Slide 60 text

ϔϧενΣοΫ͕௨Βͳ͍Πϯελϯε͕ൃੜ ͡ʔͬͱϩάΛݟΔ ʮΉΉɺ͜ͷIPΞυϨε͸ݟ͕֮͑…ʯ

Slide 61

Slide 61 text

ϔϧενΣοΫ͕௨Βͳ͍Πϯελϯε͕ൃੜ աڈʹىಈ͍ͯͨ͠ΠϯελϯεͷIPΞυϨεΛϩά͔Βऩू 10୆͙Β͍Ұؾʹىಈ͢Δ ࣦഊͨ͠΍ͭͷIPΞυϨεΛݟΔ

Slide 62

Slide 62 text

Ṗ͸͢΂ͯ...

Slide 63

Slide 63 text

աڈʹ࢖༻͞Εͨ͜ͱ͕ ͋ΔIPΞυϨε͕࠶ׂΓ ౰ͯ͞ΕͨΠϯελϯε ͕ElastcacheRedisʹܨ ͕Βͳ͍

Slide 64

Slide 64 text

աڈʹ࢖༻͞Εͨ͜ͱ͕͋ΔIPΞυϨε͕࠶ׂΓ ౰ͯ͞ΕͨΠϯελϯε͕ElastcacheRedisʹ ܨ͕Βͳ͍ ElasticacheRedisͷARPςʔϒϧϦϑϨογϡʹ໰୊͕͋ͬͨ (2015೥6݄౰࣌) αϙʔτͰݸผରԠ (2015೥8݄2िҎ߱ʹ৽نىಈ͞Εͨnode͸໰୊ͳ͍ͦ͏Ͱ͢)

Slide 65

Slide 65 text

ΞϓϦέʔγϣϯϨϕϧͷ ϔϧενΣοΫΛ͍ͯͯ͠Α͔ͬͨ

Slide 66

Slide 66 text

ຊ౰ʹ͋ͬͨා͍࿩(2) ϝϯςφϯεฤ

Slide 67

Slide 67 text

MHAͰDB master੾Γସ͑ ΞϓϦέʔγϣϯΛ͢΂ͯϝϯςϞʔυʹ MHAͰmaster switch

Slide 68

Slide 68 text

ϝϯς໌͚Α͏ͱͨ͠Β ΞϓϦέʔγϣϯαʔό ͕མ͍ͪͯͨ

Slide 69

Slide 69 text

ϔϧενΣοΫͰDB΁ͷ઀ଓΛΈ͍ͯͨ DB master͕switch DB΁ͷӬଓ઀ଓ͕੾அ͞ΕΔˠ࣍ͷϦΫΤετͰ࠶઀ଓ(༧ఆ) App͸Plack͕80ϓϩηε ֤ϓϩηε͕੾அͰΤϥʔΛฦ͢ →ͳ͔ͳ͔ϔϧενΣοΫ͕௨Βͳ͍ →Πϯελϯεterminate

Slide 70

Slide 70 text

ܭըϝϯςͰͳͯ͘΋DB͕ࢮ͵͜ͱ͸͋Δ ϔϧενΣοΫ͕௨Βͳ͍ͱΠϯελϯε͕མͪΔ RDS΍Elasticache͸ͨ·ʹࢮ͵(ͷ͕લఏ)

Slide 71

Slide 71 text

ʮΠϯελϯεͷࣄނ͸΄΅ىಈ࣌ʯ Ұ౓ਖ਼ৗʹىಈͨ͠Πϯελϯε͕ࢮ͵ͷ͸Πϯελϯεো֐ ͕΄ͱΜͲ ઃఆϛε΍ϛυϧ΢ΣΞͷ໰୊Ͱશ໓͢Δͷ͸·͍ͣ → Ұ౓ਖ਼ৗʹ૊Έࠐ·ΕͨΒΞϓϦέʔγϣϯϨϕϧͷϔϧε νΣοΫ͸͠ͳ͍ʂ

Slide 72

Slide 72 text

Ұ౓ਖ਼ৗʹ૊Έࠐ·ΕͨΒ… at ίϚϯυΛ࢖͏ ࣗಈىಈͷ࠷ޙʹ at 'now + 5 min' -f /usr/local/sbin/confirm-pass-healthcheck ىಈޙ5෼ͷ࣌఺ͰELBͰInServiceͩͬͨΒ touch /dev/shm/pass_healthcheck ͱ͍͏ίϚϯυΛ࣮ߦ

Slide 73

Slide 73 text

nginxͷϨϕϧͰϔϧενΣοΫΛฦ͢ location /ping { if (-f "/dev/shm/pass_healthcheck") { return 200; } # ϑΝΠϧ͕ͳ͚Ε͹ΞϓϦέʔγϣϯͷϔϧενΣοΫ΁ proxy_pass http://app; } tmpfsʹஔ͍ͯ͋ΔͷͰෆҙͷ࠶ىಈ͕͋ͬͯ΋ىಈ࣌ͱಉ͡

Slide 74

Slide 74 text

ೖΔ΂͖ELBͰInServiceʹͳ͍ͬͯΔ͔Λ൑அ #!/bin/bash instance_id=$(curl -s 169.254.169.254/latest/meta-data/instance-id) for elb in $(jq -r ".[]" /etc/elb.conf) do health=$(aws elb describe-instance-health \ --load-balancer-name "${elb}" --instances "${instance_id}") state=$(echo "$health" | jq -r '.InstanceStates[].State') if [[ $state != "InService" ]]; then exit 1 fi done touch /dev/shm/pass_healthcheck

Slide 75

Slide 75 text

ຊ౰ʹ͋ͬͨා͍࿩ ·ͱΊ ੈؒ͸ݫ͍͠

Slide 76

Slide 76 text

·ͱΊ Φʔτεέʔϧ͸ίετ࡟ݮʹ༗༻ (ن໛ʹΑΔ) ߟ͑ํͷมֵΛഭΒΕΔ (ָ͍͠) ͪΌΜͱ੍ޚ͢Δͷ͸େม (େม)