[日本語] WordPress with CloudFront + AMAZON RDS + S3

Bdaf0b291f02fe64a02cdf592a8a0c8f?s=47 AMIMOTO
April 25, 2016

[日本語] WordPress with CloudFront + AMAZON RDS + S3

Bdaf0b291f02fe64a02cdf592a8a0c8f?s=128

AMIMOTO

April 25, 2016
Tweet

Transcript

  1. WordPress with CloudFront + AMAZON RDS + S3 @Amimoto_Ami ja.amimoto-ami.com

  2. ΞʔΩςΫνϟ

  3. AMAZON CloudFront AMAZON RDS AMAZON S3 w ߴ͍଱ো֐ੑΛ࣋ͭ%# w $%/Ͱίϯςϯπͷ഑৴Λߴ଎Խ

    w ௿ίετϝσΟΞετϨʔδ ࣮ݱ͢Δ͜ͱ
  4. AWSαʔϏεͷ্ཱͪ͛ ϓϥάΠϯͷઃఆ Workflow ४උ

  5. ߏஙલͷ ४උ

  6. http://bit.ly/1VAnJ8q ίϚϯυ·ͱΊ

  7. AWS CLIΠϯετʔϧ CloudFrontରԠ Workflow AMIMOTO AMIͷ४උ ߏஙલͷ ४උ

  8. AWS CLIΠϯετʔϧ CloudFrontରԠ Workflow AMIMOTO AMIͷ४උ ߏஙલͷ ४උ

  9. https://aws.amazon.com/marketplace/pp/B01DAONMCK/

  10. AMIMOTOΛ্ཱͪ͛ͨΒ͜ͷը໘·ͰਐΜͰࢭΊ͍ͯͩ͘͞

  11. AWS CLIΠϯετʔϧ CloudFrontରԠ Workflow AMIMOTO AMIͷ४උ ߏஙલͷ ४උ

  12. AWS CLI w "84ͷ$-*πʔϧ w ίϚϯυϥΠϯ͔Βૢ࡞Մೳ w $MPVE'SPOUͷηοτΞοϓʹར༻ "84$-*

  13. IAMϢʔβʔͷ࡞੒ ॳظઃఆ Workflow AWS-CLIͷΠϯετʔϧ

  14. IAMϢʔβʔͷ࡞੒ ॳظઃఆ Workflow AWS-CLIͷΠϯετʔϧ

  15. 1. Mac ΍ PC ΁ AWS ίϚϯυϥΠϯΠϯλʔϑΣΠε (aws-cli) ΛΠϯετʔϧ
 


    aws-cli ͷΠϯετʔϧํ๏͸ೋ௨Γ:
 - AWS ϢʔβΨΠυϖʔδͷखॱͰߦ͏:
 http://docs.aws.amazon.com/cli/latest/userguide/installing.html
 
 - Mac ͷ৔߹͸ ύοέʔδϚωʔδϟͷ Homebrew Λ࢖ͬͯΠϯετʔϧΛ͢Δ:
 http://brew.sh/index.html
 "84$-*ͷΠϯετʔϧ
  16. ࣍ͷίϚϯυΛλʔϛφϧ΁ίϐʔ&ϖʔετ͍ͯͩ͘͠͞ɻ
 $ /usr/bin/ruby -e "$(curl -fsSL https:// raw.githubusercontent.com/Homebrew/install/ master/install)"
 $

    brew install wget
 $ brew install awscli
 .BDͰΠϯετʔϧ
  17. 8JOEPXTͰΠϯετʔϧ w %PXOMPBEUIF"84$-*.4*JOTUBMMFSGPS8JOEPXT CJU  IUUQTTBNB[POBXTDPNBXTDMJ"84$-*NTJ w %PXOMPBEUIF"84$-*.4*JOTUBMMFSGPS8JOEPXT CJU 

    IUUQTTBNB[POBXTDPNBXTDMJ"84$-*NTJ
  18. IAMϢʔβʔͷ࡞੒ ॳظઃఆ Workflow AWS-CLIͷΠϯετʔϧ

  19. None
  20. Identity and Access Management ΁Ҡಈ͠·͢

  21. ϢʔβΛ࡞੒͠·͢

  22. Ϣʔβ໊Λೖྗͯ͠ΞΫηεΩʔΛੜ੒͠·͢ BNJNPUPDMJ BNJNPUPDMJ

  23. ηΩϡϦςΟΫϨσϯγϟϧΛอଘ͠·͢

  24. ϙϦγʔΛϢʔβ΁ద༻͠·͢

  25. ͜͜Ͱ͸ CloudFrontFullAccess Λબ୒͍ͯͩ͘͠͞

  26. ͞Βʹ AmazonS3FullAccess Λબ୒͍ͯͩ͘͠͞

  27. ϙϦγʔͷద༻͞Εͨ IAM Ϣʔβͷঢ়ଶͰ͢

  28. IAMϢʔβʔͷ࡞੒ ॳظઃఆ Workflow AWS-CLIͷΠϯετʔϧ

  29. aws configure --profile amimoto-cli

  30. ઃఆΠϝʔδ AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXX
 AWS Secret Access

    Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 Default region name [None]: ap-northeast-1
 Default output format [None]: JSON
  31. AWS Access Key ID ͱAWS Secret Access Key

  32. ઃఆΠϝʔδ AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXX
 AWS Secret Access

    Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 Default region name [None]: ap-northeast-1
 Default output format [None]: JSON
  33. AWS CLIΠϯετʔϧ CloudFrontରԠ Workflow AMIMOTO AMIͷ४උ ߏஙલͷ ४උ

  34. aws --profile amimoto-cli configure set preview.cloudfront true ઃఆίϚϯυ

  35. aws --profile amimoto-cli cloudfront help ಈ࡞֬ೝ

  36. None
  37. AWSαʔϏεͷ ηοτΞοϓ

  38. Amazon RDS Amazon S3 Workflow CloudFront

  39. Amazon RDS Amazon S3 Workflow CloudFront

  40. AMAZON CloudFront •AWSͷϗετ͢ΔCDNαʔϏε •αΠτͷߴ଎Խͱෛՙ࡟ݮΛ࣮ݱ •ো֐࣌ͷϑΣΠϧΦʔόʔʹ΋ରԠ

  41. export origin_url='{ORIGIN URL}'; aws --profile amimoto-cli cloudfront create-distribution --cli- input-json

    "$(curl -l -s https:// raw.githubusercontent.com/amimoto-ami/create-cf- dist-settings/master/source_dist_setting.sh | sh)" "84$-*͔ΒηοτΞοϓ
  42. http://bit.ly/1VAnJ8q ίϚϯυ·ͱΊ

  43. WordPress ͸ϧʔτσΟϨΫτϦ΁Πϯετʔϧ͍ͯͩ͘͠͞ɻ
 
 {ORIGIN URL HERE} - ΦϦδϯαʔόͷυϝΠϯ໊Λೖྗ͍ͯͩ͘͠͞ɻ
 IP ΞυϨεͰ͸ͳ͍ͷͰ͝஫ҙ͍ͩ͘͞ɻ

    ϋϯζΦϯͰ͸{ORIGIN URL HERE}͸EC2ͷ ύϒϦοΫDNSΛࢦఆ͠·͢ ஫ҙ఺
  44. &$ʹύϒϦοΫ%/4͕ͳ͍৔߹

  45. FYQPSUPSJHJO@VSMbFD99999999BQ OPSUIFBTUDPNQVUFBNB[POBXTDPN` BXTŠQSPpMFBNJNPUPDMJDMPVEGSPOUDSFBUFEJTUSJCVUJPODMJ JOQVUKTPO DVSMMTIUUQTSBXHJUIVCVTFSDPOUFOUDPN BNJNPUPBNJDSFBUFDGEJTUTFUUJOHTNBTUFS TPVSDF@EJTU@TFUUJOHTIcTI  ೖྗΠϝʔδ

  46. None
  47. ηοτΞοϓ׬ྃ·Ͱ ̎̌ʙ̏̌෼

  48. Amazon S3 Amazon RDS Workflow CloudFront

  49. AMAZON S3 •AWSͷετϨʔδαʔϏε •৑௕Խ͞Ε͍ͯͯো֐ʹڧ͍ •ϑΝΠϧ਺ɾ༰ྔʹ্ݶͳ͠

  50. AWS ίϯιʔϧͰ S3 Λબ୒͍ͯͩ͘͠͞

  51. όέοτΛ࡞੒͠·͢

  52. όέοτ΁෼͔Γ΍໊͍͢લΛ෇͚͍ͯͩ͘͞

  53. όέοτͷ֓ཁը໘

  54. Endpoint Λ߇͍͑ͯͩ͘͞

  55. Enable website hosting Λબ୒͍ͯͩ͘͠͞

  56. Index Document ͸ index.html Λೖྗ͍ͯͩ͘͠͞

  57. [Save] Λԡͯ͠ઃఆΛอଘ͍ͯͩ͘͠͞

  58. Amazon S3 Amazon RDS Workflow CloudFront

  59. AMAZON RDS •AWSͷϗετ͢ΔDBαʔϏε •εϖοΫมߋͳͲ͕̍ΫϦοΫͰ •ෳ੡ʢϨϓϦΧ࡞੒ʣ΋؆୯

  60. AMAZON RDS MariaDB Amazon Aurora બ΂ΔDBΤϯδϯ MySQL

  61. DB੾Γସ͑ Workflow ηοτΞοϓ

  62. DB੾Γସ͑ Workflow ηοτΞοϓ

  63. None
  64. None
  65. None
  66. None
  67. ೖྗ͢Δ஋ • DB Instance IdentifierɿDBΠϯελϯε໊ • Master UsernameɿDBͷϧʔτϢʔβʔ໊ • Master

    PasswordɿDBͷϧʔτϢʔβʔύεϫʔυ • Confirm Passwordɿύεϫʔυͷ֬ೝ ͋ͱͰ࢖͏ͷͰɺςΩετΤσΟλͳͲʹϝϞ
  68. None
  69. ".*.050Ͱ࢖͏ σʔλϕʔε໊

  70. None
  71. None
  72. ٳܜ

  73. None
  74. σʔλϕʔεͷ 63-

  75. None
  76. None
  77. None
  78. DB੾Γସ͑ Workflow ηοτΞοϓ

  79. MPDBMDPOpHQIQΛฤू $ sudo su - # cd /var/www/vhosts/{INSTANCE_ID} # vim

    local-config.php
  80. มߋ͢Δ৔ॴʢ11ʙ18ߦ໨෇ۙʣ if ( !$db_data ) { $db_data = array( 'database'

    => '{Database Name}', 'username' => '{Master Username}', 'password' => '{Master Password}', 'host' => '{RDS_ENDPOINT}', ); }
  81. CloudFrontͷDNSͰαΠτʹΞΫηε

  82. ඞཁͳ৘ใΛೖྗͯ͠ΠϯετʔϧΛ࣮ࢪ

  83. Πϯετʔϧ׬ྃͷը໘

  84. AMIMOTO(EC2)ͷ MySQLΛఀࢭ͢Δ

  85. # vim /opt/local/amimoto.json

  86. MySQLͷࣗಈىಈΛఀࢭ • Before { "mod_php7" : { "enabled": true },

    "run_list" : [ "recipe[amimoto]" ] } • After { "mod_php7" : { "enabled": true }, "mysql": { "enabled": false }, "run_list" : [ "recipe[amimoto]" ] }
  87. # /opt/local/provision

  88. ʮσʔλϕʔε઀ଓΤϥʔʯ • local-config.php͸·ͩAMIMOTOͷDBΛࢀর͍ͯ͠·͢ • local-config.phpͷ಺༰Λ΋͏Ұ౓ݟ௚͍ͯͩ͘͠͞

  89. WordPress ϓϥάΠϯͷ ηοτΞοϓ

  90. C3 CloudFront Cache Clear CF Preview Fix Plugins Nephila clavata

  91. CF Preview Fix C3 CloudFront Cache Clear Nephila clavata Plugins

  92. WordPress ͷμογϡϘʔυͰ Nephila clavata ϓϥάΠϯΛ༗ޮԽ

  93. ϓϥάΠϯͷઃఆΛߦ͍·͢

  94. ೖྗ͢Δ஋ • AWS Access Keyɿamimoto-s3ͷaccesskey • AWS Secret Keyɿamimoto-s3ͷsecret key

    • AWS RegionɿϦʔδϣϯʢ೚ҙʣ • S3 Bucketɿઌ΄Ͳ࡞੒ͨ͠S3όέοτͷ໊લ • S3 URLɿઌ΄Ͳ࡞੒ͨ͠S3όέοτͷURL • Storage ClassɿSTANDARD
  95. Amazon S3 ্΁Ҡಈͨ͠ WordPress ϝσΟΞϥΠϒϥϦ

  96. CF Preview Fix C3 CloudFront Cache Clear Plugins Nephila clavata

  97. $$MPVE'SPOU$MFBS $BDIF • WordPress͔ΒCloudFrontͷΩϟο γϡ࡟আ • هࣄެ։ɾߋ৽࣌ͱखಈͰ࡟আ • CloudFront͸Ωϟογϡ࡟আ࣌ʹ՝ ۚ͞ΕΔͷͰཁ஫ҙ

  98. ϓϥάΠϯΛηοτΞοϓ͢Δ $ cd /var/www/vhosts/{INSTANCE_ID} $ wp plugin activate c3-cloudfront-clear-cache $

    wp c3 update distribution_id <DISTRIBUTION_ID> $ wp c3 update access_key <AWS_ACCESS_KEY> $ wp c3 update secret_key <AWS_SECRET_KEY>
  99. None
  100. CF Preview Fix C3 CloudFront Cache Clear Plugins Nephila clavata

  101. [CF Preview Fix] ϓϥάΠϯΛΠϯετʔϧͯ͠༗ޮԽ͠·͢

  102. Ϧιʔεͷ ࡟আ

  103. AMAZON CloudFront CloudFrontͷແޮԽ

  104. None
  105. None
  106. AMAZON RDS Amazon RDSͷ࡟আ

  107. None
  108. None
  109. AMAZON S3 Amazon S3ͷ࡟আ

  110. None
  111. 4όέοτͷ࡟আ • ϝσΟΞϑΝΠϧશͯ࡟আ͞Ε·͢ • όέοτ໊ΛଞͷϢʔβʔ͕औಘ͢ ΔՄೳੑ΋͋Δ

  112. IAM IAMͷ࡟আ

  113. None
  114. None
  115. AMAZON CloudFront CloudFrontͷ࡟আ

  116. None
  117. None
  118. EC2ͷ࡟আ΋ ͓๨Εͳ͘

  119. http://ja.amimoto-ami.com/slack/ ࣭͝໰͸͓ؾܰʹ:

  120. @Amimoto_Ami ja.amimoto-ami.com THANK YOU! WordPress with CloudFront + AMAZON RDS

    + S3