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

2年間運用しているソーシャルゲームのサーバ構成の変遷

5292dd0924f5e440a4b7ff40b165a0b4?s=47 tkuchiki
January 27, 2017

 2年間運用しているソーシャルゲームのサーバ構成の変遷

5292dd0924f5e440a4b7ff40b165a0b4?s=128

tkuchiki

January 27, 2017
Tweet

Transcript

  1. 2೥ؒӡ༻͍ͯ͠Δ ιʔγϟϧήʔϜͷ αʔόߏ੒ͷมભ @tkuchiki

  2. ※ެ։༻ʹҰ෦εϥΠυΛ ࡟আ͓ͯ͠Γ·͢

  3. WHOAMI(1) • @tkuchiki • ΠϯϑϥνʔϜ • ୲౰ • ιʔγϟϧήʔϜ •

    ࣗࣾαʔϏε • Web+DB PRESS Vol.94
  4. Agenda • αʔόߏ੒ͷมભ • ໰୊ղܾฤ • Auto Scaling ฤ •

    Replace ฤ
  5. ໰୊ղܾฤ

  6. ϦϦʔε࣌ͷαʔόߏ੒

  7. ϛυϧ΢ΣΞ • શ୆ڞ௨ • Perl 5.16.3 • consul + dnsmasq

    • ಺෦ DNS • Service Discovery(DNS) • zabbix-agent
  8. ϛυϧ΢ΣΞ • Openresty 1.4.6 • MySQL 5.6(RDS) • zabbix-proxy

  9. ϛυϧ΢ΣΞ • Redis + Redis Sentinel • master ͷ IP

    Λ Sentinel ʹ໰͍߹ΘͤΔ • Consul ͷ Service Discovery • gearmand • Job Queue
  10. ϛυϧ΢ΣΞ • fluent-agent-lite • Nginx ͷϩάΛసૹ • td-agent • s3,

    numric_counter, datacounter, sampling_filter, anomalydetect, cloudwatch, zabbix, suppress, redshift
  11. ELB Web+App Deploy x 1 Batch x 1 Admin x

    1 Redis x 2 S3 CloudFront RDS for MySQL Redshift Origin  0QFOSFTUZ  qVFOUBHFOUMJUF  UEBHFOU  qVFOUBHFOUMJUF  HFBSNBOE Log  3FEJT  3FEJT 4FOUJOFM  UEBHFOU  3FEJT 4FOUJOFM Log(Backup) Log Asset Bundle  0QFOSFTUZ
  12. fluentd ͕٧·Δ • ॱௐʹΞΫηε͕૿͑Δ • ϩάू໿ଆͷ fluentd ͕٧·Γ࢝ΊΔ • fluentd

    ͸ 1core ͔͠࢖͑ͳ͍ • Nginx ͷΞΫηεϩάू໿ͷෛՙ͕ߴ͍ • fluent-plugin-multiprocess Ͱ Nginx ͷ ΞΫηεϩάू໿ͱͦΕҎ֎Λ෼͚Δ
  13. σΟεΫ༰ྔ͕ᷓΕͦ͏ʹͳΔ • fluentd ͷෛՙ௿ݮ͸੒ޭ • ࠓ౓͸σΟεΫ༰ྔ͕଍Γͳ͘ͳΔ • cron.daily ͰϩάͷѹॖΛͯ͠ɺҰఆظؒա ͗ͨΒ࡟আ͍ͯͨ͠

    • σΟεΫΛ௥Ճͯ͠ cron.daily ͰϩάΛୀආ
  14. ·ͩσΟεΫ༰ྔ͕ᷓΕͦ͏ • 1೔1ճͷϩάୀආͰ͸ؒʹ߹Θͳ͘ͳΔ • ຖ࣌ϩάΛѹॖͱୀආ

  15. MySQL ߴෛՙ • MySQL 1 ୆Ͱ͸ࡹ͖͖Εͳ͍ෛՙ • Slave(Read Replica) Λ௥Ճͯ͠ࢀর෼ࢄ

    • HAProxy ಋೖ • ͍ͭͰʹ؅ཧը໘༻ͷ Slave Λ௥Ճ
  16. ELB Web+App Deploy x 1 Batch x 1 Admin x

    1 Redis x 2 S3 CloudFront RDS for MySQL Redshift Origin 3%4GPS.Z42- 3%4GPS.Z42-Y  0QFOSFTUZ  qVFOUBHFOUMJUF  UEBHFOU  )"1SPYZ  qVFOUBHFOUMJUF  HFBSNBOE Log  3FEJT  3FEJT 4FOUJOFM  UEBHFOU  3FEJT 4FOUJOFM Log(Backup) Log Asset Bundle  0QFOSFTUZ
  17. ࢼ߹ Batch ͷ࣮ߦ͕࣌ؒ௕͍ • Ϣʔβ૿Ճʹ൐͍ࢼ߹਺΋૿Ճ • Batch ͷ࣮ߦ׬ྃ·Ͱͷ͕࣌ؒͲΜͲΜ৳ͼ ͍ͯ͘ •

    εέʔϧΞοϓͰରԠ • ݱࡏ΋εέʔϧΞ΢τ͠ͳ͍ߏ੒ͳͷͰࠓ ޙͷ՝୊
  18. fluent-plugin-redshift͕ࢗ͞Δ • fluentd ͔Β redshift ʹσʔλΛ import ͢Δ • ϦϦʔε࣌͸໰୊ͳ͔͕ͬͨɺΞΫηε͕૿

    ͔͑ͯΒ࣌ʑࢗ͞ΔΑ͏ʹͳΔ • plugin-redshift ͕ࢗ͞Δͱ fluentd ࣗମ͕ ࢭ·Δ • ൒೥Ҏ্ଓ͖·ͨ͠
  19. rin • https://github.com/fujiwara/rin • S3 ͷΠϕϯτ௨஌Ͱ SQS ʹΩϡʔΛ௥Ճ • SQS

    ͷΩϡʔΛऔΓग़ͯ͠ redshift ʹ COPY ίϚϯυΛ࣮ߦ
  20. ELB Web+App Deploy x 1 Batch x 1 Admin x

    1 Redis x 2 S3 CloudFront RDS for MySQL Redshift Origin 3%4GPS.Z42- 3%4GPS.Z42-Y  0QFOSFTUZ  qVFOUBHFOUMJUF  UEBHFOU  )"1SPYZ  qVFOUBHFOUMJUF  HFBSNBOE Log  3FEJT  3FEJT 4FOUJOFM  UEBHFOU  3FEJT 4FOUJOFM  SJO Log Asset Bundle  0QFOSFTUZ SQS COPYίϚϯυ Log( +Backup)
  21. ElastiCache for Redis ʹҠߦ • Sentinel ͷӡ༻ίετ͕ߴ͍ • ElastiCache for

    Redis ͷ Multi-AZ ͕ϦϦʔε • EC2(ΦϯϓϨ)͔ΒͷҠߦͳΒ AOF Λग़ྗ͠ ͯ redis-cli --pipe Ͱྲྀ͚ͩ͢
  22. ELB Web+App Deploy x 1 Batch x 1 Admin x

    1 S3 CloudFront RDS for MySQL Redshift Origin 3%4GPS.Z42- 3%4GPS.Z42-Y  0QFOSFTUZ  qVFOUBHFOUMJUF  UEBHFOU  )"1SPYZ  qVFOUBHFOUMJUF  HFBSNBOE Log  UEBHFOU  SJO Log Asset Bundle  0QFOSFTUZ SQS COPYίϚϯυ ElastiCache for Redis Log( +Backup)
  23. ҆ఆظʹಥೖ • ϦϦʔεޙ1೥͘Β͍Ͱେ͖ͳ໰୊͸ղফ • վળʹऔΓ૊ΊΔΑ͏ʹͳΔ

  24. Auto Scaling ฤ

  25. αʔόͷखಈ௥Ճ • ΠϕϯτͰߴෛՙ͕ݟࠐ·ΕΔ৔߹ʹ Webɾ ΞϓϦέʔγϣϯαʔόΛखಈͰ௥Ճ • AWS CLI Ͱ EC2

    Λىಈͯ͠ ELB ʹ௥ՃͰ͖ ΔΑ͏ʹ͢ΔεΫϦϓτΛ࡞੒ • Management Console ͕৮Εͳͯ͘΋࡞ ۀ͕Ͱ͖Δ
  26. αʔόͷखಈ௥Ճ • ࡞ۀ͸Ͱ͖Δ͕... • ෛՙ͕௿͍ͱαʔόϦιʔε͕༨Δ • ༧ظͤ͵ෛՙ૿େʹରԠͰ͖ͳ͍ • EC2 ͕ಥવࢮ͢ΔͱखಈͰ෮׆ͤ͞Δඞཁ͕

    ͋ͬͨ • ࠓ͸ CloudWatch Alarm Ͱࣗಈ࠶ىಈͤ͞Δ ͜ͱ͕Ͱ͖·͢
  27. Auto Scaling ͷಋೖ • αʔόඅͷ࠷దԽ • Մ༻ੑͷ޲্ • खಈΦϖϨʔγϣϯΛۃྗݮΒ͢ •

    Πϕϯτ։࢝લʹ minimum capacity Λ૿΍ ͢ඞཁ͕͋ΔͨΊ׬શʹͳ͘͢͜ͱ͸Ͱ͖ ͳ͍
  28. Auto Scaling ಋೖͷ໰୊ • Ͳ͏΍ͬͯαʔόΛ࠷৽ͷঢ়ଶʹ͢Δʁ • ΞϓϦέʔγϣϯίʔυɾαʔόઃఆΛम ਖ਼͢Δ౓ʹ AMI Λ࡞੒ʁ

    • αʔόىಈ࣌ʹ deploy ͢Δʁ • deploy αʔό͔ΒίʔυΛऔͬͯ͘Δʁ
  29. Stretcher • https://github.com/fujiwara/stretcher • Consul/Serf ͷ Event Λड͚ͯ manifest Λ

    औಘ • tarball Λ S3 ͳͲ͔Βऔಘͯ͠ rsync Ͱల։ • ೚ҙͷίϚϯυΛ࣮ߦͰ͖Δ • chef-solo ͷ࣮ߦʹ΋ར༻͍ͯ͠Δ
  30. # stretcher $ consul watch -type event -name deploy stretcher

    # deploy $ consul event -name deploy s3://path/to/manifest.yml # ඪ४ೖྗΛड͚Δ͜ͱ΋Մೳ $ echo s3://path/to/manifest.yml | stretcher Stretcher ͰͷσϓϩΠྫ
  31. Auto Scaling ͷ࢓૊Έ • Consul KV ʹ deploy ͞Ε͍ͯΔίʔυͷ manifest

    ϑΝΠϧͷ path Λอଘ • /etc/rc.local Ͱ stretcher Λ࢖ͬͯɺchef-solo ͱΞϓϦͷ deploy • tarball ʹ deploy id ΛೖΕͯɺConsul KV ͷ஋ͱൺֱ͠ɺঢ়ଶ ͕Ұக͠ͳ͚Ε͹ΞϓϦΛىಈ͠ͳ͍ • Zabbix ʹϗετΛ௥Ճ • autoscale service Λ࡞ͬͯɺshutdown ࣌ʹ Zabbix ϗετΛ࡟ আ & Consul Cluster ͔Β leave
  32. Auto Scaling ಋೖͷޮՌ • ౰ॳͷ໨త͸ୡ੒ • αʔόඅͷ࠷దԽ • Մ༻ੑͷ޲্ •

    Pull ܕ deploy ʹมߋ͢Δ͜ͱͰ deploy ࣌ؒ ୹ॖ
  33. Replace ฤ

  34. ৽ήʔϜαʔόϦϦʔε • 2016೥8݄ʹ৽ήʔϜαʔόͷϦϦʔεܾఆ • طଘήʔϜαʔόͱ͸શ͘ผͷ؀ڥͱͯ͠ߏங • ιʔείʔυ͸ڞ༗ • DB ΋ޓ͍ʹࢀর͋͠Θͳ͍

    • ΦϯϥΠϯήʔϜͷήʔϜαʔόͷΑ͏ͳΠϝʔδ • ϦϦʔε࣌ʹ௕࣌ؒϝϯςφϯεΛೖΕΒΕΔ • طଘ؀ڥ΋ Replace ͢Δ͜ͱʹ
  35. طଘήʔϜαʔόͷ໰୊ • OS ͕ݹ͍ • Amazon Linux 2014.03 • ΠϯελϯελΠϓ΋ݹ͍

    • ߏ੒͕ݹ͍ɾྑ͘ͳ͍ • ϩάू໿αʔό͕εέʔϧ͠ͳ͍ • ϩάͷूܭ͸ Norikra Ͱ... • etc
  36. αʔόߏ੒ͷ Replace • OS Λ Amazon Linux ࠷৽൛ʹ • ΠϯελϯελΠϓ΋࠷৽(c4,

    m4)ʹ • ϩάू໿αʔόΛεέʔϧͰ͖ΔΑ͏ʹ • fluent-agent-lite -> fluent-agent-hydra • RDS for MySQL -> Aurora
  37. αʔόߏ੒ͷ Replace • ϛυϧ΢ΣΞͷόʔδϣϯΞοϓ • Openresty • Consul • HAProxy

    • td-agent Λ΍Ίͯ build ͨ͠࠷৽൛ͷ ruby Ͱ fluentd Λಈ͔͢ • εέʔϧͰ͖ΔΑ͏ʹ͢ΔͨΊ multiprocess Λ࢖Θ ͳ͍Α͏ʹ
  38. αʔόߏ੒ͷ Replace • Consul ͷ External Service Λ׆༻ • Consul

    Cluster ֎ͷ Service Discovery ػೳ • RDS ͱ ElastiCache ͷ endpoint Λ Consul DNS ܦ༝Ͱࢀর • ήʔϜαʔό͝ͱʹઃఆϑΝΠϧͰࢀরઌΛม͑Δඞཁ ͕ͳ͍ • consul-template Λ׆༻ͯ͠ϝϯςφϯεΛೖΕΒΕΔΑ͏ʹ͢ Δ • KV Λมߋͨ͠Β Nginx ͕ 503 Λฦ͢Α͏ʹͳΔ
  39. ELB Web+App Deploy x 1 Batch x 1 Admin x

    1 S3 CloudFront RDS for MySQL Redshift Origin 3%4GPS.Z42- 3%4GPS.Z42-Y  0QFOSFTUZ  qVFOUBHFOUMJUF  UEBHFOU  )"1SPYZ  qVFOUBHFOUMJUF  HFBSNBOE Log  UEBHFOU  SJO Log Asset Bundle  0QFOSFTUZ SQS COPYίϚϯυ ElastiCache for Redis Log( +Backup) Replace લ
  40. ELB Web+App Deploy x 1 Batch x 1 Admin x

    1 S3 CloudFront Aurora Redshift Origin "VSPSB "VSPSBY  0QFOSFTUZ  qVFOUBHFOUIZESB  qVFOUE  )"1SPYZ  qVFOUBHFOUIZESB  HFBSNBOE Log Log( +Backup) Log Asset Bundle  0QFOSFTUZ SQS COPYίϚϯυ ElastiCache for Redis Log x 2 Norikra x 1  qVFOUE  SJO  qVFOUE  /PSJLSB Log Replace ޙ
  41. Replace ͷޮՌ • ϩάू໿αʔόͷೖΕସ͕͑(΄΅)ແఀࢭͰߦ ͑Δ • Aurora มߋޙɺEBS ͷϨΠςϯγ૿ʹΑΔΫ ΤϦੑೳͷྼԽ͕ൃੜ͠ͳ͘ͳΔ

    • Norikra + fluentd + fluent-plugin-slack ͰϦΞ ϧλΠϜͳΤϥʔ௨஌͕Մೳʹ
  42. Replace ͷޮՌ • ϩάͷूܭΛ Norikra Ͱߦ͏͜ͱͰϩάू໿ αʔόͷෛՙ௿ݮ • Zabbix ΁ͷϝτϦΫεૹ৴͸

    https:// github.com/tkuchiki/norikra-listener-zabbix Ͱ Norikra ͔Β௚઀ૹ৴
  43. Replace ͷޮՌ • ϝϯςφϯεঢ়ଶͷ੾Γସ͕͑ߴ଎ʹ • Nginx ͰϑΝΠϧͷ༗ແΛݟͯ 503 Λฦ͠ ͍ͯͨͨΊɺͦͷͨΊ͚ͩʹ

    deploy ͢Δ͔ શ୆ʹϑΝΠϧΛ഑Δɾফ͢࡞ۀ͕ඞཁͩͬ ͨ
  44. Replace ͷޮՌ • ΠϯελϯελΠϓΛมߋͨ͜͠ͱͰ CPU ͷ ॲཧੑೳ͕޲্ • ϨεϙϯελΠϜ͕(ଟগ)ߴ଎ʹ

  45. ՝୊ • Batch αʔό͕εέʔϧ͠ͳ͍ • gearmand Λ SQS ʹஔ͖׵͑Δ •

    Norikra ͕ SPOF • Kinesis Streams, Analytics, Firefose + Lambda ʁ