Border
Author: Bruce Grant, Jr. (BX)
Published: April 15, 2008
Installing Tomcat on Ubuntu 7.10
How I got my server up Part VI: a Guide for Linux Novices
This guide will walk through how to install and configure a Tomcat application server tied into Apache using mod_jk on a newly installed Ubuntu Linux Server and is meant for the complete Linux novice. The guide assumes readers have a moderate degree of experience with Tomcat, Apache and Java and application servers in general. This is the sixth installment of a series of articles explaining the technologies used to bring this web site online.
This guide explains how I installed and configured Tomcat to power this web site on an Ubuntu server. Why did I use Tomcat? My goal was to create a web site that would be really easy to maintain once I got it up. In later articles I'll explain the specific frameworks I used inside of Tomcat that made creating and maintaining this site a snap. So lets get on with it.
Java already Installed
Fedora allows multiple versions of Java to be installed simultaneously and then has a mechanism to determine which is the default. If you're following my guides then you won't hava Java installed already and won't have to worry about dealing with previously installed versions of Java. If you have Java installed pay close attention to sections I.2.D and I.2.E.

Assumptions
This guide assumes that you have a working knowledge of Java, Tomcat and web applications in general. It assumes you've already installed Apache2 (see previouse guide). It also assumes you have "sysvconfig" installed to manage services:

  1. Installing Tomcat on Ubuntu 7.10
    1. Java Fun
      The way that Ubuntu installs Java from prepared packages may be problematic for a production application server. Don't trust it.
      Each version of Java has a direct download page which you may use to download from the command line.
      1. Download Java
        1. At the top of the page you'll find a link "Previous Snapshot Releases" click it and scroll down to the binary release you want and click it
        2. Scroll down to Linux Platform and find the Linux self-extracting JDK file
        3. Remember the URL and jump over to a terminal for your server and find a temporary directory to run this command in:
          Download JDK
          Change the URL to the one you want to download. Also note I'm using wget to download the file over HTTP, if you don't have wget you'll need to get it: sudo apt-get install wget
      2. Setting up Java
        1. Go to the directory where you downloaded the JDK
        2. Make the file executable and execute it
          After executing it you'll need to hit space bar to scroll through the license agreement and type yes at the bottom to accept it.
        3. You now have a folder containing the JDK. Mine was named ./jdk1.6.2_02. We need to move it to its final destination in /usr/lib. I renamed the directory also so it's easier to manage.
        4. As noted above Ubuntu wants to know about installed versions of java and manage which one is the "default" version to use. So the following will tell Ubuntu about the JDK version we just installed.
        5. If you have other versions of Java installed you'll want to also set the new JDK as the default. After running the command below simply select the number of the just installed JDK.
      3. Set Java Paths
        We need to specify the JAVA_HOME and CLASSPATH environment variables both globally and in your local user settings, just to be safe.
        1. Set Global Paths
          Modify File: sudo nano /etc/environment
          Add these lines to the bottom of the file and change the path to reflect where you put the JDK.

    2. Tomcat
      Again I recommend you download Tomcat and install it manually instead of relying on a package.
      1. Download Tomcat
        1. Pick the version you want and remember the URL of tar.gz version
        2. Jump over to a terminal for your server, find a temporary directory to run this command in:
          Download Tomcat
          Change the URL to the one you want to download. Also note I'm using wget to download the file over HTTP, if you don't have wget you'll need to get it: sudo apt-get install wget
        3. Unpack tomcat and copy it to its final home
      2. Set Tomcat Paths
        We need to specify the CATALINA_HOME environment variable both globally and in your local user settings, just to be safe.
        1. Set Global Paths
          Modify File: sudo nano /etc/environment
          Add this line to the bottom of the file and change the path to reflect where you put tomcat.
        2. Set User Paths
          Modify Files
          Add line 4 to the bottom of this file (note change myusername to the username you usually log in with)
          Add line 4 to the bottom of this file
      3. Tomcat in Headless Mode
        I run my server without a windowing environment (gnome, kde, etc.) since I don't need one and it sucks resources from my server. However, I do have Java code that needs a display device context in order to do image manipulation (Canvas, Panel and others also require it). If you're in the same boat this section is for you, otherwise push on to the next.
        1. Modify Tomcat Startup Script
        2. X-Windows Virtual Frame buffer (XVbf)
          XVbf is a lightweight but fast virtual framebuffer X11 server enabling all the graphical capabilities Java might require but without requiring a full x-windows installation.
          sudo apt-get install xvfb
      4. Install Tomcat as Service
        1. Copy the tomcat startup script to the system 5 init daemon so it will startup automatically on reboot
          sudo cp /usr/share/tomcat6/bin/catalina.sh /etc/init.d/tomcat
        2. Run sysvconfig
          sudo sysvconfig
        3. You'll now see a menu. Scroll to Enable/Disable and hit return
        4. Scroll down until you see tomcat and hit space bar (it will now startup on reboot)
        5. Exit this screen and then scroll to finished and hit return
        6. Then scroll down to quit and hit return
      5. Controlling Tomcat
      1. Configure mod_jk

      2. Apache to Tomcat via mod_jk
        Lastly you need to modify your virtual hosts to specify which URL patterns to forward requests on to Tomcat via mod_jk.
        Directory Mounted to Tomcat
        This appears in my /etc/apache2/sites-available/default virtual host. I have a webapp in tomcat named webapp_name. Any url with /webapp_name will be forwarded to tomcat from apache.
        I don't want any content cached by browsers since all content from here is dynamic (uses mod_expires).
        Mounts this URL path to Tomcat using the ajp13_worker specified in my workers.properties file (see above).
Comments
Be the first to add a comment.
Add a Comment
User:
Anonymous (Login or Create Account or Help)
Border