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

WordPress goes more Cloud ! - Infrastructure a...

WordPress goes more Cloud ! - Infrastructure as CodeでWordPressをより便利に

#jawsdays 2017

Hidetaka Okamoto

March 13, 2017
Tweet

More Decks by Hidetaka Okamoto

Other Decks in Technology

Transcript

  1. Wo rd P re s s g o e s

    m o re C l o u d ! - I n f r a s t r u c t u re a s C o d e Ͱ Wo rd P re s s Λ Α Γ ศ ར ʹ J A W S D AY S 2 0 1 7 LT
  2. Wo rd P re s s ࢖ ͬͯ ͳ ͍

    ਓ ͸ E C 2 Ͱ ಈ ͔ ͯ͠ Δ Ξ ϓ Ϧ ʹ ஔ ͖ ׵ ͑ͯ ߟ ͑ Α ͏
  3. H i d e t a k a O k

    a m o t o • AMIMOTO / Shifter • WordBenchKyoto • WordCamp Kyoto 2017
  4. I f y o u c re a t e

    Wo rd P re s s S e r v e r • AWSίϯιʔϧΛ։͘ • EC2ͰΠϯελϯεΛىಈ • WordPressΛϓϩϏδϣϯ • WordPressηοτΞοϓ
  5. ؅ ཧ ͢ Δ α ʔόʔ ͕ ૿ ͑ͯ͘Δ ͱ

    ɾ ɾ ɾ • Πϯελϯεϩʔϧ෇͚๨Εͨɾɾɾ • Πϯελϯεফ࣌͢ʹηΩϡϦςΟάϧʔϓফ͠๨ΕͯΔɾɾɾ • UserDataͷίϐϖϛεͬͯϓϩϏδϣϯ͕ࣦഊͨ͠ɾɾɾ • खॱΛ·ͱΊΔͷΊΜͲ͍͘͞ɾɾɾ
  6. AW S C l o u d F o r

    m a t i o n
  7. C l o u d F o r m a

    t i o n Λ ࢖ ͑ ͹ • SG΍Πϯελϯεϩʔϧ΋JSON / YAMLͰఆٛͰ͖Δ • ফ͠๨Ε΍ରԠ࿙Ε͕͓͖ͳ͘ͳΔ • RDS΍EFS , CloudFrontͳͲͱͷ࿈ܞ΋ίʔυԽͰ͖Δ • ʮ͜ͷखॱͰߏஙͯ͠ʯͱ͍͏खॱॻ͕ཁΒͳ͘ͳΔ
  8. t e r r a f o r m ͡

    Ό μϝ ͳ ͷ ʁ • AWS SDK͔Βૢ࡞Ͱ͖ΔͷͰɺCloudFormation೿Ͱ͢ • ͱ͸͍͑terraformͰ͔͠࡞Εͳ͍Ϧιʔε΋͋Δ(SESͳͲ) • terraformͰCloudFormationͷػೳΛΧόʔ͢Δ • MarketPlaceʹϓϩμΫτͱͯ͠ܝࡌͰ͖Δͷ΋CloudFormation
  9. Wo rd P re s s ͷ Π ϯ ϑ

    ϥ ͸ ό Ϧ Τʔ γ ϣ ϯ ͕ ଟ ͍ • ͜ͷҊ݅͸EC2ͱRDS • ͬͪ͜͸CloudFrontͱELB΋ඞཁ • ͋ͷҊ݅ը૾૿͖͔͑ͯͨΒS3௥Ճ͠Α͏͔ͳ • AutoScale͍ͨ͠ͷ͕ग़͖͔ͯͨΒEFSͰϚ΢ϯτ͠Α͏ →ຖճϦιʔεΛίϐϖͯ͠ςϯϓϨʔτ࡞Δͷ͕ۤߦʹɾɾɾ
  10. $Stack_Type = 'autoscale' AWSTemplateFormatVersion "2010-09-09" Description (<<-EOS).undent WordPress powered by

    JINKEI (AutoScaling HVM) EOS Resources do if $Stack_Type == 'autoscale' then _include 'include/iam/instance_profile.rb' else _include 'include/iam/for_stack_001.rb' end end Mappings do _include "include/mapping/ami_as.rb" _include "include/mapping/amimoto_config.rb" end k u m o g a t a & k u m o g a t a 2 • Codenize.tools ͷ̍ͭ • Ruby DSLͰCloudFormation͕ॻ͚Δ • ϦιʔεผʹϑΝΠϧΛ࡞ͬͯ include͢Ε͹࠶ར༻Ͱ͖Δ • if΍ม਺ɾ_includeͰߏ੒ΧελϜ͕ ؆୯ʹ
  11. A f t e r s e t u p

    Wo rd P re s s • WordPressͷίΞɾϓϥάΠϯͷόʔδϣϯΛ֬ೝ͍ͨ͠ • PHP΍OSͷόʔδϣϯ΋ݟ͓͔ͯͳ͍ͱ • ͲͷΠϯελϯεʹͲͷυϝΠϯ͕ೖ͍ͬͯΔ͔΋֬ೝ͍ͨ͠ • Let’s Encryptͷূ໌ॻߋ৽ࣗಈԽ΋͠ͳ͚Ε͹ɾɾɾ → ӡ༻ϚχϡΞϧɾखॱॻ͕ͲΜͲΜ૿͍͑ͯ͘
  12. E C 2 S y s t e m s

    M a n a g e r • ΠϯϕϯτϦͰΠϯελϯε৘ใΛίϯιʔϧ͔ΒҰ๬Ͱ͖Δ • Run commandͰ೚ҙͷ৘ใΛΠϯϕϯτϦͤ͞Δ͜ͱ͕Մೳ • State ManagerͰΞοϓσʔτίϚϯυΛఆظ࣮ߦ͢Δ͜ͱ΋ʂ • ConfigͰมߋཤྺΛτϥοΩϯάͰ͖ΔͷͰ؂ࢹʹ΋࢖͑Δ
  13. E C 2 S y s t e m s

    M a n a g e r f o r Wo rd P re s s • ؅ཧ͍ͯ͠ΔαʔόʔʹΠϯετʔϧ͞ΕͨWPαΠτΛΠϯϕϯτϦ • ֤WordPress಺ͷϓϥάΠϯ໊ͱόʔδϣϯΛΠϯϕϯτϦ • AWS ConfigΛ࢖ͬͯʮউखʹຊ൪Ξοϓσʔτ΍Β͔ͨ࣌͠ظʯͷಛఆ • WP-CLI + Run commandͰWPૢ࡞͸͍͍ͩͨͳΜͰ΋Ͱ͖Δ
  14. E C 2 S y s t e m s

    M a n a g e r ࢖ ͬͯ Έͯ ײ ͡ ͨ ͜ ͱ • Run command࢖͏͚ͩͩͱɺ݁ہίϚϯυखॱॻ͕ඞཁʹͳΔ • DocumentԽ͠Α͏ͱ͢ΔͱɺJSONͱͷಆ͍͕͸͡·Δ
  15. { "schemaVersion":"2.0", "description":"Run a script", "mainSteps":[ { "action":"aws:runShellScript", "name":"runShellScript", "inputs":{

    "commands":"aws ssm put-inventory -- instance-id "ID" --items '[{"CaptureTime": "2016-08-22T10:01:01Z", "TypeName": "Custom:RackInfo", "Content":[{"RackLocation": "Bay B/Row C/Rack D/Shelf E"}], "SchemaVersion": "1.0"}]'" } }, Π ϯϕ ϯ τ Ϧ ί Ϛ ϯ υ υ Ω ϡ ϝ ϯ τ υΩϡϝϯτ༻ͷதͷJSON಺ʹ ΠϯϕϯτϦͷͨΊͷJSONΛͶ͡ࠐΉ ↓ ݟ௨͕͠ѱͯ͘؅ཧͮ͠Β͍
  16. schemaVersion: "1.2" description: "Example Documents by CFN" runtimeConfig: aws:runShellScript: properties:

    - id: 0.aws:runShellScript runCommand: - INSTANCEID=$(/usr/bin/curl -s http:// 169.254.169.254/latest/meta-data/instance-id) - WPVERSION=$(sudo -u ec2-user /usr/ local/bin/wp core version --path=/var/www/html/) - ITEMS=$(jo -a $(jo CaptureTime=$(date +%Y-%m-%dT%H:%M:%SZ) TypeName=Custom:DefaultWPVersion Content=$ (jo -a $(jo wp_version=${WPVERSION})) SchemaVersion=\"1.0\") | sed 's/\\"//g') - aws ssm put-inventory --instance-id "$ {INSTANCEID}" --items "$(echo ${ITEMS})" A W S : : S S M : : D o c u m e n t • Run Command༻υΩϡϝϯτͷCFN • CloudFormation͔ͩΒYAMLͰ͔͚Δ • SSMͰ࣮ߦ͢ΔίϚϯυ΋ίʔυԽ
  17. $ rezept help put_inventory Usage: rezept put_inventory -c, --content=key:value -i,

    --instance-id=INSTANCE_ID -n, -- name=NAME Options: -n, --name=NAME # The name of the inventory type -i, --instance-id=INSTANCE_ID # EC2 Instance ID -c, --content=key:value # Parameters for the document [--schema-version=SCHEMA_VERSION] # The schema version for the <ޙུ> A tool to manage EC2 Systems Manager (SSM) Documents with programmable DSL. R E Z E P T
  18. E C 2 S y s t e m s

    M a n a g e r ࢖ ͬͯ Έͯ ײ ͡ ͨ ͜ ͱ • CloudFormation΍RezeptͰ؅ཧ͢Ε͹ӡ༻͸ָʹͰ͖ͦ͏ • AWSͷνϡʔτϦΞϧ͕਌੾ͳͷͰɺ؆୯ʹ͸͡ΊΔ͜ͱ͕Ͱ͖Δ • ͨͩ͠೔ຊޠͷهࣄ͕΄ͱΜͲແ͍ͷͰԠ༻ܥ͸ख୳ΓʹͳΓ͕ͪ • ʮແྉʯͰʮศརʯͳͷʹͳͥʁ
  19. – ษ ڧ ձ ओ ࠵ ͯ͠ Δ ਓ ͨ

    ͪ “ؼͬͯϒϩάΛॻ͘·Ͱ͕ษڧձͰ͢”
  20. C l o u d F o r m a

    t i o n ͱ E C 2 S y s t e m s M a n a g e r ͷ ه ࣄ Λ Έ Μ ͳ ΋ ͬ ͱ ॻ ͜͏ ʂ
  21. Wo rd P re s s ωλ ͳ Β Wo

    rd C a m p K y o t o 2 0 1 7 ΁ ʂ h t t p s : / / 2 0 1 7 . k y o t o . w o rd c a m p . o rg /