1

I have followed the installation guide available here: http://www.excelsior-usa.com/articles/tomcat-amazon-ec2-basic.html

I am running an AWS EC2 instance with the Amazon Linux AMI (Amazon Machine Image): Amazon Linux AMI 2014.03.2 (HVM) - ami-d13845e1

I have installed Java 7 on the machine:

${JAVA_HOME}/bin/java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (amzn-2.5.1.2.43.amzn1-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

And I've installed Tomcat7. When I started up the server and try to connect to my machine's address on port 8080, I get a blank page or the request simply hangs. I have installed all of the Tomcat7 packages (see step #5 in the article linked at start of this post) and so I should be seeing the default Tomcat home page (I'd even be happy with a 400 response code!)

I can confirm that my security group is correct (I've previously run Jetty from port 8080 with this same security group). I also followed the guide's command to check if tomcat7 is running and listening to port 8080:

$ sudo fuser -v -n tcp 8080 
                     USER        PID ACCESS COMMAND
8080/tcp:            tomcat     1669 F.... java

When I attempted to run the version command, I got a very strange response:

$ sudo service tomcat7 version
/usr/sbin/tomcat7: line 21: .: /etc/sysconfig/: is a directory
/usr/sbin/tomcat7: line 25: cd: HOME not set
Error: Could not find or load main class org.apache.catalina.util.ServerInfo

I've tried to Google around for solutions and I tried stuff like this but nothing has resulted in success. I'm not sure if the above message I'm receiving from version is related to why my tomcat7 isn't working but it is the only thing I can think of to try and troubleshoot.

Has anyone experiences similar? Does anyone have ideas of what might be wrong? Anyone else sad when they follow a wonderful guide to do something 'easy' and it still doesn't work? :-P

As a side note, I have installed Tomcat7 successfully on my local Windows7 machine via the .exe file and it works beautifully. I'm trying to develop locally and then push to my Amazon Web Service but it seems like I have to solve this problem first.

kngrace
  • 58
  • 1
  • 5

1 Answers1

2

I can confirm the issue you are facing. However, I got it working just fine using Oracle JDK. I followed these steps:

create an instance from ami-d13845e1

removed the existing OpenJDK: yum -y remove java-1.7.0-openjdk

Download and installed Oracle JDK: http://download.oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.rpm

Note: downloading Oracle JDK itself is pain. it’s just not fun downloading it using Linux wget command. Oracle forces you to accept the terms and conditions. So figure out your own way of downloading that file.

Installed the Oracle JDK: rpm -ivh jdk-7u65-linux-x64.rpm

Verified the java version:

# java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

Check in above output that it says "HotSpot"....

Once this is done, then I installed tomcat (http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz) from the source.

BTW, I always use netstat -anp | grep 8080 instead of user -v -n tcp 8080.

The bottom line is, I resolved this issue by removing OpenJDK and installing Oracle JDK. That's the essence.

In case you need steps on installing tomcat from source, then let me know.

EDIT: As requested, Here are the steps to install Tomcat from source:

Download Tomcat and move it to /usr/share/:

# wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.55/bin/apache-tomcat-7.0.55.tar.gz
# tar -xvzf apache-tomcat-7.0.55.tar.gz
# mv apache-tomcat-7.0.55 /usr/share/

Create /etc/init.d/tomcat script as below:

#!/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.55

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

Run below commands (these should be self-explanatory):

# chmod 755 /etc/init.d/tomcat
# chkconfig  --add tomcat
# chkconfig  tomcat on
# chkconfig  --list tomcat

I usually stop iptables for the time being to avoid unnecessary trouble:

# service iptables stop

Start the Tomcat:

# service tomcat start

Ensure that tomcat is running:

# netstat -anp | grep 8080
tcp        0      0 :::8080                     :::*                        LISTEN      1704/java

That's it !!

There are various methods to install tomcat. I always follow this method for installing and running tomcat as a service.

slayedbylucifer
  • 22,878
  • 16
  • 94
  • 123
  • You may want to edit your response for future visitors. The instruction to "download and install Oracle JDK" links to the tomcat install. **Re Note:** I used FTP to transfer then install Java. Very easy :-) Now I was able to muddle through installing Tomcat from source but I couldn't figure out how to get it working as a service. I loosely followed this guide (https://wiki.jasig.org/display/UPM40/Installing+Tomcat) and it appears to work when I run `$TOMCAT_HOME/bin/startup.sh` but I would like to be able to use `service tomcat7 start`. Can you provide installation guidance? – kngrace Aug 06 '14 at 20:22
  • I think I'm going to try some more things related to your baseline suggestion of: remove the JDK Amazon's Linux has and install JDK and Tomcat directly from source (which basically is because Amazon's available packages are broken...) As it turns out, [Part II of the guide I linked](http://www.excelsior-usa.com/articles/tomcat-amazon-ec2-java-stack.html) is essentially that, so I'm going to try it tomorrow. I'll let you know how it goes but I'll keep checking for other responses in case someone can fix Amazon's packaged offerings. – kngrace Aug 06 '14 at 22:54
  • Looks great! I appreciate you breaking it down for me more because I am now realizing that the `service tomcat xyz` bit is just a shell script that runs specific tasks with defined output to console. I probably should have included a disclaimer that I'm fairly new to Linux shell but it didn't occur to me it would matter too much. I feel like I learn more when I struggle through something and I enjoyed this. I ended up mixing your start/stop/restart script and [this one](http://www.excelsior-usa.com/articles/tomcat-amazon-ec2-java-stack.html) to get what I wanted. I'll mark as answered! Thanks – kngrace Aug 07 '14 at 15:44