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

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

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

AMIMOTOでRDSを利用する方法

More Decks by Amimoto - Flexible Cloud WordPress Hosting

Other Decks in How-to & DIY

Transcript

  1. 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 

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

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

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

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

    3306 -u {mymasteruser} -p {databasename} < dump.sql
 
 {endpoint} ͸ AWS Management Console ͷ RDS ৘ใͰ֬ೝͰ͖·͢ɻ
 {mymasteruser} ͱ {databasename} ͸ RDS ࡞੒࣌ʹࢦఆͨ͠΋ͷΛೖྗ͍ͯͩ͘͠͞
  5. 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', ); }
  6. AMIMOTO AMI ͷ MySQL ΛࢭΊΔ MySQL Λ RDS ΁Ҡಈͤ͞Δͱ AMIMOTO

    AMI ಺ͷ MySQL ϓϩηε͕ෆཁʹͳΓ·͢ɻ ઃఆϑΝΠϧΛฤूͯ͠ MySQL ϓϩηεΛऴ͍ྃͤͯͩ͘͞͞ɻ AMIMOTO AMI Ͱ͸ϛυϧ΢ΣΞͷઃఆ͸ /opt/local/amimoto.json ʹ͋Δ 
 chef-solo Λ࢖͍ͬͯ·͢ɻ
  7. 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]" ]
 }
  8. 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]" ] }