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: http://stackoverflow.com/questions/11535617/add-ebs-to-ubuntu-ec2-instance

 

Advertisements

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.

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-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   someuser@someserver.compute-1.amazonaws.com

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
HostName 100.100.100.100
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

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0

For 32-bit version of MongoDB, add the following

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0

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

logpath=/var/log/mongo/mongod.log
port=27017
dbpath=/var/lib/mongo

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
or
/etc/init.d/mongod start

To start MongoDB on server reboot

chkconfig --levels 235 mongod on