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 memcached on Mac OS X

Easiest way to install memcached on Mac OS X is using MacPorts (port)

According to the MacPorts website…

The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system. To that end we provide the command-line driven MacPorts software package under a BSD License, and through it easy access to thousands of ports that greatly simplify the task of compiling and installing open-source software on your Mac.

The easiest way to install MacPorts on a Mac OS X system is by downloading the dmg for Lion, Snow Leopard or Leopard and running the system’s Installer by double-clicking on the pkg contained therein, following the on-screen instructions until completion.

Now, to install memcached, type the following command

sudo port install memcached

Memcached Server can be started by running the following command

memcached -vv

To run memcached as a daemon

memcached -d

These instructions have been tested on Mac OS X 10.6.8 (Snow Leopard)

Installing JDK, Tomcat on EC2 Fedora Core 8 instance

  • Download JDK to say /mnt/downloads/

wget -O jdk1.6.bin

  • cd /usr/local/
  • sh /mnt/downloads/jdk1.6.bin
  • mv jdk1.6.0_16/ jdk1.6
  • vi /etc/profile

export JAVA_HOME=/usr/local/jdk1.6
export PATH=$PATH:$JAVA_HOME/bin

  •  Download Tomcat to say /mnt/downloads


  • tar -zxvf apache-tomcat-6.0.20.tar.gz
  • mv apache-tomcat-6.0.20 /usr/local/tomcat6
  • useradd -d /home/tomcat -s /bin/bash -m tomcat
  • chown -R tomcat:tomcat /usr/local/tomcat6/
  • test using commans: su – tomcat -c /usr/local/tomcat6/bin/
  • shutdown:  su – tomcat -c /usr/local/tomcat6/bin/shutdown.shconfigure the startup script

or use startup script:

#vi /etc/init.d/tomcat

use the following script:

Add it to chkconfig and turn it on:

# chkconfig --add tomcat
# chkconfig tomcat on

Using Memcached with Java on Windows

Windows Memcached software is available on this page:

Download the Win32 binary zip file. Unzip the file (memcached.exe) in a directory of choice and then do the following to install memcached as a service.

c:/bin/memcached.exe  -d install

At this point the service is installed, it can started or stopped using the following commands

c:/bin/memcached.exe -d  start
c:/bin/memcached.exe -d  stop

By default, the memcached service has a limit of 64MB. If that is not enough, you can increase by tweaking the Windows Registry. Open the following entry.

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached Server

Locate the entry called ImagePath. To increase the limit to 128MB set the value to…

“c:/bin/memcached.exe” -d runservice -m 512

A good Java client for memcached is spymemcached. Download the jar file from here:

// Get a memcached client connected to the local server
MemcachedClient c = new MemcachedClient(AddrUtil.getAddresses(""));
// Store a value (async) for one hour
c.set("someKey", 3600, someObject);
// Retrieve a value (synchronously).
Object myObject= c.get("someKey");