BBQ Reviews - Charcoal BBQ Reviews - Kamado Smoker Reviews - Wood Pellet Grill Reviews - Charcoal Kamado Reviews - Pellet Grill Reviews - Ceramic Grill Reviews

How to install Tomcat 7 on RHEL 6

http://www.funstonguitars.com/index.php

How to install Tomcat 7 on RHEL 6

How to install tomcat 7 on RHEL 6 you ask? Tomcat is a fantastic piece of software, and when combined with a great operating system, you have a great application platform. So Tomcat on Red Hat 6 or even Centos 6 (which is really the same thing) is a super platform. I’ve run many tomcat instances on RHEL 5. It was Tomcat version 5, no hickups, and it handled the loads quite well.  Tomcat will need Java obviously. Java being the meat and potatoes of the application to be installed. The specific version will depend on what your developers developed there code with. So that is open ended with respect to versions.

Tomcat is the modern incantation of Apache JServ. I  used to work with this product in the late 90’s I think. Or early 2000’s. It worked, but… it wasn’t a tomcat by any stretch of the imagination. It was the free equivalent to IBM’s Websphere 3.x. You wanted to save money, install JServ. Here I will show the quick and dirty installation. High level look. No Apache hooks in the front end, just a standalone Tomcat 7 instance.

Download and Install Java

How to install Tomcat 7 on RHEL 6

How to install Tomcat 7 on RHEL 6

You need the right version of Java, for your specific environment, depending on what versions your developers used.

# export JAVA_HOME=/usr/java/jdk1.6.0_45

Load jdk-6u45-linux-x64-rpm.bin to /opt

# mkdir /usr/java
# cd /usr/java
# sh /opt/jdk-6u45-linux-x64-rpm.bin

# java -version java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

I just ran java -version above to confirm that I have the right version.  See: http://www.oracle.com/technetwork/java/javaee/downloads/index.html for further information.

Download and Install Tomcat 7

Download apache-tomcat-7.0.39.tar.gz and load it to /opt

# tar -xzvf apache-tomcat-7.0.39.tar.gz
# cd /opt/apache-tomcat-7.0.39/bin
# vi catalina.sh

Add “JAVA_HOME=/usr/java/ jdk1.6.0_45” on the top of the file, this is from the Java installation process above.


Create Tomcat user and group

create tomcat user account/group.  In some cases, specifically in a production or secure environment, give the tomcat use a /bin/false or /dev/null shell.

# groupadd -g 521 tomcat # useradd -u 521 -g 521 -c "Tomcat Service Account" -d /opt/apache-tomcat-7.0.39 tomcat # chown -R tomcat:tomcat /opt/apache-tomcat-7.0.39

Tomcat start / stop script

The key part to the startup script is to have the CATALINA_HOME set to the base of the Tomcat installation

# cat /etc/init.d/tomcat
#!/bin/bash # Tomcat7: Start/Stop Tomcat 7 # # chkconfig: - 90 10 # description: Tomcat is a Java application Server. # Source function library . /etc/init.d/functions #. /etc/sysconfig/network CATALINA_HOME=/opt/apache-tomcat-7.0.39 CATALINA_BASE=/opt/apache-tomcat-7.0.39 TOMCAT_USER=tomcat LOCKFILE=/var/lock/subsys/tomcat RETVAL=0 start(){    echo "Starting Tomcat7: "    su $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"    RETVAL=$?    echo    [ $RETVAL -eq 0 ] && touch $LOCKFILE    return $RETVAL } stop(){    echo "Shutting down Tomcat7: "    $CATALINA_HOME/bin/shutdown.sh    RETVAL=$?    echo    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE    return $RETVAL } case "$1" in    start)       start       ;;    stop)       stop       ;;    restart)       stop       start       ;;    status)       status tomcat       ;;    *)       echo $"Usage: $0 {start|stop|restart|status}"       exit 1       ;; esac exit $?

Configuring the Tomcat Webapps location

The server.xml file holds all the key configuration information. In this case, the default webapps base or appBase location is fine, but can be changed. Lets look at the appBase setting:

# cd $CATALINA_HOME/conf # cat server.xml search for this section: <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">

So this means that you would place your WAR file in $CATALINA_HOME/webapps. Also, the autoDeploy is set to true, which is what you want in some cases. Specifically if the Host autoDeploy attribute is “true”, the system will deploy or “try” to deploy and update web applications dynamically. All that has to be done is have the WAR file placed in the appBase folder. The system needs to have it’s background processing enabled. I believe this to be the  default configuration. So this is good for an environment where you dont’ want outages during new deployments. You can still shutdown tomcat, delete all the old war files and jsp’s etc.. You place a new WAR file in the webapps folder with all your new fancy features and fixes, tomcat will automatically explode the war file and deploy it once restarted.

# cd $CATALINA_HOME/webapps
# ls
docs  examples  hello  hello.war  host-manager  manager  ROOT  sample  sample.war

The Tomcat 7 installation gives you the default war files for testing. sample and hello. Which you can test. But you don’t want these, you have a fancy new app, so all you have to do is:

# pwd /opt/apache-tomcat-7.0.39/webapps # rm -rf * # cp ~/dev/my_java_src/GREAT_App.WAR .

If you need to change some of the default settings as an example heap memory or execution threads, those settings should be put into the  $CATALINA_HOME/bin/setenv.sh file.  Now your WAR file is in the webapps folder, you can start tomcat.

Start Tomcat Server Process

You can start tomcat using the startup.sh script as a test. The service script /etc/init.d/tomcat calls the startup.sh script. So either will work.

# su – tomcat
# ./startup.sh

Using CATALINA_BASE:   /opt/apache-tomcat-7.0.39
Using CATALINA_HOME:   /opt/apache-tomcat-7.0.39
Using CATALINA_TMPDIR: /opt/apache-tomcat-7.0.39/temp
Using JRE_HOME:        /usr/java/jdk1.6.0_45
Using CLASSPATH:       /opt/apache-tomcat-7.0.39/bin/bootstrap.jar:/opt/apache-tomcat-7.0.39/bin/tomcat-juli.jar

Here we start is with the service script


# service tomcat start # ps -ef | grep tomcat tomcat    2721     1  0 May01 ?        00:02:05 /usr/java/jdk1.6.0_45/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-7.0.39/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/opt/apache-tomcat-7.0.39/endorsed -classpath /opt/apache-tomcat-7.0.39/bin/bootstrap.jar:/opt/apache-tomcat-7.0.39/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-7.0.39 -Dcatalina.home=/opt/apache-tomcat-7.0.39 -Djava.io.tmpdir=/opt/apache-tomcat-7.0.39/temp org.apache.catalina.startup.Bootstrap start

I always tail the catalina.out for errors. Sometimes things don’t always work with certain java developers and you get some nasty exceptions. So after the WAR file has been exploded, you should see a message stating that the tomcat server is up and running. The exact message looks like:

INFO: Server startup in 1011 ms

This brings tears to my eyes. The catalina.out file can get huge depending on whether debugging information is set, or errors are generated for some reason. So care must be taken to not fill up the filesystem. Here’s a typical catalina.out output. Notice the last line:

# tail -50 $CATALINA_HOME/logs/catalina.out
May 1, 2013 1:22:25 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
May 1, 2013 1:22:25 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
May 1, 2013 1:22:25 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
May 1, 2013 1:22:25 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
May 1, 2013 1:22:25 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
May 1, 2013 1:22:25 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
May 1, 2013 1:22:25 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
May 1, 2013 1:57:22 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.6.0_45/jre/lib/amd64/server:
/usr/java/jdk1.6.0_45/jre/lib/amd64:/usr/java/jdk1.6.0_45/jre/../lib/amd64:/usr/java/packages
/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
May 1, 2013 1:57:22 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
May 1, 2013 1:57:22 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
May 1, 2013 1:57:22 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 714 ms
May 1, 2013 1:57:22 PM org.apache.catalina.users.MemoryUserDatabase createUser
WARNING: Null or zero length user name specified. The user will be ignored.
May 1, 2013 1:57:22 PM org.apache.tomcat.util.digester.FactoryCreateRule begin
INFO: [FactoryCreateRule] Create exception ignored: Null or zero length user name specified. The user will be ignored.
May 1, 2013 1:57:22 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 1, 2013 1:57:22 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.39
May 1, 2013 1:57:22 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /opt/apache-tomcat-7.0.39/webapps/hello.war
May 1, 2013 1:57:22 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /opt/apache-tomcat-7.0.39/webapps/sample.war
May 1, 2013 1:57:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/apache-tomcat-7.0.39/webapps/host-manager
May 1, 2013 1:57:23 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/apache-tomcat-7.0.39/webapps/docs
May 1, 2013 1:57:23 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/apache-tomcat-7.0.39/webapps/examples
May 1, 2013 1:57:23 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/apache-tomcat-7.0.39/webapps/manager
May 1, 2013 1:57:23 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/apache-tomcat-7.0.39/webapps/ROOT
May 1, 2013 1:57:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 1, 2013 1:57:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 1, 2013 1:57:23 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1011 ms

Now test your web site. Without using an Apache instance with an AJP connector, you can just point your browser to the 8080 port. So something like:

http://yourdomain.name.ca:8080/sample

This is the URL to hit the sample.war file shown above from the default installation. You should hit a JSP of some kind, and see something meaningful. Likely something like:

How to install Tomcat 7 on RHEL 6

How to install Tomcat 7 on RHEL 6

Additional Tomcat 7 settings

Tomcat has many settings that affect the performance and behaviour of the servlet engine. Below are some of the big ticket items. Setting Tomcat 7 Heap size.

-Xmx is the maximum amount of heap memory Java can use

-Xms is the inital amount of heap size setting

-Xss is the setting to control the amount of memory each thread consumes, a thread stack. This shouldn’t be set to frugally, or too low. You will see errors pointing to StackOverflow exceptions. Your app may continue working, but portions will fail.

export CATALINA_OPTS=”-Xms512M -Xmx1024M”

I should note that the above example, the -Xms or initial heap size if half the size of the -Xmx or maximum amount of heap size. There are many developers, admins and other techies who wouldn’t do as I have done above. They would have -Xms be the same size as -Xmx. I have done both and never had issues.

Setting up a tomcat instance with UTF8 enconding, up to 1024M heap memory. It also sets the -XX:PermSize to 256M, which limits a classes memory consumption.

CATALINA_OPTS=”-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512M -Xmx1024M -XX:MaxPermSize=512M -XX:PermSize=256M”

See All Solaris BlogsSee All Linux Blogs  Netapp BlogsSee Puppet Master Blogs  See All OpenLDAP Blogs

How to install Tomcat 7 on RHEL 6

How to install Tomcat 7 on RHEL 6

13 Responses to How to install Tomcat 7 on RHEL 6

  1. marion May 10, 2013 at 8:55 am #

    This is great,

    thanks very much

  2. raj May 27, 2013 at 1:15 pm #

    good sir

    i deploy war file as you do and find error like this

    INFO: Deploying web application archive VALID8.war May 27, 2013 9:40:20 AM org.apache.catalina.core.ContainerBase addChildInternal
    SEVERE: Error deploying web application archive VALID8.war java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[validate.mine].StandardContext[/VALID8]] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:816)
    Caused by: java.lang.UnsupportedClassVersionError: com/yuppie/Populator : Unsupported major.minor version 51.0 (unable to load class com.validator.maker) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2824) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1150)
    SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[yuppie.com].StandardContext[/VALID8]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:932)

    thankyou

    • rocker May 30, 2013 at 7:01 am #

      Wow, I don’t want to seem unhelpful, but I can’t help you with that one. All I can tell is that tomcat can’t work with something in your war file. I would check your valid8.war file. Great name by the way.

      Sorry, let me know if you can figure out what the cause is.

      Cheers

    • jmaasing October 15, 2013 at 10:15 am #

      “major.minor version 51.0 (unable to load class com.validator.maker)”

      This means the WAR was compiled using java 7 but your tomcat is running Java 6.

  3. I love Java and NGINX July 10, 2013 at 4:39 am #

    Is there any updates if Tomcat now supports Web Sockets?

    • rocker July 10, 2013 at 9:31 am #

      Hello

      Tomcat’s implementation of RFC 6455 isn’t done yet. I don’t know when it will be I’m afraid. Beyond that, I have nothing else to say.
      Sorry?

  4. Scott August 12, 2013 at 2:13 pm #

    You want to put your environment variable config in $CATALINA_HOME/bin/setenv.sh (such as the JAVA_HOME assignment) instead of editing catalina.sh. The existing scripts check for the existence of this file and source it if it’s there. This method will make upgrades much easier, as your changes won’t get overridden.

    • rocker August 12, 2013 at 9:43 pm #

      Actually a dandy idea Scott. We use to doctor up ~tomcat/.whatever_environment file in addition to the actual service start script. Which didn’t work well when you had multiple tomcat instances. In this case, each individual tomcat instance has it’s own environment file. Wish I had read that readme back in tomcat 5. The biggest tomcat installations I worked with was with tomcat 5.

      All good. Thanks for the tip.

  5. saurabh September 10, 2013 at 4:13 am #

    Nice article indeed.
    Thanks for the info. very knowledgeable.

  6. Leonard Saers October 8, 2013 at 4:16 am #

    Thanks for a great post.

    Just one detail which I had some problem with. I had to alter on line in the /etc/init.d/tomcat script to get it to work.

    I needed to change the following line:
    su – $TOMCAT_USER -c “$CATALINA_HOME/bin/startup.sh”

    to:
    su $TOMCAT_USER -c “$CATALINA_HOME/bin/startup.sh”

    Otherwise, the script would try to start up Tomcat with the systems CATALINA_HOME.

    • rocker October 8, 2013 at 9:27 pm #

      Hi Leonard

      Thanks for the comment. I suppose the startup script was a bit short sighted on my part. I made the assumption that this was a single instance system. I think Robben correctly pointed this out. You are therefore correct, and I might take the liberty of changing my script here. The system I took the script from was actually a single instance system. Which is rare in most of the environments I’ve worked in.

      Thanks for the tip

  7. robben October 8, 2013 at 3:51 pm #

    The su – only works if you have a single installation and you configure ~tomcat/.profile file with the required variables. This is short sighted in that typically there are multiple instances, and as the author mentiones above, the setenv.sh script is sourced by the start script. And is probably the best way to do it. So if all your important glue is defined there, this shouldn’t be a problem. The ultimate solution is what you have done, remove the “-“.

    The author should probably change that as well.

    Robben

  8. danesh October 15, 2013 at 2:37 pm #

    This was very helpful, thank you!

Leave a Reply


Hit Counter provided by Skylight