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

[日本語]How to use Amazon RDS with AMIMOTO AMI WordPress

[日本語]How to use Amazon RDS with AMIMOTO AMI WordPress

AMIMOTOでRDSを利用する方法

Bdaf0b291f02fe64a02cdf592a8a0c8f?s=128

AMIMOTO

March 25, 2016
Tweet

More Decks by AMIMOTO

Other Decks in How-to & DIY

Transcript

  1. @Amimoto_Ami amimoto-ami.com AMIMOTO (HHVM) + AMAZON RDS

  2. AMAZON RDS ͱ͸

  3. εέʔϥϒϧ ར༻Մೳͳ6ͭͷDB Τϯδϯ ϦϨʔγϣφϧσʔλϕʔε ༰қͳઃఆͱӡ༻

  4. ϝϦοτ •εέʔϧՄೳͳ CPUɼIOPSɼετϨʔδ
 •ࣗಈ·ͨ͸೚ҙͷόοΫΞοϓ͕
 εφοϓγϣοτ͔ΒՄೳ
 • ϚϧνΞϕΠϥϏϦςΟκʔϯͷσϓϩΠ
 • ϓϥΠϚϦͷো֐ൃੜ࣌ʹ͸
 ଈ࠲ʹηΧϯμϦ΁੾Γସ͑Մೳ

  5. σϝϦοτ • DB ΁ͷγΣϧΞΫηε͕Ͱ͖ͳ͍ • Ϣʔβݖݶʹ੍໿͕͋Δ • MySQL ͰͷϨϓϦέʔγϣϯ͕ແޮ •

    ि4࣌ؒͷϝϯςφϯε΢Οϯυ΢දࣔ • ࢭΊΒΕͳ͍ RDS Πϯελϯε
  6. RDS ΁DBΛ
 Ҡߦ͠Α͏

  7. RDS ͷͳ͍ΞʔΩςΫνϟ

  8. RDS ͷ͋ΔΞʔΩςΫνϟ

  9. AWS ίϯιʔϧ ΁ϩάΠϯ

  10. MySQL Λ Amazon RDS ಺ʹ࡞੒

  11. σʔλϕʔεΤϯδϯͷબ୒

  12. σʔλϕʔεΤϯδϯͷબ୒

  13. σʔλϕʔεͷ֤छઃఆ

  14. σʔλϕʔεͷৄࡉઃఆ

  15. σʔλϕʔεͷ࡞੒

  16. ࡞੒͞Εͨ σʔλϕʔε

  17. SSH ͰΠϯελϯε΁ϩάΠϯ

  18. EC2 Λ RDS ΁઀ଓ͠·͢ 1. SSH Ͱαʔό΁઀ଓ͠·͢:
 
 $ ssh

    -i /Users/USERNAME/Desktop/example.pem ec2-user@instance_ip or domain
 2. ࣍ͷίϚϯυΛ࣮ߦͯ͠ MySQL ΁઀ଓ͍ͯͩ͘͠͞:
 
 $ mysql -h {endpoint} -P 3306 -u {mymasteruser} -p 

  19. {endpoint} ͸ AWS Management Console ͷ RDS ৘ใͰ֬ೝͰ͖·͢
 {mymasteruser} ͱ

    ύεϫʔυ͸ RDS ࡞੒࣌ʹࢦఆͨ͠΋ͷΛೖྗ͍ͯͩ͘͠͞
  20. σʔλϕʔεͷϚΠάϨʔγϣϯ wp-cli Ͱ MySQL ͔ΒσʔλΛΤΫεϙʔτ͠·͢:
 
 $ wp --path=/path/to/wordpress db

    export
 
 
 /path/to/wordpress ͸ WordPress ͷΠϯετʔϧσΟϨΫτϦΛࢦఆ͍ͯͩ͘͠͞ɻ
 AMIMOTO AMI Ͱ͸௨ৗ /var/www/vhosts/{instance_id} ͱͳ͍ͬͯ·͢ɻ

  21. σʔλϕʔεͷϚΠάϨʔγϣϯ ΤΫεϙʔτͨ͠σʔλΛ RDS ΁Πϯϙʔτ͠·͢:
 
 $ mysql -h {endpoint} -P

    3306 -u {mymasteruser} -p {databasename} < dump.sql
 
 {endpoint} ͸ AWS Management Console ͷ RDS ৘ใͰ֬ೝͰ͖·͢ɻ
 {mymasteruser} ͱ {databasename} ͸ RDS ࡞੒࣌ʹࢦఆͨ͠΋ͷΛೖྗ͍ͯͩ͘͠͞
  22. wp-config.php ͷฤू // ** MySQL settings - You can get

    this info from your web host ** // $db_data = false; if ( file_exists('/opt/aws/cloud_formation.json') ) { $db_data = json_decode(file_get_contents('/opt/aws/ cloud_formation.json'), true); if ( isset($db_data['rds']) ) { $db_data = $db_data['rds']; $db_data['host'] = $db_data['endpoint'] . ':' . $db_data['port']; } } if ( !$db_data ) { $db_data = array( 'database' => 'RDS_DATABASE_NAME_HERE', 'username' => 'RDS_USER_NAME_HERE', 'password' => 'RDS_PASSWORD_HERE', 'host' => 'RDS_ENDPOINT_HERE', ); }
  23. wp-config.php ͷฤू RDS_DATABASE_NAME_HERE: σʔϕʔεͷৄࡉઃఆͰઃఆࡁΈͷσʔλϕʔε໊ RDS_USER_NAME_HERE: σʔλϕʔεͷ֤छઃఆͰઃఆࡁΈͷϢʔβ໊ RDS_PASSWORD_HERE: σʔλϕʔεͷ֤छઃఆͰઃఆࡁΈͷύεϫʔυ RDS_ENDPOINT_HERE: RDS

    ͷΤϯυϙΠϯτ wp-config.php ΁্ͷઃఆΛೖΕͨ͋ͱ WordPress ʹ઀ଓͰ͖Δ͔͔͘Μ͍ͯͩ͘͠͞ɻ
  24. AMIMOTO AMI ͷ MySQL ΛࢭΊΔ MySQL Λ RDS ΁Ҡಈͤ͞Δͱ AMIMOTO

    AMI ಺ͷ MySQL ϓϩηε͕ෆཁʹͳΓ·͢ɻ ઃఆϑΝΠϧΛฤूͯ͠ MySQL ϓϩηεΛऴ͍ྃͤͯͩ͘͞͞ɻ AMIMOTO AMI Ͱ͸ϛυϧ΢ΣΞͷઃఆ͸ /opt/local/amimoto.json ʹ͋Δ 
 chef-solo Λ࢖͍ͬͯ·͢ɻ
  25. AMIMOTO AMI ͷ MySQL ΛࢭΊΔ MySQL Λ RDS ΁Ҡಈͤ͞Δͱ AMIMOTO

    AMI ಺ͷ MySQL ϓϩηε͕ෆཁʹͳΓ·͢ɻ ઃఆϑΝΠϧΛฤूͯ͠ MySQL ϓϩηεΛऴ͍ྃͤͯͩ͘͞͞ɻ AMIMOTO AMI Ͱ͸ϛυϧ΢ΣΞͷઃఆ͸ /opt/local/amimoto.json ʹ͋Δ 
 chef-solo Λ࢖͍ͬͯ·͢ɻ 
 MySQL Λఀࢭͤ͞Δʹ͸ϑΝΠϧΛ࣍ͷΑ͏ʹॻ͖׵͍͑ͯͩ͘͞:
 {
 "nginx" : { "config" : { "user" : "nginx", "group" : "nginx" } },
 "php" : { "config" : { "user" : "nginx", "group" : "nginx" } },
 "mysql" : { "enabled" : false },
 "phpfpm" : { "enabled" : true },
 "run_list" : [ "recipe[amimoto]" ]
 }
  26. AMIMOTO AMI ͷ MySQL ΛࢭΊΔ AMIMOTO AMI HHVM ൛ͷ৔߹͸ҎԼͷΑ͏ʹมߋ͍ͯͩ͘͠͞: {

    "nginx" : { "config" : { "user" : "nginx", "group" : "nginx" } }, "php" : { "config" : { "user" : "nginx", "group" : "nginx" } }, "mysql" : { "enabled" : false }, "hhvm" : { "enabled" : true }, "run_list" : [ "recipe[amimoto]" ] }
  27. AMIMOTO AMI ͷ MySQL ΛࢭΊΔ ࠷ޙʹ࣍ͷίϚϯυΛ࣮ߦ͍ͯͩ͘͠͞:
 
 $ sudo /opt/local/proviosion

    
 $ mysql stop service
  28. ja.amimoto-ami.com/slack ࣭͝໰͓ड͚͍ͨ͠·͢:

  29. @Amimoto_Ami amimoto-ami.com THANK YOU! AMIMOTO (HHVM) + AMAZON RDS