Tomcat7 is not available in the yum Repo on EC2. So this is how installed tomcat 7 on my RHEL 6.4 EC2 instance:
First, I wanted oracle jdk.
Oracle JDK installation:
Remove any existing JDKs
# rpm -qa | grep jdk
java-1.6.0-openjdk-1.6.0.0-1.62.1.11.11.90.el6_4.x86_64
java-1.7.0-openjdk-1.7.0.25-2.3.10.4.el6_4.x86_64
# rpm -e java-1.6.0-openjdk-1.6.0.0-1.62.1.11.11.90.el6_4.x86_64 java-1.7.0-openjdk-1.7.0.25-2.3.10.4.el6_4.x86_64
Download and Install Oracle JDK
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm"
# mv jdk-7u45-linux-x64.rpm\?AuthParam\=1385533795_9ebb9bbbd4d15a8ca5d17a0dab41fedc jdk-7u45-linux-x64.rpm
# rpm -ivh jdk-7u45-linux-x64.rpm
Verification
# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
# javac -version
javac 1.7.0_45
Set JAVA_HOME
# echo "export JAVA_HOME=/usr/java/default" >> /etc/profile
# source /etc/profile
Tomcat 7 Installation:
Download Tomcat
# wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz
# tar -xvzf apache-tomcat-7.0.47.tar.gz
# mv apache-tomcat-7.0.47 /usr/share/
Make tomcat run as a script.
# cat > /etc/init.d/tomcat < EOF
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/default
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.47/
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
EOF
Tomcat service commands:
# chmod 755 /etc/init.d/tomcat
# chkconfig --add tomcat
# chkconfig tomcat on
# chkconfig --list tomcat
# service tomcat start
Using CATALINA_BASE: /usr/share/apache-tomcat-7.0.47
Using CATALINA_HOME: /usr/share/apache-tomcat-7.0.47
Using CATALINA_TMPDIR: /usr/share/apache-tomcat-7.0.47/temp
Using JRE_HOME: /usr/java/default
Using CLASSPATH: /usr/share/apache-tomcat-7.0.47/bin/bootstrap.jar:/usr/share/apache-tomcat-7.0.47/bin/tomcat-juli.jar
Add JAVA_OPTS
as below on 2nd line on /usr/share/apache-tomcat-7.0.47/bin/catalina.sh
so that it looks like:
#!/bin/sh
JAVA_OPTS="-Xms1024m -Xmx2048m"
Restart Tomcat
# service tomcat restart
Verification:
# netstat -anp | grep 8080
tcp 0 0 :::8080 :::* LISTEN 1792/java
You can configure tomcat to be run a normal user as well. It wasn't needed in my case and hence I did not do it. Hope this helps.