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

AWSのオートスケールとなかよく付き合う

 AWSのオートスケールとなかよく付き合う

YAP(achimon)C::Asia Hachioji 2016 mid

FUJIWARA Shunichiro

July 02, 2016
Tweet

More Decks by FUJIWARA Shunichiro

Other Decks in Technology

Transcript

  1. ͳͥΦʔτεέʔϧ͢Δͷ͔ min : avg : max = 200 : 1000

    : 3000 ϐʔΫ࣌ͷෛՙ͸1೔ฏۉͷ3ഒ ϐʔΫΛ૝ఆͨ͠ΠϯελϯεΛৗ࣌ىಈ͢Δͱ ! ෛՙʹԠͯ͡Πϯελϯε୆਺Λௐ੔͢Ε͹અ໿Ͱ͖Δ
  2. ͦ΋ͦ΋Φʔτεέʔϧ͢Δ΂͖ʁ 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ສԁ ͋Δఔ౓ͷن໛͕͋Ε͹࡟ݮֹ͕େ͖͍
  3. ن໛͕ͦΕ΄ͲͰ΋ͳ͍৔߹ 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 ఔ౓ɺݻఆඅͱൺ΂Δͱ…
  4. Auto Scaling Group Πϯελϯεͷ·ͱ·Γ͝ͱʹ Auto Scaling GroupΛఆٛ • ୆਺ͷ࠷খ(min)ɺ࠷େ(max)ɺر๬ (desired)

    • ؔ࿈͚ͮΔ ELB • ىಈઃఆ (Launch Configuration) • εέʔϦϯάϙϦγʔ
  5. ࠷খ୆਺ (min) ❌ ͜ͷ୆਺ҎԼʹ͸ݮΒͳ͍ ⭕ ͜ͷ୆਺Λ࠷௿ݶҡ࣋͠Α͏ͱ͢Δ min: 3, ݱࡏ3୆ͷঢ়ଶͰ1୆͕ϔϧενΣοΫࣦഊ →

    ৽͍͠Πϯελϯε͕ىಈ͞ΕΔ → ࣦഊͨ͠Πϯελϯε͕࡟আ͞ΕΔ Ұ࣌తʹ͸minΛԼճΔ͜ͱ͕͋Δ
  6. spot or on demand? εϙοτΠϯελϯε ಈ࡞தͷεϙοτՁ֨ (धཁͱڙڅͰܾఆ)Ͱֹ͕ܾۚ·Δ ͍҆ (͍͍ͨͯͷ৔߹ΦϯσϚϯυͷ1/5ʙ1/10) ߴಅ͢Δ͜ͱ͕͋Δ

    (ΦϯσϚϯυՁ֨ͷ਺ഒ΋) ೖࡳՁ֨ΛεϙοτՁ্͕֨ճΔͱΠϯελϯε࡟আ → શ໓͢ΔՄೳੑ͕͋Δ ଟগͷॲཧ஗Ԇ͕ڐ͞ΕΔδϣϒϫʔΧʔ޲͖
  7. ELBʹ૊ΈࠐΉͨΊʹ͸ϔϧενΣοΫ͕ඞཁ 1. ❌ EC2Πϯελϯε͕ੜ͖͍ͯΔ → Πϯελϯεىಈ ≠ ΞϓϦέʔγϣϯͷ४උ 2. ❌

    TCPͰ઀ଓͰ͖Δ → Webαʔόىಈ ≠ ΞϓϦέʔγϣϯαʔόͷ४උ 3. ⭕ HTTPͰԠ౴Λ200Ͱฦ͢ GET /ping HTTP/1.0 ΞϓϦέʔγϣϯαʔόͰDB઀ଓͳͲ΋νΣοΫ͢Δ
  8. Ұ౓ਖ਼ৗʹ૊Έࠐ·ΕͨΒ… at ίϚϯυΛ࢖͏ ࣗಈىಈͷ࠷ޙʹ at 'now + 5 min' -f

    /usr/local/sbin/confirm-pass-healthcheck ىಈޙ5෼ͷ࣌఺ͰELBͰInServiceͩͬͨΒ touch /dev/shm/pass_healthcheck ͱ͍͏ίϚϯυΛ࣮ߦ
  9. nginxͷϨϕϧͰϔϧενΣοΫΛฦ͢ location /ping { if (-f "/dev/shm/pass_healthcheck") { return 200;

    } # ϑΝΠϧ͕ͳ͚Ε͹ΞϓϦέʔγϣϯͷϔϧενΣοΫ΁ proxy_pass http://app; } tmpfsʹஔ͍ͯ͋ΔͷͰෆҙͷ࠶ىಈ͕͋ͬͯ΋ىಈ࣌ͱಉ͡
  10. ೖΔ΂͖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