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

capistrano-bundle_rsync使ったらオートスケールが高速化した話

 capistrano-bundle_rsync使ったらオートスケールが高速化した話

Affc58cd0f63630fb0c5bcec49902546?s=128

ryonext

June 17, 2015
Tweet

Transcript

  1. $BQJTUSBOPCVOEMF@STZOD ࢖ͬͨΒΦʔτεέʔϧ͕ߴ ଎Խͨ͠࿩

  2. ࣗݾ঺հ w Ϣχίϯͱ͍͏ϕϯνϟʔͰ3BJMTॻ͍ͯ·͢ w ΠΧJESZPOFYU

  3. ໨࣍ w DBQJTUSBOPCVOEMF@STZODͱ͸ w ๊͍͑ͯͨ՝୊ w ղܾͨ͠ํ๏ͱखॱ w ݁Ռ

  4. DBQJTUSBOPCVOEMF@STZODͱ ͸ w %F/"ͷ!TPOPUT͞Μ͕࡞ͬͨɺ֤ϊʔυʹ STZODͰσϓϩΠͰ͖Δ(FN w IUUQTHJUIVCDPNTPOPUTDBQJTUSBOP CVOEMF@STZOD

  5. Կ͕͍͍ͷ͔ʁ w ௨ৗͷDBQJTUSBOPͰ͸ɺ֤ϊʔυʹTTI͠ɺ֤ ϊʔυͰෛՙͷֻ͔ΔCVOEMFJOTUBMMΛߦ͏ɻ w ͜ͷ(FN͸ɺσϓϩΠ༻ͷαʔόͰCVOEMF JOTUBMMΛߦ͍ɺσϓϩΠޙͷʮ੒Ռ෺ʯΛ࡞ͬͨ ͋ͱͰɺ֤ϊʔυʹSTZODͰ഑෍͢Δ

  6. ಈ࡞Πϝʔδ DBQJTUSBOP࣮ߦαʔό σϓϩΠର৅αʔό σϓϩΠର৅αʔό σϓϩΠର৅αʔό/ TTI ֤αʔόͰCVOEMFJOTUBMM͕ߦΘΕΔ

  7. ಈ࡞Πϝʔδ DBQJTUSBOP࣮ߦαʔό σϓϩΠର৅αʔό σϓϩΠର৅αʔό σϓϩΠର৅αʔό/ DBQJTUSBOP࣮ߦαʔόͰ CVOEMFJOTUBMMͨ͠΋ͷΛ STZODͰ഑෍͢Δ σϓϩΠର৅෺

  8. ͜ΕʹΑΓ w ֤ϊʔυͰDQVෛՙͷ͔͔Δ࡞ۀ͕ߦΘΕͳ͍ ͷͰϦιʔεʹ΍͍͞͠ w ୆਺͕૿͖͑ͯͨͱ͖ɺ଎౓͕஗͘ͳΓʹ͍͘

  9. ͦͷଞͷϝϦοτ w Ұ౓σϓϩΠͨ͠όʔδϣϯ͸σϓϩΠαʔό ʹอଘ͞Ε͍ͯΔͨΊɺಉ͡όʔδϣϯͷσϓ ϩΠ͕ૣ͍ w ͜Ε͕Φʔτεέʔϧʹ௒ޮ͘

  10. ๊͍͑ͯͨ՝୊ w ࣍ͷΑ͏ͳ࢓૊ΈͰΦʔτεέʔϧΛઃఆ͍ͯ͠ ·ͨ͠

  11. ΦʔτεέʔϦϯά༻".*Λ࡞ ੒ ΦʔτεέʔϦϯ ά༻".* ΠϯελϯεΛ৽ن࡞੒͠ɺΞϓϦಈ࡞ʹඞཁͳϛυϧ΢Σ Ξʢ3VCZ΍/HJOYͳͲʣΛೖΕͨ΋ͷΛ".*Խ ΞϓϦ༻ͷ "OTJCMF

  12. ىಈ࣌ʹ6TFS%BUBͰҎԼͷॲ ཧΛ࣮ߦ ΦʔτεέʔϦϯ ά༻".*͔Β্ཱͪ ͕ͬͨΠϯελϯε  (JU)VC͔ΒΞϓϦͷϦϙδτϦΛऔಘ  औಘͨ͠ϦϙδτϦ͔Βɺࣗ਎ʹରͯ͠DBQEFQMPZΛ࣮ߦ

  13. w ϝϦοτ w ؆୯ w σϝϦοτ w ճCVOEMFJOTUBMM͕૸ΔͷͰ஗͍ w ͱݴ͏͔ճͰ΋஗͍

  14. ͜ΕʹΑΓ w ฏۉͯ͠෼ڧͷ͕͔͔͍࣌ؒͬͯͨ

  15. w ࠷৽ͷBQQαʔό͔Β".*Λ࡞ͬͯɺىಈͯ͠ 6OJDPSOΛ্ཱͪ͛Δɺͱ͍͏΍Γํ΋͋Δ͚ Ͳ w ".*ࠩ͠ସ͑ BVUPTDBMJOHHSPVQࠩ͠ସ͑· ͰɺσϓϩΠͱηοτͰ΍Δͷ͸ϋʔυϧߴ͍ ʢҰԠࣗಈԽ͸Ͱ͖Δ͔΋ʣ

  16. ղܾͨ͠ํ๏ͱखॱ

  17. ͜͏ߟ͑ͨ w σϓϩΠ͞Ε͍ͯΔ΋ͷNBTUFSΛอ͓ͬͯΓɺ ඞͣDBQJTUSBOPͰσϓϩΠ͍ͯ͠ΔͷͰ w BVUPTDBMFͰىಈ࣌ʹɺDBQJTUSBOP CVOEMF@STZODͰσϓϩΠ͢Ε͹ɺࠓNBTUFSʹ ͋Δ΋ͷΛSTZOD͢Δ͚ͩͳͷͰૣ͍ͷͰ͸ʁ

  18. ͜͏͍͏ߏ੒ʹ σϓϩΠαʔό $JSDMF$* "QQαʔό "QQαʔό BVUPTDBMF ࣌ʣ σϓϩΠґཔ ݱࡏՔಇதͷ"QQαʔόʹσϓϩΠ ࣗ෼ʹσϓϩΠґཔ

    σϓϩΠ
  19. $JSDMF$*͔Β௚઀σϓϩΠ͠ͳ ͍ཧ༝ w ࡞ऀͷ!TPOPUT͞Μͷϒϩάʹ΋هड़͞Ε͍ͯ ·͕͢ɺσϓϩΠαʔόͱ"QQαʔόͷΞʔΩ ςΫνϟ͕ಉ͡Ͱ͋Δඞཁ͕͋ΔͨΊɻ w σϓϩΠαʔόͰCVOEMFJOTUBMM͔ͯ͠Β STZODͰSVCZΞϓϦΛࢃ͘DBQJTUSBOP֦ு ࡞ͬͨTPOPUTCMPHIUUQCMPHMJWFEPPSKQ

    TPOPUTBSDIJWFTIUNM
  20. ௨ৗσϓϩΠ࣌ͷεΫϦϓτ 15 production: 16 branch: master 17 commands: 18 -

    ssh {Ϣʔβ}@{σϓϩΠαʔό} 'source ~/.bash_profile; branch=master stage=production sh' < deploy.sh DJSDMFZNM
  21. ௨ৗσϓϩΠ࣌ͷεΫϦϓτ 1 #!/bin/sh 2 3 mkdir -p deploy/{app_name} 4 5

    if [ ! -d ./deploy/{app_name}/$branch ] ; then 6 git clone git@github.com:{github_user}/{github_repo} ~/deploy/ {app_name}/$branch 7 fi 8 cd /home/ubuntu/deploy/{app_name}/$branch 9 git fetch 10 git checkout -f origin/$branch 11 bundle 12 bundle exec cap $stage deploy EFQMPZTI
  22. ௨ৗσϓϩΠ࣌ͷεΫϦϓτ 1 set :stage, :production 2 set :branch, ENV['BRANCH_NAME'] ||

    'master' 3 set :rails_env, 'production' 4 5 require 'aws-sdk' 6 7 AWS.config( 8 access_key_id: ENV['AWS_ACCESS_KEY_ID'], 9 secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'], 10 region: ‘{region}’ 11 ) 12 13 instances = AWS.ec2.instances.with_tag(:Name, ‘{instance_name}’).select{|i| i.status == :running}.map(&:dns_name) 14 15 role :app, instances, user: 'ubuntu' 16 role :web, instances, user: 'ubuntu' 17 role :db, instances.first, user: 'ubuntu' DPOpHEFQMPZQSPEVDUJPOSC
  23. Φʔτεέʔϧ࣌ 1 #!/bin/bash 2 sudo su - {Ϣʔβ} -c "ssh

    {Ϣʔβ}@{σϓϩΠαʔό} -o StrictHostKeyChecking=no 'source ~/.bash_profile; HOST=`hostname` branch=master stage=autoscale sh /home/ubuntu/deploy/{app_name}/ master/deploy.sh’” >> /tmp/autoscale.log 6TFS%BUB
  24. Φʔτεέʔϧ࣌ DPOpHEFQMPZBVUPTDBMFSC 1 set :stage :production 2 set :rails_env, 'production'

    3 set :host, ENV['HOST'] 4 5 server fetch(:host), user: 'ubuntu', roles: %w{app web db}
  25. ݁Ռ w ΦʔτεέʔϧͰֻ͔Δ࣌ؒʢ"84Ͱ "VUP4DBMJOH(SPVQΛ ୆ͨ͠ͱ͜Ζ͔Βɺ&-#Ͱ αʔϏεΠϯ͢Δ·Ͱͷ࣌ؒʣ w #FGPSF w ෼ඵ

    w "GUFS w ෼ඵ
  26. ͜͏͔͸͹͙ͭΜͩʂ w ࣮࣭ɺΦʔτεέʔϧͰ୆૿΍͔ͯ͠Βɺ࣮ࡍ ʹαʔό͕ಈ͘Α͏ʹͳΔ·Ͱʹ਺෼͔͔Δͷ ͰɺσϓϩΠ࡞ۀࣗମ͸෼Ҏ಺ͰऴΘ͍ͬͯΔ ͜ͱʹɻ

  27. ·ͱΊ w ճCVOEMFJOTUBMM͢Δࠓ·Ͱͷ΍Γํ͕ѱ͔ͬ ͨͱ͍͏ͷ΋͋Γ·͕͢ɺͦΕͰ΋ઈେͳޮՌ Λൃش͢Δ͜ͱʹɻ

  28. ಉ͡Α͏ͳ͜ͱ͕Ͱ͖Δϓϩ μΫτ w TʹΞοϓϩʔυͯ͠ɺσϓϩΠ࣌ʹQVMMͯ͘͠Δͱ͍͏΋ͷ w IUUQTHJUIVCDPNTPSBINBNJZB w IUUQTHJUIVCDPNGVKJXBSBTUSFUDIFS w ͜Ε΋!TPOPUT͞Μʹ঺հͯ͠΋ΒͬͨͷͰ͕͢ɺDFSG΍DPOTVM͕ඞཁͩͬͨͷͰɺ·ͣ͸

    DBQJTUSBOP͚ͩͰͰ͖Δຊ(FNͰ΍ͬͯΈ·ͨ͠ɻ w ࠓ΍ͬͯΔαʔϏε͕౰ͨͬͯେن໛ʹͳ͖ͬͯͨΒ࠶ݕ౼ͯ͠Έ·͢ɻ