Monday 5 April 2010

Small J2EE Fedora Development Server On Amazon EC2.

In the last 10 years I used a LINUX server at home to develop my private applications. Twice a year I spend a weekend to update/upgrade the server. Now I should replace the old hardware with a newest one.

Instead of buying a new server I decided to search for alternative solutions. Due to the small amount of time I really use the server, the solution have to be cheap. At the same time, due to the kind of experiments I do, I need root access to the instance.

I signed up for Amazon S3 and EC2 to be able to run a LINUX AMI. The first question is: where may I find a Fedora AMI?

The best solution for me seems to be a self defined AMI built using Elastic Server. My server is based on Fedora 10 and contains the JDK 1.6.0_13, Tomcat 6.0.18, PHP 5.2.6, MySQL 5.0.67 and Apache2. Almost the same configuration I use at home.

Elastic Server build, deploys and starts the AMI automatically. I had to define a S3 bucked, something like daniele-ami where the service will copy the image of the AMI. The builder needs to access my account at Amazon to store the image and start the AMI, so I define a dedicated Access Key. As soon as the new instance works I disable the dedicated key. The key may be re-enabled each time I want to deploy a new AMI.

Elastic Server sends an email to the account owner containing all the informations to access the the running instance.

The login (cftuser) may be performed using PuTTY (Windows) or ssh (UNIX). To gain root access I have to use the command sudo su - . A quick check of the environment confirms that everything works as expected.

Add a Data Volume

Since I don't work with a reserved instance when the instance terminates all changes made after the startup are lost. To reduce the inconvenience I define a 10 GB EBS volume using the AWS console. Note: the volume have to be defined in the same zone as the EC2 instance.

The volume is attached as device sdf (/dev/sdf)

Now the procedure is the same used to add a disk to any LINUX system:

  1. Use fdisk (fdisk /dev/sdf) to delete all existing partitions (select d).
  2. Save the new (empty) partition table (select w).
  3. Add a new partition (select n).
  4. Save the new partition table (select w).
  5. Use mkfs (e.g. mkfs -t ext3 /dev/sdf1) to format the patition.
  6. Use tune2fs (e.g. tune2fs -L /data /dev/sdf1) to put a label on the patition.
  7. Create the mount point (e.g. mkdir /data).
  8. Modify the file /etc/fstab as displayed into the next section.
  9. Mount the partition (e.g. mount /data).
# /etc/fstab: static file system information.
# AMI version
#
# 'file system' 'mount point'   'type'  'options'       'dump'  'pass'
/dev/sda1       /               ext3    defaults,errors=remount-ro 1    1
/dev/sda2       /mnt            ext3    defaults        0       0
/dev/sda3       none            swap    sw              0       0
proc            /proc           proc    defaults        0       0
none            /sys            sysfs   defaults        0       0
none            /dev/shm        tmpfs   defaults        0       0
none            /dev/pts        devpts  gid=5,mode=620  0       0
LABEL=/data     /data           ext3    defaults        1       2

After a new start the last three steps of the previous list have to be done again to remount the disk. I do it using the following script:

#!/bin/bash
mkdir /data
echo "LABEL=/data     /data           ext3    defaults        1       2" >> /etc/fstab
/bin/mount /data

Execute:

  • sudo su -
  • vi setup
  • copy & paste
  • sh setup

The cost for an afternoon of programming and testing is $0.40 which is really cheap.