Setting up EBS for Mercury [Beta]

You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!
nullvariable's picture

Once you've followed the steps outlined for installing your site on Mercury you'll then want to take your site to the next level using Elastic Block Store. This is going to keep your MySQL database(s) persistent should your server instance crash. Also make it easy to replicate data for testing etc.

There's a good generic Amazon doc page on this here.

Step 1 - Collect the necessary data

Note the following:

  • instance ID
  • region (example: us-east-1). Also be sure to note the letter following it.
  • access key ID
  • secret access key.

Step 2 - Create (Provision) the Volume

You can do this with command line tools or Elastic Fox, I've included a screen shot of the current AWS Management Console. Select the size you'll need the drive to be, choose the availability zone that matches the region your instance is in, including the letter as noted in step 1. If this is a new volume you won't be using a snapshot (we'll cover this later)

Step 3 - Connect the EC2 Instance to the EBS Volume

Part 1: attach the EC2 Instance to the EBS. Click the "Attach Volume" button and find the instance previously noted to link this drive to the server. Make sure you note the device name (example: /dev/sda) assigned to the volume, you'll need it in a minute.

Part 2: login via SSH, and mount the EBS volume. You'll need a ubuntu utility for this step so issue the following command:

apt-get install -y xfsprogs

Now create an XFS file system on the EBS volume:
sudo modprobe xfs
sudo mkfs.xfs [device name]

Device name should look like "/dev/sda"

Now mount the EBS volume:

echo "/dev/sdh /vol xfs noatime 0 0" | sudo tee -a /etc/fstab
sudo mkdir -m 000 /vol
sudo mount /vol

Congrats! You now have a working EBS volume and anything you save here will persist beyond the specific machine instance.

Step 4 - Move the MySQL Install to the EBS Volume

Stop the MySQL server.

/etc/init.d/mysql stop

Now move all the database files to the EBS volume.

mkdir /vol/etc /vol/lib /vol/log

mv /mnt/mysql     /vol/etc/
mv /var/lib/mysql /vol/lib/
mv /var/log/mysql /vol/log/

And point everything to the EBS volume:

sudo mkdir /mnt/mysql
sudo mkdir /var/lib/mysql
sudo mkdir /var/log/mysql

echo "/vol/etc/mysql /mnt/mysql     none bind" | tee -a /etc/fstab
mount /mnt/mysql

echo "/vol/lib/mysql /var/lib/mysql none bind" | tee -a /etc/fstab
mount /var/lib/mysql

echo "/vol/log/mysql /var/log/mysql none bind" | tee -a /etc/fstab
mount /var/log/mysql

Start up your MySQL server again.

Now your MySQL files are secure against failure of the EC2 instance. The following steps are optional but will allow you to create incremental backup snapshots of the EBS volume. These snapshots aren't just great backups, they can also be used to create another EBS volume (perfect for spooling up a test server with real content that's almost fresh).

Step 5 - Configure Snapshots

This script takes care of most of the heavy lifting. I'll try to add more detailed instructions on how you can use it soon.
EC2 Consistent Snapshot
[Coming soon]

Step 6 - Automated Snapshots

(See above script)
[Coming soon]

Basics adapted from this AWS tutorial.
See also my guide to setting up EBS and RAID.

AttachmentSize
AWS screenshot.png12.15 KB