A picture of Rob

Robert Capra
http://www.ils.unc.edu/~rcapra


Home |  Publications |  Research |  Teaching |  Notes


Installing Tomcat and Solr on RedHat Enterprise Linux 5

posted: 07-Aug-2007
updated:

Updating in-progress


I needed to install Solr on a new RHEL5 box that had not run Tomcat or Solr before. Finding, installing, and debugging Java, Tomcat, and Solr on this system turned out to be a fairly confusing process, so I thought I'd write up my expereicnes in hopes that I may help someone in the future (perhaps even myself when I need to do this again).

I spent about a day and a half trying to get Solr installed and working using RHEL5 packages (default packages plus a few additional packages installed from RedHat using yum). Ultimately, I never got it working using this approach. Instead, what worked for me was to do a fresh install of Tomcat from an Apache mirror. After I gave up on using the RHEL/yum Tomcat installation and installed a new Tomcat myself, I had Solr working in about 20 minutes.

The Problem

Install Solr with Tomcat on a RHEL5 machine, using as much of the RHEL 5 default infrastructure as possible.

The Solution

Summary

  • Download and install a recent Sun Java JDK RPM.
  • Don't try to use Tomcat as installed by yum for RHEL5. Instead, download and install a Tomcat on your own. I found the instructions for a "Simple Example Install" at the Apache SolrTomcat wiki especially useful.
I first tried to use the installation of Tomcat that RHEL5 supports (see False Starts below). I was never able to get the RHEL5 Tomcat working with Solr. Instead, I had success downloading and installing a fresh version of Tomcat from an Apache mirror site. On the plus side, using this approach I got Solr working in about 20 minutes. On the minus side, I now have a non-RHEL-standard piece of software to administer on my system. This means writing and maintaining startup and shutdown scripts for it and doing any updates manually instead of through yum update.

Step 1: Download and install a recent Sun Java JDK RPM

RHEL5 comes with the GNU Compiler for Java (GCJ), which supports Java 1.4.2. Tomcat is okay with 1.4.2, but Solr needs Java 1.5. You can check what Java you are running by typing:
java -version
To get Java 1.5 support, I recommend getting a recent version of the Sun JDK in an RPM. I followed the instructions for "Install the Sun JDK" at Switching to a Sun JVM in RHEL. These instructions walk you through downloading the Sun JDK RPM, installing it, and then installing JPackage. JPackage is a nice tool that allows you to easily switch between multiple versions of Java on a RHEL system.

The instructions below are largely based on the steps detailed at Switching to a Sun JVM in RHEL are:

  1. Download the latest Sun JDK RPM.
    1. Go to java.sun.com and navigate to the downloads page. As of this writing it is http://java.sun.com/javase/downloads/index.jsp
    2. If you are on a text console, you may want to use the "links" text browser rather than wget or curl. The Sun site requires you to accept a license agreement before it will allow you to access the download.
    3. Navigate to the downloads for a recent version of the JDK (e.g. JDK 6 update 2).
    4. On the downloads page, download the "Linux RPM in self-extracting file" This will have a name such as jdk-6u2-linux-i586-rpm.bin
    5. Save the file in a convient location (/tmp would work).
  2. Extract and install the RPM
    1. In the directory that you saved the rpm.bin file, type:
      ./jdk-6u2-linux-i586-rpm.bin
      
    2. The JDK should extract and install. There is a licence agreement.
  3. Download and install JPackage, a tool to help manage multiple installation of Java on the same machine.
    1. Go to ftp://jpackage.hmdc.harvard.edu/JPackage/1.7/generic/RPMS.non-free/
    2. Download the rpm that corresponds to the version of the Sun Java JDK that you just installed. This can be a bit confusing... you need to get the version and build correct (i.e 1.6.0.02). For my installation of JDK 6u2, I downloaded java-1.6.0-sun-compat-1.6.0.02-1jpp.i586.rpm
    3. Install the RPM by typing:
      rpm -ivh java-1.6.0-sun-compat-1.6.0.02-1jpp.i586.rpm
      
  4. Use the jpackage tools to configure which java to use
    1. Enter the following commands and when prompted by each command, select the Sun JDK version that you just installed.
      /usr/sbin/alternatives --config java
      /usr/sbin/alternatives --config javac
      
    2. Verify which java is in use:
      java -version
      

Step 2: (optional) Remove existing tomcat installation

If you don't need it (be sure of this!), you can remove the existing tomcat installation that may have come with RHEL5. It is possible to have two different tomcat installations on the same server, so if you are not sure, it is okay to leave the existing one. I choose to remove the default RHEL5 tomcat since I didn't need it and so that I would not get confused about which version of tomcat was in use.

Here are the steps I used (as root):

  1. Use yum to remove the tomcat5 RHEL5 package:
    yum remove tomcat5*
    
  2. Remove the tomcat user and directory:
    /usr/sbin/userdel -r tomcat
    /bin/rm -fr /usr/share/tomcat5
    

Step 3: Download and install Tomcat from an Apache mirror

  1. First, download Tomcat from Apache or a mirror site and unpack it. For example:
    cd /opt
    wget http://mirrors.ibiblio.org/pub/mirrors/apache/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.tar.gz
    tar xvzf apache-tomcat-5.5.23.tar.gz
    
  2. Next you need to decide where to put Tomcat. You will need a directory for your Tomcat installation and also a place to store your Tomcat applications. This can be the same directory, but does not have to be. The method that I will illustrate here uses /opt/mytomcat for both directories. Note that Tomcat as installed by RHEL5 packages has a 'tomcat' user with a home directory of /usr/share/tomcat5. To allow for two installations of Tomcat and to avoid confusion with the RHEL5 'tomcat' user, I like to distinguish this custom installation by naming it 'mytomcat':

    Often you may need to refer to the directory in which Tomcat is installed. This is stored in the environment variable $CATALINA_HOME (Catalina is Tomcat's servlet container). Thus, by installing Tomcat into /opt/mytomcat, we can consider /opt/mytomcat to be $CATALINA_HOME.

    ln -s /opt/apache-tomcat-5.5.23 /opt/mytomcat
    
  3. Next, you need to decide how you will run Tomcat. Tomcat can be run as root or as a regular user. For security reasons, many people prefer to create a special user account to run Tomcat and to own Tomcat files. In this example, I will show how to set up a 'mytomcat' user. You'll need to do most of the installation and setup as root and can then chown files to be owned by the mytomcat user.

    /usr/sbin/groupadd mytomcat
    /usr/sbin/useradd -g mytomcat -d /opt/mytomcat mytomcat
    
  4. Change the directory to be owned by the mytomcat user (and also group mytomcat):
    chown mytomcat.mytomcat mytomcat
    chown mytomcat.mytomcat apache-tomcat-5.5.23
    
  5. In order for Tomcat to find the installation of Java, you need to set the JAVA_HOME environment variable. One way to do this is to create a file $CATALINA_HOME/bin/setenv.sh that contains the following line:
    JAVA_HOME="/usr/java/latest"
    
  6. At this point, we should be able to try starting Tomcat. Since you are probably root, but we want to run Tomcat as user 'mytomcat', use 'su -c' to run the startup.sh script:
    su mytomcat -c $CATALINA_HOME/bin/startup.sh
    
    If everything worked, you should be able to navigate to http://localhost:8080 and see the Tomcat welcome page.
    To stop the server, use:
    su mytomcat -c $CATALINA_HOME/bin/shutdown.sh
    

Step 4: Download and install SOLR

  1. Download SOLR from Apache or a mirror, unpack it, and set up a link to it from /opt/solr.
    cd /opt
    wget ftp://www.ibiblio.org/pub/mirrors/apache/lucene/solr/1.2/apache-solr-1.2.0.tgz
    tar xvzf apache-solr-1.2.0.tgz
    ln -s apache-solr-1.2.0.tgz /opt/solr
    
  2. Change the ownership and group to be mytomcat:
    chown mytomcat.mytomcat solr
    chown mytomcat.mytomcat apache-solr-1.2.0
    
  3. Make a copy of a SOLR webapp. SOLR instances run as web applications in the webapps directory of Tomcat. There is a default application in /opt/solr/dist that is packaged as a .war file. To use this, just copy it over to /opt/mytomcat/webapps and give it a descriptive name:
    cp /opt/solr/dist/apache-solr-1.2.0.war /opt/mytomcat/webapps/mytestapp.war
    chown mytomcat.mytomcat /opt/mytomcat/webapps/mytestapp.war
    
  4. SOLR stores its indicies for each instance in a "solr/home" directory. For SOLR webapps that you run, you will need to create a solr/home directory. I put all mine in /opt/solr_home, so that I have directories like /opt/solr_home/app1, /opt/solr_home/app2,... There is a sample directory that you should copy that contains the starting files and directories that SOLR expects for the solr/home:
    mkdir /opt/solr_home
    cp -R /opt/solr/example/solr /opt/solr_home/mytestapp
    chown -R mytomcat.mytomcat /opt/solr_home
    

False Starts

RHEL5 Tomcat

First, I needed to make sure that Tomcat was installed and working. This seemed easy enough:
yum install tomcat5
Yum installed the tomcat5 package, and by doing:
yum list installed | grep tomcat5
I could see that I was running Tomcat 5.5.23. So far, so good. Pointing a browser to http://localhost:8080 gave a timeout error -- understandable since I had not started Tomcat yet. The RHEL5 Tomcat package installed a startup script that I used to start Tomcat:
/etc/init.d/tomcat5 start
Again I pointed a browser to http://localhost:8080 this time expecting to see the familiar Tomcat logo and start page. Instead, I got a blank browser window. No timeout error, but no Tomcat start page. Turns out there are additional packages that need to be installed if you want the Tomcat admin webapp and the sample webapps:
yum install tomcat5-webapps
yum install tomcat5-admin-webapps
After installing these, Tomcat needed to be restarted:
/etc/init.d/tomcat5 restart
Finally, when I pointed my browser to when I pointed my browser to http://localhost:8080 I got the familiar Tomcat logo and startup page. I tried a few of the sample applications and all seemed to be working well.

Links/References

  1. SolrTomcat
  2. Switching to a Sun JVM in RHEL


Home |  Publications |  Research |  Teaching |  Notes


Prepared by r c a p r a 3 [at] u n c [dot] e d u
Last modified: March 11 2008 00:19:11
Copyright 2000-2008 by Robert G. Capra III