Currently I´m researching and learning about Amazon Web Services (AWS). Today I want to share my experience and knowledge about Amazon Elastic Compute Cloud (EC2) and Elastic Block Storage (EBS) storage.
EC2 is a web service that provides a resizable compute capacity (to support scalability) in the Amazon AWS. Amazon EC2 enables to provision and run new server instances (server farm) in minutes to support architectural quality attributes such as high performance, high availability and scalability.
EBS provides a block-level storage for EC2 instances as volumes to be used as primary storage for the file system and database storage. You create a ESB volume and then you mount it in an instance , format it and then start to use it. You can unmounit it and then remount it to another instance. You can also take snapshot backups of ESB volumes to S3 storage. EBS volume provides high availability and reliability in its availability zone (data center). It´s possible to increase the I/O performance by mounting multiple EBS volumes in one instance and striping the data across them.
In order to interact with EC2 instances, you´ll need to create a new account in Amazon AWS (http://aws.amazon.com) and sign up for EC2 and EBS.
Amazon is providing a free usage tier for new customers (for further details at http://aws.amazon.com/en/free/).
Now it´s time to create and lunch an AWS instance. Open the AWS Management Console and select the EC2 tab at https://console.aws.amazon.com/console/home. Select the desired region to launch the instance (red circle) and click on the Lauch Instance button (blue circle) in the following figure.
Next select the Amazon Linux AMI 2012.03 (see Figure 2).
Next page is for setting the instance details as shown in the following figure.
After that, we have a set of advanced setting for the instances configuration. When you reach the key pairs page, you have to click on the Create and Download your Key Pair and save the myfirst_instance_keypair.pem file in your local machine. You need a key pair (public/private) to be authenticated when logging using ssh. The public key is retained in the instance (copied into the .ssh/authorized_keys file in the primary user account´s home directory), allowing you to use the private key (downloaded to your local machine) to log in securely without a password. You can have several pair keys, and each key pair requires a name.
Next page allows you creating security groups to define your instance firewall. By default, the only open port is the 22 (ssh) to any host in order to manage our instance using ssh. Enter a name and description for the security group (blue circle in the following figure)
And finally, you´re able to review all your inputs regarding the instance and click on the button Launch (see Figure 6).
Once the instance is running, you might connect using SSH. One thing to note is that you need to locate the myfirst_instance_keypair.pem and use the following command over it: chmod 400 myfirst_instance_keypair.pem.
Next step is to connect using the following command: ssh -i myfirst_instance_keypair.pem ec2-user@<public_dns>.amazonaws.com.
Now let´s install the Apache HTTP server on the instance by typing the following command: sudo yum install httpd.
After the installation is completed, you need to type the following command to start Apache: sudo /etc/init.d/httpd start.
And finally, we need to open the http port (80) for inbound traffic toward our instance using the Security Groups mechanisms as shown in the following figure.
If you go with your browser to http://<public_dns>.amazonaws.com, you will see something like this:
Now we´re going to create a dedicated EBS volume for our EC2 instance. In the Management Console, select the Volumes node on the Elastic Block Store tree and click on the Create Volume button. In the Create Volume popup, you need to enter an appropriate size and select the same availability zone of our EC2 instance. Finally, let´s click on the Yes, Create button (see Figure 9).
Next step is to select the created volume and select the option Attach Volume to attach it to our instance. Click on the Yes, Attach button (see Figure 10).
Now let´s format the new volume (device= /dev/sdf) using ext3 file system by typing the following command: sudo mkfs –t ext3 /dev/sdf.
Now let´s create mounting point for the volumen at /data by typing the following command: sudo mkdir /data.
To mount the EBS volume at /dev/sdf in the file system at the mounting point /data, we need to type the following command: sudo mount /dev/sdf /data. For mounting automatically the EBS volume, you need to add the mount command at the /etc/fstab file by typing the following command: echo “/dev/sdh /data xfs noatime 0 0” | sudo tee -a /etc/fstab.
Next step is to install Postgresql, you need to type the following command: sudo yum install postgresql postgresql-contrib postgresql-libs postgresql-server.
Let´s configure the Postgresql database server to point the data directory to the directory /data pointing to the ESB volume. First of all, we need to stop the Postgresql server by typing the command: sudo /etc/init.d/postgresql stop. Open the Postgresql configuration file and change the data_directory to /data. And finally, let´s start the Postgresql server again: sudo /etc/init.d/postgresql start.
In this article, I´ve shown how to provision an EC2 instance with two ESB block-storage devices as well as how to install Apache and Postgresql on to the instance.