Once you have added the above to ~/.bash_profile, you should log out, then log back in and check that the JAVA_HOME is set correctly.

[root@srv6 ~]# echo $JAVA_HOME
/usr/java/jdk1.7.0_05

Note: If you decided to use JDK 6 rather than 7 as we did above, simply save the JDK 6 bin file to /opt (or another location), then navigate to /usr/java and issue: 'sh /opt/jdk-6u33-linux-x64.bin'. This will create a JAVA Home of /usr/java/jdk1.6.0.33

The above script is simple and contains all of the basic elements you will need to get going.

As you can see, we are simply calling the startup.sh and shutdown.sh scripts located in the Tomcat bin directory (/usr/share/apache-tomcat-7.0.29/bin).

You can adjust your script according to your needs and, in subsequent posts, we'll look at additional examples.

CATALINA_HOME is the Tomcat home directory (/usr/share/apache-tomcat-7.0.29)

Now, set the permissions for your script to make it executable:

[root@srv6 init.d]# chmod 755 tomcat

We now use the chkconfig utility to have Tomcat start at boot time. In my script above, I am using chkconfig: 234 20 80. 2345 are the run levels and 20 and 80 are the stop and start
priorities respectively. You can adjust as needed.

So, open the Catalina.sh file located under /usr/share/apache-tomcat-7.0.29/bin with a text editor or vi.

Since we are using 128 Mb for both initial and maximum heap size, add the following line to Catalina.sh

JAVA_OPTS="-Xms128m -Xmx128m"

I usually just add this in the second line of the file so it looks as so:

#!/bin/sh
JAVA_OPTS="-Xms128m -Xmx128m"
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at

Step 6 (Optional): How to Run Tomcat using Minimally Privileged (non-root) User.

In our Tomcat configuration above, we are running Tomcat as Root.

For security reasons, it is always best to run services with the only those privileges that are necessary.

There are some who make a strong case that this is not required, but it's always best to err on the side of caution.

To run Tomcat as non-root user, we need to do the following:

1. Create the group 'tomcat':

[root@srv6 ~]# groupadd tomcat

2. Create the user 'tomcat' and add this user to the tomcat group we created above.

[root@srv6 ~]# useradd -s /bin/bash -g tomcat tomcat

The above will create a home directory for the user tomcat in the default user home as /home/tomcat

If we want the home directory to be elsewhere, we simply specify so using the -d switch.

Note: it is possible to enhance our security still further by making certain files and directories read-only. This will not be covered in this post and care should be used when setting such
permissions.

4. Adjust the start/stop service script we created above. In our new script, we need to su to the user tomcat:

As an alternative to running Tomcat on port 80, if you have Apache in front of Tomcat, you can use mod_proxy as well as ajp connector to map your domain to your Tomcat application(s) using an Apache vhost as shown below.

While Tomcat has improved it's 'standalone performance', I still prefer to have Apace in front of it for a number of reasons.

In your Apache config, be sure to set KeepAlive to 'on'. Apache tuning, of course, is a whole subject in itself...

+1 to that, really helpful. I've installed solr with tomcat a dozen times or more on Windows but faced with a bare-bones RedHat server and zero linux experience was a bit befuddled. Happily your instructions contain enough detail to get me through even the n00b linux hurdles of making users and groups, chown etc. So big thanks!

Hi David,
The steps were quite clear, unfortunately, I am stuck up at Step 4, last step, I am not getting tomcat home screen after installation.
Its just page cannot be displayed like tomcat is not installed at all.
Your advice would be highly appreciated.
Thanks,
Aaron

in this step :
[root@srv6 init.d]# more /usr/share/apache-tomcat-7.0.29/logs/catalina.out

i get a problem like this :

java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:236)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:426)
i use centos 5.
please help me

Hello Devid,
Thanks for your nice article. I have followed your process but I have been facing a problem. My web server starts with no error and the port 8080 listen but when I give a URL like localhost:8080 but it shows waiting but after few time it shows the connection was reset. What may be the error for this kind of problem?
Thanks,
Rajib.

Nice tutorial but by tomcat is not running it showing error
Using CLASSPATH: /usr/share/apache-tomcat-7.0.34/bin/bootstrap.jar:/usr/share/apache-tomcat-7.0.34/bin/tomcat-juli.jar
/usr/share/apache-tomcat-7.0.34/bin/catalina.sh: line 439: /usr/java/jdk1.7.0_10/bin/java: No such file or directory
But This file exist.
Please suggest me...

Hi @David thanks for reply, I solved this issue.
I removed installed open JDK using yum remove after that i downloaded rpm file from oracle using wget command then i installed downloaded rpm file using #rpm -i jdk---.rpm
Now Tomcat working fine.
Thanks again for sharing this articles.
Regards,
Vivekanand Saraswati

Thanks for this great guide, and I finally got it to start on bootup, but I had to add runtime level 5 with chkconfig --level 2345 tomcat on command.
Would this be because the server is stopped when I log onto the X display manager?

before step 4, when you do http://yourdomain.com:8080.
in CentOS at least if u dont durn off your firewall you cant see it from another computer so if you have a virtual machine like me you just have to do this as root:

# service iptables save
# service iptables stop
# chkconfig iptables off
your manual work for me until this step. so thanks

This is an awesome guide. It helped me a lot. Tomcat is successfully running on my fedora 14. But I can't access it from a remote windows 7 pc or any other linux pc. What are step wise configuration procedure to access my tomcat and mysql database from any other remote pc? My tomcat version is 7.0.37. Port is 8080.
Thanks in advance

CentOS 6 is fully updated, latest versions of Java (jdk-7u25-linux-x64.tar.gz) is installed like you write, same goes for Tomcat7. Tomcat is starting, stopping, and restarting just fine. Firewall is open for 8080. However, it does not pop-up in the browser?!?!? Should be here... http://37.34.54.28:8080/

Great, however in the docs (RUNNING.TXT in catalina home) says:
Note: Do not use JAVA_OPTS to specify memory limits. You do not need much
memory for a small process that is used to stop Tomcat. Those settings
belong to CATALINA_OPTS.

Hi,because I set the CATALINA_HOME and JAVA_HOME to the /etc/profile, so I deleted the
"JAVA_HOME=/usr/java/jdk1.7.0_05
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.29/bin ".

But when I excute "service tomcat start",it display "sh: /bin/startup.sh: No such file or directory". It looks like, the shell can not read the "CATALINA_HOME" variable. Why? Thank you verymuch!