Tomcat – Run Tomcat and Java on Amazon EC2 Instance

amazon ec2javatomcat

I have installed the tomcat and Java on my Amazon EC2 Instance by followingthe instructions on the following tutorial. http://sites.google.com/site/amistrongeryet/setting-up-java-tomcat-on-ec2. But after installing when I run the "updatedb; locate javac | grep bin" command it did not recognize the update and locate command and gives me the error message locate: command not found and after installing the tomcat everything went sommoth during installation according to the instructions in above mentioned tutorial but at the end when I run the command "bin/startup.sh" and try to navigate the url http://my_public_dns_key:8080 it gives me the connection timed out error.

Also please find below the command reference for my linux commands that I am using to run Java and tomcat.

Command References:

[ec2-user@domU-12-31-39-09-D1-AA ~]$ cd /env/tomcat/
[ec2-user@domU-12-31-39-09-D1-AA tomcat]$ ls
apache-tomcat-6.0.33  apache-tomcat-6.0.33.tar.gz
[ec2-user@domU-12-31-39-09-D1-AA tomcat]$ cd apache-tomcat-6.0.33
[ec2-user@domU-12-31-39-09-D1-AA apache-tomcat-6.0.33]$ sudo bin/startup.sh
Using CATALINA_BASE:   /env/tomcat/apache-tomcat-6.0.33
Using CATALINA_HOME:   /env/tomcat/apache-tomcat-6.0.33
Using CATALINA_TMPDIR: /env/tomcat/apache-tomcat-6.0.33/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /env/tomcat/apache-tomcat-6.0.33/bin/bootstrap.jar
[ec2-user@domU-12-31-39-09-D1-AA apache-tomcat-6.0.33]$ rpm -q tomcat
package tomcat is not installed
[ec2-user@domU-12-31-39-09-D1-AA apache-tomcat-6.0.33]$ cd /usr/local/java/
[ec2-user@domU-12-31-39-09-D1-AA java]$ ls
jdk-6u20-ea-bin-b02-linux-amd64-01_apr_2010-rpm.bin  sun-javadb-client-10.5.3-0.2.i386.rpm  sun-javadb-core-10.5.3-0.2.i386.r
jdk-6u20-ea-linux-amd64.rpm                          sun-javadb-common-10.5.3-0.2.i386.rpm  sun-javadb-demo-10.5.3-0.2.i386.r
[ec2-user@domU-12-31-39-09-D1-AA java]$ cd env/tom
-bash: cd: env/tom: No such file or directory
[ec2-user@domU-12-31-39-09-D1-AA java]$ cd /env/tomcat/
[ec2-user@domU-12-31-39-09-D1-AA tomcat]$ cd apache-tomcat-6.0.33
[ec2-user@domU-12-31-39-09-D1-AA apache-tomcat-6.0.33]$ sudo bin/startup.sh
Using CATALINA_BASE:   /env/tomcat/apache-tomcat-6.0.33
Using CATALINA_HOME:   /env/tomcat/apache-tomcat-6.0.33
Using CATALINA_TMPDIR: /env/tomcat/apache-tomcat-6.0.33/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /env/tomcat/apache-tomcat-6.0.33/bin/bootstrap.jar
[ec2-user@domU-12-31-39-09-D1-AA apache-tomcat-6.0.33]$

Please provide any help that you can provide and help me to sort the issue out. Thanks in advance.

Best Answer

Here are the steps I documented for myself in setting up java and tomcat in a 32 bit small instance. (lame that they support 32/64 bit on micro, but only 32 bit on small!)

Installing Tomcat

# make the directory that is going to hold tomcat
sudo mkdir /opt/tomcat
cd /opt/tomcat
# download tomcat
curl http://mirror.olnevhost.net/pub/apache/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.zip > tomcat6.zip
unzip tomcat6.zip
# now go into apache-tomcat-.../conf/server.xml and change all 8080 to 80 so we are running on the regular web port.
# then start tomcat.
sudo /opt/tomcat/apache-tomcat-.../bin/startup.sh

I later change it to use sudo wget http://apache.tradebit.com/pub/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.tar.gz

At this point, you should be able to hit http:/// and get the tomcat management page.

Installing Sun JDK 6 Download Sun JDK 6. You must agree to the terms and conditions in order to download, so I think you'll have to download and then sftp it over. I downloaded from http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html the 32 bit .bin version.

unzip the jdk into /opt/jdk1.6.xxx and then install it as a java alternative using the following:

sudo alternatives --install /usr/bin/java java /opt/jdk1.6.0_26/bin/java 1500
sudo alternatives --install /usr/lib/jvm/jre jre /opt/jdk1.6.0_26 1500
sudo alternatives --set java /opt/jdk1.6.0_26/bin/java
sudo alternatives --set jre /opt/jdk1.6.0_26

Then make sure you are running java by checking java -version. Since tomcat will be starting as root, I used sudo to test it.

$ sudo java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)