Corporate Home Open Source Home
Syndicate content
Eucalyptus

Install a service into an EBS volume

This guide will show a way to have some application running of an EBS volume. For simplicity we assume a Debian distro, but the same concept can be extented to other distros. In short we'll install a full system into the EBS volume and we'll install and start the services on the EBS volume.

  • start an instance (in our case a debian instance);
  • create a volume of the appropriate size (in our case we'll use 5GB, and a cluster called 'wind')
    euca-create-volume -s 5 -z wind
  • attach the volume to the running instance
    euca-attach-volume -i i-31AB05AF vol-5957061D -d /dev/sdc
    of course you have to change the instance ID and the volume ID and where you want to volume to appear;
  • log into the instance as root: you should see a new 'disk' on the instance. In this case we are using kvm so the disk is not showing up as sdc as requested, but as the next available (sdb here). Let's create a single partition and format it
    mk2efs /dev/sdb1
  • create a mount point for the volume (/ebs in this case) and mount it there
    mkdir /ebs
    mount /dev/sdb1 /ebs

    Note: some user on the forum were concerned of loosing data on the EBS volume due to instance (or node) crash; mounting the volume with the sync option (add -o sync to the mount command) should minimize this problem at the cost of much slower disk performance;
  • since we are using Debian, we are going to use debootstrap, so let's install the package
    apt-get install debootstrap
  • let's install a basic system (in this case squeeze the current debian testing) in the EBS volume
    debootstrap squeeze /ebs
    Note: if you need a break this is the moment since this step it will take some time;
  • you will need to mount the proc and sys filesystem for all tools to work correctly (for example ps)
    mount proc /ebs/proc -t proc
    mount sysfs /ebs/sys -t sysfs
    mount -o bind /dev /ebs/dev
  • now you are ready to work on the EBS image as if was a new machine: let's use chroot
    chroot /ebs
  • you may want to have your own locale and configure it
    apt-get install locales
    dpkg-reconfigure locales
  • finally we are ready to install the application we want: for example apache2
    apt-get install apache2
  • we are now done with the chroot enviroment and the instance
  • in this case we need to make sure the security group allow port 80, so on the machine you are using to run the euca2ools command
    euca-authorize -P tcp -p 80 -s 0.0.0.0/0 default
  • point your browser to your instance public IP and you should be able to see the default apache web page!

Now that you have a service running in an EBS volume you may want to make the starting and stopping easier: in this case we can have a script similar to this
#!/bin/bash
if [ ! -e /ebs/start_ebs.sh ]; then
echo "EBS volume is not mounted!"
exit 1
fi
if [ "$1" = "stop" ]; then
umount /ebs/sys
umount /ebs/proc
umount /ebs/dev
chroot /ebs /etc/init.d/apache2 stop
umount -lf /ebs
else
mount -t proc proc /ebs/proc
mount -t sysfs sysfs /ebs/sys
mount -o bind /dev /ebs/dev
chroot /ebs /etc/init.d/apache2 start
fi

and the best place to keep it is the EBS volume itself: log in to the instance, then copy the above script into /ebs and name it start_ebs.sh.
We can now move the EBS volume (and our service) to another instance:

  • stop the service
    . /ebs/start_ebs.sh stop
  • detach the volume
    euca-detach-volume vol-5957061D
  • create another instance (let's say we create one with id i-42B207F7) and attach the volume
    euca-attach-volume -i i-42B207F7 -d /dev/sdc vol-5957061D
  • login the new instance and mount the volume
    mkdir /ebs
    mount /dev/sdb1 /ebs
  • finally restart the service
    . /ebs/start_ebs.sh start
  • Now your web site moved to the new instance.

    Of course this tecnique works very well coupled with elastic IPs: in this manner you can guarantee that the IP address of you web server will always be the same, just remember to use euca-associate-address and euca-disaccociate-address to move the IP around.

    As an added benefit you can take backups of your EBS volume (in this case a web site) very easily:
    euca-create-snapshot vol-5957061D