Add EBS volume to a Linux EC2 Instance

  1. Create an EBS volume using the AWS console (WEB UI)
  2. Using the AWS console, attach the EBS volume to running instance. The attached volume may get assigned to /dev/sdf (EC2’s external name for this particular device number).
  3. Format file system /dev/xvdf (Ubuntu’s internal name for this particular device number):
    sudo mkfs.ext4 /dev/xvdf
  4. Mount file system (with update to /etc/fstab so it stays mounted on reboot):
    sudo mkdir -m 000 /vol
    echo "/dev/xvdf /vol auto noatime 0 0" | sudo tee -a /etc/fstab
    sudo mount /vol

For more info:


How to enable JMX on Tomcat running on EC2 (behind a firewall)

Step 1: Copy catalina-jmx-remote.jar into Tomcat’s lib folder. This jar file is available in the extras folder of Tomcat’s binary distribution.

Step 2: Modify Tomcat’s server.xml by adding a new Listener entry.

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" 
rmiRegistryPortPlatform="9090" rmiServerPortPlatform="9091"/>

Step 3: Open both of these ports in your firewall. Ports 9090 and 9091 and just examples, you can choose to use any port numbers you like.

Step 4: Add the following options to Tomcat startup script. 
-Djava.rmi.server.hostname=public-ip (or public dns)

All done! Restart Tomcat and connect to it using jconsole or visualvm from a remote system.

Connecting to EC2 servers from Mac using shortnames

If you have to connect to a number of EC2 machines, typing a long command that looks like the following each time can be painful.

ssh -i  /somepath/somefile.pem

A way to make this command much shorter is by using SSH config file.

Edit (or create) file ~/.ssh/config

vi ~/.ssh/config

Now for each EC2 server that you connect to, add a section that looks like this…

Host test1
User ec2-user
IdentityFile /User/name/ec2pems/test1.pem

Now you can connect to the instance by typing a command that looks like this…

ssh test1

Installing MongoDB on an EC2 Linux instance

This applies to Fedora/CentOS/RedHat distributions of Linux.

Log in to the instance is as root

Add the 10gen MongoDB repository for yum, by creating the file /etc/yum.repos.d/10gen-mongodb.repo

For 64-bit version of MongoDB, add the following

name=10gen Repository

For 32-bit version of MongoDB, add the following

name=10gen Repository

Install MongoDB by running the following command

yum install mongo-10gen mongo-10gen-server

Modify the file /etc/mongod.conf Change the location of DB, logs files, ports as necessary


If you have changed the location of the db or log files, make sure that mongod has write permissions at the new locations. If not assign persmission

chown mongod:mongod /newlocation/mongodbfiles

Start MongoDB server

service mongod start
/etc/init.d/mongod start

To start MongoDB on server reboot

chkconfig --levels 235 mongod on