Showing posts with label rds. Show all posts
Showing posts with label rds. Show all posts

Saturday, February 2, 2013

Amazon RDS - how to increase storage size and upgrade instance size

In the RDS Management Console, click on DB Instances in the left sidebar.

Right click on an instance and click on Modify.

You can change the DB Instance Class and increase the size here.

Keep in mine that you can only increase size but not decrease size here. If you really want to reduce the storage size, you will need to manually export and import the data.

Click Apply Immediately if you want the changes to take effect right away. Otherwise, it will be carried up in the maintenance time window.

FYI, Changing a 20GB volume to a 100GB volume took around 1 hour for me.

Thursday, January 17, 2013

Running Wordpress on Amazon EC2


This article is about how to install Wordpress on Amazon EC2 with MySQL running on Amazon RDS.


Launch a EBS-backed AMI

In the ec2 console,  click launch select Ubuntu Server 12.04.1 LTS 64-bit (AMI id = ami-3d4ff254).
Use t1.micro.
Set delete on termination to false for the root device.
Set termination behaviour to Stop.
Add port 22, 80, 443 for security group


Install Software

sudo apt-get update
sudo apt-get install apache2 libapache2-mod-auth-mysql php5-mysql mysql-client libapache2-mod-php5

We are not going to install mysql-server, since we will be using RDS.


Use Amazon RDS as the database

If you want to set up your own MySQL database, you can do so. For the purpose of this tutorial, we will use Amazon RDS because it takes care of scaling, replication and backups (to S3) without minimim effort.

Read Using MySQL on Amazon RDS to create a MySQL database.

After you created a database, note the database name, username, password, and endpoint address of the DB instance. The endpoint address will be like wordpress.a2ks0zoxdxq.us-east-1.rds.amazonaws.com.

You can ssh into your ec2 instance and run the mysql command to access the database.

mysql -h {endpoint_address} -P 3306 -u{username} -p{password}

Note that when I used a different syntax for the above mysql command, I kept on getting access denied error. Please use the syntax I specified above.


Download Wordpress

sudo mkdir /var/www
cd /var/www
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rm latest.tar.gz
mv wordpress {name_of_your_blog}


Configure Wordpress

mv wp-config-sample.php wp-config.php
vi wp-config.php

Change these:

define('DB_NAME', 'database_name_here');
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

The DB_HOST will be the endpoint we specified above. Include the port :3306 as well.
Ex. wordpress.a2ks0zoxdxq.us-east-1.rds.amazonaws.com:3306

Generate keys for the following:
https://api.wordpress.org/secret-key/1.1/salt/

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

Configure Apache

cd /etc/apache2/sites-available
cp default wordpress
vi wordpress

Change DocumentRoot and Directory from /var/www/ to your blog's directory.

Change AllowOverride from none to all. (If you don't do this, you can't do pretty links in Wordpress.)


                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
       

Save the File.

a2dissite default
a2ensite wordpress

a2enmod rewrite

service apache2 reload

Launch the site

If you are starting a new Wordpress site, access the site from the browser, and following the on screen instruction and you are done.


Porting data from local MySQL to RDS MySQL

To export data:

mysqldump -u{username} -p{password} -h {host} {database} > backup.sql

To import data:

mysql -u{username} -p{password} -h {host} {database} < backup.sql


Creating a Wordpress EBS-backed AMI


The goal is to create a customized Wordpress image that can be quickly launched for scaling purposes.
When an instance is launched with this image, all services (Apache, MySQL, etc) should start on boot and resume normal operations.

Steps for creating a Wordpress AMI:
  1. Launch a EBS-backed AMI instance (MUST be EBS-backed, not instance store-backed)
  2. When the instance is running, install required software and load applications (Apache, Wordpress).
  3. Create an image from the instance

Note that if you attach new volumes, the new AMI will contain block device mapping information for those volumes. When you launch an instance with the new AMI, the instance will launch additional volumes.

1 & 2) Launch a running Wordpress Instance

Follow Running Wordpress on Amazon EC2 to launch a running instance with all Wordpress software installed.

3) Create an image from the instance

In the AWS Management Console, click instances at the left sidebar.

Right click on the Wordpress instance created above and click on Create Image.

Fill in the image name. I like to name things in a convention that is systematic. If you are planning to write deploy scripts and do auto-scaling, it is easier to identify what an image is. I use the following convention:

{namespace}_{what_is_it}_{date}

Ex. mycompany_blog_20130118

You will want the date because you may create an image every time you deploy new codes.

Leave the other options as default, and click on Create Image.

On the left sidebar, click on AMIs under Images.

You can see the status of the AMI we just created.

You should launch an instance from this AMI and test all the data is there.

Using MySQL on Amazon RDS

For an introduction on what is Amazon RDS, please refer to What is Amazon Relational Database Service (Amazon RDS).

AWS Free Tier includes 750hrs of Micro DB Instance each month for one year, 20GB of Storage, and 20GB for Backups with Amazon Relational Database Service (RDS).


Create a DB Security Group

In the RDS UI console, click on DB Security Groups on the left sidebar.

Click Create DB Security Group

Fill in the name and description. (Ex. Name=blog, Description=wordpress blog)

Select the newly created Security Group.

In the bottom half of the screen (the description tab), choose EC2 Security Group for the drop down box and select the desired EC2 Security Group.


Launch a RDS instance

In the RDS UI console, click on DB Instances on the left sidebar.

Click Launch a DB Instance.

Select MySQL Community Edition.

Fill in the database specs.

If you want 24/7 availability, you would want Multi-AZ deployment. But it would cost more.

For this parameter......Do this:
License ModelSelect the default, General-Public-License, to use the general license agreement for MySQL.
DB Engine VersionSelect 5.5.20 to use the default version of MySQL. Note that RDS supports additional versions of MySQL.
DB Instance ClassSelect db.m1.small to select a configuration that equates to 1.7 GB memory, 1 ECU (1 virtual core with 1 ECU), 64-bit platform, and moderate I/O capacity. for more information about the capacity for all the DB Instance class options, see Amazon Relational Database Service Features.
Multi-AZ DeploymentSelect No to not request that your database be made available in multiple availability zones. For more information about multiple availability zones, see the RDS documentation.
Auto Minor Version UpgradeSelect Yes to enable your DB Instance to receive minor DB Engine version upgrades automatically when they become available.
Allocated StorageType 5 to allocate 5 GB of storage for your database. In some cases, allocating a higher amount of storage for your DB Instance than the size of your database can improve I/O performance. For more information about storage allocation, see Amazon Relational Database Service Features.
Use Provisioned IOPSLeave the check box unselected. This option turns on Provisioned IOPS (I/O operations per second), a high-performance storage option in RDS that is optimized for I/O-intensive, transactional (OLTP) database workloads. For more information about high performance storage, see Provisioned IOPS.
DB Instance IdentifierType a name for the DB Instance that is unique for your account in the region you selected. You may chose to add some intelligence to the name such as including the region and DB Engine you selected, for example west2-mysql-instance1.
Master User NameType a name using alphanumeric characters that you will use as the master user name to log on to your DB Instance with all database privileges.
Master User PasswordType a password that contains from 8 to 16 printable ASCII characters (excluding /,", and @) for your master user password.

Click continue to Additional Configuration.

Fill in the database name. For Availability Zone, choose the same region that your EC2 instance is at. This will speed up the connection and also not induce any cross-region fees.

Select the DB Security Group that we created in the previous section.

Click continue to Management Options.

Enable Automatic Backups, and set the Backup Retention Period to your desired days. A retention period of 7 days means that the daily backup will be deleted after 7 days. That also means there will be 7 backups at anytime.

Review the information in the next screen and launch the DB instance.