WordPress with CloudFront + AMAZON RDS + S3

WordPress with CloudFront + AMAZON RDS + S3

#Creating JIN-KEI Simple Stack
- List of commands on this hands-on
https://github.com/amimoto-ami/hans-on-materials/blob/master/howto/simple-stack_en.md

Bdaf0b291f02fe64a02cdf592a8a0c8f?s=128

AMIMOTO

April 27, 2016
Tweet

Transcript

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

  2. Architecture

  3. AMAZON CloudFront AMAZON RDS AMAZON S3 w %#XJUIIJHIGBJMVSFUPMFSBODF w TQFFEVQDPOUFOUTEFMJWFSZXJUI$%/

    w $PTUF⒎FDUJWFNFEJBTUPSBHFT (PBM
  4. Starting up AWS services Plugins configurations Workflow Preparations

  5. Preparations for construction

  6. http://bit.ly/1Xio3cC -JTUPGDPNNBOET

  7. AWS CLI installation CloudFront corresponding Workflow Start up AMIMOTO AMI

    preparations
  8. AWS CLI installation CloudFront corresponding Workflow Start up AMIMOTO AMI

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

  10. When you start up AMIMOTO, 
 step forward until this

    “Welcome” page.
  11. AWS CLI installation CloudFront corresponding Workflow Start up AMIMOTO AMI

    preparations
  12. AWS CLI w $PNNBOE-JOF*OUFSGBDFGPS"84 w :PVDBONBOJQVMBUFBMMUISPVHI DPNNBOEMJOF w 'PSDPOpHVSFUIF$MPVE'SPOU "84$-*

  13. Create IAM user Initial setup Workflow AWS-CLI installation

  14. Create IAM user Initial setup Workflow AWS-CLI installation

  15. 1. Install AWS Command Line Interface (aws-cli) to your Mac

    or PC
 
 Two ways to install aws-cli:
 - Install follow the AWS user guide page:
 http://docs.aws.amazon.com/cli/latest/userguide/installing.html
 
 - Install through package manager Homebrew, if you use Mac:
 http://brew.sh/index.html
 "84$-*JOTUBMMBUJPO
  16. Copy below command and pate into your terminal.app then hit

    [return] key
 $ /usr/bin/ruby -e "$(curl -fsSL https:// raw.githubusercontent.com/Homebrew/install/ master/install)"
 $ brew install wget
 $ brew install awscli
 'PS.BDVTFST
  17. 'PS8JOEPXTVTFS w %PXOMPBEUIF"84$-*.4*JOTUBMMFSGPS8JOEPXT CJU  IUUQTTBNB[POBXTDPNBXTDMJ"84$-*NTJ w %PXOMPBEUIF"84$-*.4*JOTUBMMFSGPS8JOEPXT CJU 

    IUUQTTBNB[POBXTDPNBXTDMJ"84$-*NTJ
  18. Create IAM user Initial setup Workflow AWS-CLI installation

  19. None
  20. move to Identity and Access Management

  21. Create new user

  22. Enter a user name and generate access key. BNJNPUPDMJ BNJNPUPDMJ

  23. Save security credentials to your local (anywhere you want)

  24. Attach policy to created user

  25. Choose CloudFrontFullAccess and…

  26. Choose AmazonS3FullAccess then click [Attach Policy]

  27. Two policies are attached to the user

  28. Create IAM user Initial setup Workflow AWS-CLI installation

  29. aws configure --profile amimoto-cli

  30. 4BNQMFDPOpHVSBUJPO 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 and AWS Secret Access Key

  32. 4BNQMFDPOpHVSBUJPO 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 installation CloudFront corresponding Workflow Start up AMIMOTO AMI

    preparations
  34. aws --profile amimoto-cli configure set preview.cloudfront true $POpHVSBUJPODPNNBOE

  35. aws --profile amimoto-cli cloudfront help $POpHVSBUJPODIFDL

  36. None
  37. Setting up 
 AWS services

  38. Amazon RDS Amazon S3 Workflow CloudFront

  39. Amazon RDS Amazon S3 Workflow CloudFront

  40. AMAZON CloudFront •Global content delivery network (CDN) service •High data

    transfer speeds and reduce server load •Supports failover if a failure
  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)" 4FUUJOH$MPVE'SPOUVQXJUI"84$-*
  42. http://bit.ly/1VAnJ8q -JTUPGDPNNBOET

  43. • Install WordPress into the server’s document root directory; •

    Replace {ORIGIN URL} to the server domain name (or Public DNS) of AMIMOTO; • Change amimoto-cli to your created profile, if necessary; • On this hands-on, set Public DNS of EC2 to {ORIGIN URL} /PUF
  44. *GZPVDBOOPUpOE1VCMJD%/4PO&$ Check following documents: Updating DNS Support for Your VPC

    http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc- dns.html#vpc-dns-updating or AWSͰPublic DNS(ύϒϦοΫDNS)ׂ͕Γ౰ͯΒΕͳ͍࣌ͷղܾ๏ http://qiita.com/kasokai/items/4ea689ce9f206e78a523
  45. FYQPSUPSJHJO@VSMbFD99999999BQ OPSUIFBTUDPNQVUFBNB[POBXTDPN` BXTŠQSPpMFBNJNPUPDMJDMPVEGSPOUDSFBUFEJTUSJCVUJPODMJ JOQVUKTPO DVSMMTIUUQTSBXHJUIVCVTFSDPOUFOUDPN BNJNPUPBNJDSFBUFDGEJTUTFUUJOHTNBTUFS TPVSDF@EJTU@TFUUJOHTIcTI  4BNQMFDPOpHVSBUJPO

  46. None
  47. 20-30 minutes to complete for 
 CloudFront starts up

  48. Amazon S3 Amazon RDS Workflow CloudFront

  49. AMAZON S3 •AWS storage service •Data is stored on redundant

    servers 
 in multiple data centres •High fault tolerance •No limit on the number of items 
 can be stored •
  50. Click S3 on AWS Console page.

  51. Create a bucket

  52. Name a bucket; unique and easy to specify

  53. Bucket properties

  54. Copy Endpoint and paste it to the text file.

  55. Choose Enable website hosting

  56. Input index.html into Index Document

  57. Click [Save] to apply settings.

  58. Amazon S3 Amazon RDS Workflow CloudFront

  59. AMAZON RDS •Managed DB service •Single click to change specification

    •Easy to replication
  60. AMAZON RDS MariaDB Amazon Aurora Various DB engine MySQL

  61. Switching DB to RDS Workflow Set up

  62. Switching DB to RDS Workflow Set up

  63. None
  64. None
  65. None
  66. None
  67. Values to input • DB Instance IdentifierɿName of DB instance

    • Master UsernameɿRoot user of DB • Master PasswordɿPassword for root user of DB • Confirm PasswordɿConfirmation password for root user of DB Copy and paste them to notepad and save as text file.
  68. None
  69. )PTUOBNFPG EBUBCBTF

  70. None
  71. None
  72. Coffee break

  73. None
  74. %BUBCBTF63-

  75. None
  76. None
  77. None
  78. Switching DB to RDS Workflow Set up

  79. &EJUMPDBMDPOpHQIQ $ sudo su - # cd /var/www/vhosts/{INSTANCE_ID} # vim

    local-config.php
  80. Needs to edit (Line: 11–18) if ( !$db_data ) {

    $db_data = array( 'database' => '{Database Name}', 'username' => '{Master Username}', 'password' => '{Master Password}', 'host' => '{RDS_ENDPOINT}', ); }
  81. Access to CloudFront’s DNS with your browser

  82. Back to WordPress’ set up page. Fill in required field

    then install WordPress.
  83. Installation has completed

  84. Stop MySQL on AMIMOTO(EC2)

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

  86. Disable MySQL autostart • 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. Error Establishing a Database Connection • local-config.php still refers to

    previous DB in EC2 (AMIMOTO) • Make sure configuration of local-config.php
  89. Set up plugins for WordPress

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

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

  92. Activate Nephila clavata plugin on WordPress Dashboard

  93. Configure the plugin

  94. Values to input • AWS Access Key: Access key for

    IAM user amimoto-s3 • AWS Secret Key: Access key for IAM user amimoto-s3 • AWS Region: Region (optional) • S3 Bucket: S3 bucket name • S3 URL: S3 bucket URL • Storage Class: Choose STANDARD
  95. Media library copied onto Amazon S3

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

  97. $$MPVE'SPOU$MFBS$BDIF • CloudFront͸Ωϟογϡ࡟আ࣌ʹ՝ ۚ͞ΕΔͷͰཁ஫ҙ • Flush CloudFront Cache on WordPress

    • Flush automatically when article published/updated or manually • Pay as each request for invalidation
  98. Configure the plugin $ 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. Install and activate [CF Preview Fix] plugin

  102. Removing resources

  103. AMAZON CloudFront Disable CloudFront

  104. None
  105. None
  106. AMAZON RDS Delete Amazon RDS

  107. None
  108. None
  109. AMAZON S3 Delete Amazon S3

  110. None
  111. %FMFUF4CVDLFU • All media are removed permanently • Someone will

    create same S3 bucket name
  112. IAM Delete the created 
 IAM user

  113. None
  114. None
  115. AMAZON CloudFront Delete CloudFront

  116. None
  117. None
  118. Never forget delete EC2

  119. http://amimoto-ami.com/slack/ Feel free to contact us!

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

    + S3