Last updated by Greg Coit on Thu, 2010-06-10 17:27
Very similar to setting up an instance with a single EBS drive, you can also fairly easily do a RAID configuration. This leads to better performance usually and higher reliability.
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 Volumes

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.
Repeat this step for the total number of EBS volumes you want in your RAID. When writing these instructions I used a 4 volume setup.
Step 3 - Connect the EC2 Instance to the EBS Volumes
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.
Repeat this step for each volume you've created.
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 xfsprogsPart 3:
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" (you can see the device name from the AWS console under "Attachment Information")
Repeat this step for each volume.
Step 4 - Create the RAID Drive
I used mdadm to create my software raid config, there are other tools too. You'll need to install it to your instance:
sudo apt-get install mdadmI went with a RAID0 configuration here as EBS volumes should already be redundant. Additionally I took the precaution of setting up snapshots on a regular basis so should anything fail I could start back up relatively easily.
sudo mdadm --create /dev/md0 --raid-devices=[num devices] --level=0 [enter device names here like:] /dev/sdf /dev/sdg /dev/sdh /dev/sdiNow we're done with that and you should have a RAID0 drive at /dev/md0 so let's mount it:
echo "/dev/md0 /vol xfs noatime 0 0" | sudo tee -a /etc/fstab
sudo mkdir -m 000 /vol
sudo mount /volreplace /dev/md0 with the RAID device you used if it's different.
Congrats! You now have a working RAID0 EBS volume
Step 5 - Move the MySQL Install to the RAID device
Stop the MySQL server.
sudo /etc/init.d/mysql stopNow 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 RAID device:
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/mysqlStart up your MySQL server again.
sudo /etc/init.d/mysql startNow your MySQL files are secure against failure of the EC2 instance and they're running at a higher level of performance. Now you should consider setting up snapshots for these EBS volumes. 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).
Next step:
Consistent backups with RAID+ec2-consistent-snapshot+cron
This command might be helpful for restoring drives:
mdadm --assemble /dev/md0 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1 Useful links: