TDS Tutorial: Getting Started

Installing Java and Tomcat

System requirements

Installation help

Users of GCJ and OS-provided packages (linux) for Java and/or Tomcat may want to reference the THREDDS mailing list for installation help.

While there are different distributors of Java and servlet containers, Unidata develops, uses and tests the THREDDS Data Server using Sun Java and the Apache Tomcat servlet container.

Installing Java

  1. Download current Java SE Developer Kit (JDK) from Sun.
  2. We will be using the Linux x32-bit, non-rpm, self-extracting file for this workshop:

    jdk-6u15-linux-i586.bin

  3. Install the JDK as per the Sun installation instructions.
  4. Copy the self-extracting file to the installation directory (our home directory is the installation directory in this example):

    $ cp jdk-6u15-linux-i586.bin ~
    $ cd
    

    Change the permissions on the file to be executable:

    $ ls -l jdk-6u15-linux-i586.bin 
    rw-r--r-- 1 thredds workshop 81771117 2009-08-03 15:56 jdk-6u15-linux-i586.bin
    
    $ chmod 755 jdk-6u15-linux-i586.bin  
    
    $ ls -l jdk-6u15-linux-i586.bin 
    -rwxr-xr-x 1 thredds workshop 81771117 2009-08-03 15:56 jdk-6u15-linux-i586.bin
    

    Run self-extracting file and agree to the terms of the code license:

    $ ./jdk-6u15-linux-i586.bin
    
  5. Set the $JAVA_HOME environment variable.
  6. $ set JAVA_HOME=/home/thredds/jdk1.6.0_15  
    $ echo $JAVA_HOME 
    /home/thredds/jdk1.6.0_15 
    

Troubleshooting tips

  • Check to make sure the JDK self-extracting file has the correct permissions and is executable.
  • If you receive an error while running the self-extracting file, you may have downloaded the wrong type of JDK for your machine.
  • Depending on your OS (e.g., Solaris), you may need install both the 32-bit and 64-bit self-extracting files.

Installing Tomcat

  1. Download current version of the Tomcat servlet container.
  2. We will be using the core binary tar.gz file for this workshop:

    apache-tomcat-6.0.20.tar.gz

  3. Install Tomcat as per the Apache Tomcat installation instructions.
  4. Copy the binary tar.gz file to the installation directory (our home directory is the installation directory in this example):

    $ cp apache-tomcat-6.0.20.tar.gz ~
    $ cd
    

    Unpack the archive to create Tomcat directory:

    $ tar xvzf apache-tomcat-6.0.20.tar.gz
    
    $ ls -ld apache-tomcat-6.0.20
    drwxr-xr-x 9 thredds workshop    4096 2009-08-03 16:04 apache-tomcat-6.0.20
    
  5. Set the $TOMCAT_HOME environment variable.
  6. $ set TOMCAT_HOME=/home/thredds/apache-tomcat-6.0.20
    $ echo $TOMCAT_HOME
    /home/thredds/apache-tomcat-6.0.20
    

Exercise One: Install Java and Tomcat

  1. Using the steps outlined in the above sections, install the JDK and Tomcat in /home/thredds.

Tomcat Directory Structure: Quick Tour

Exploring $TOMCAT_HOME

  1. Examine the Tomcat directory structure.
  2. Move into the new Tomcat directory and do a long listing:

    $ cd apache-tomcat-6.0.20
    $  ls -l 
    total 88
    drwxr-xr-x 2 thredds workshop  4096 2009-08-03 16:04 bin
    drwxr-xr-x 2 thredds workshop  4096 2009-05-13 17:15 conf
    drwxr-xr-x 2 thredds workshop  4096 2009-08-03 16:04 lib
    -rw-r--r-- 1 thredds workshop 37951 2009-05-13 17:15 LICENSE
    drwxr-xr-x 2 thredds workshop  4096 2009-05-13 17:15 logs
    -rw-r--r-- 1 thredds workshop   556 2009-05-13 17:15 NOTICE
    -rw-r--r-- 1 thredds workshop  7317 2009-05-13 17:15 RELEASE-NOTES
    -rw-r--r-- 1 thredds workshop  6368 2009-05-13 17:15 RUNNING.txt
    drwxr-xr-x 2 thredds workshop  4096 2009-08-03 16:04 temp
    drwxr-xr-x 7 thredds workshop  4096 2009-05-13 17:15 webapps
    drwxr-xr-x 2 thredds workshop  4096 2009-05-13 17:15 work
    
  3. Familiarize yourself with the following important directories.
  4. $TOMCAT_HOME/bin

    • Contains startup.sh, shutdown.sh and other scripts/programs.
    • The *.sh files (for Unix systems) are functional duplicates of the *.bat files (for Windows systems).

    $TOMCAT_HOME/conf

    • Server-wide Tomcat configuration.
    • You will modify server.xml and tomcat-users.xml to adjust logging, authentication and access control, enable SSL, etc.
    • Web applications can override some server-wide settings in their own configuration files (more about that later).

    $TOMCAT_HOME/logs

    • Tomcat log files are here by default.
    • This is one of the directories you will be looking for log files (the TDS logs elsewhere by default).
    • The log files should be your first stop for troubleshooting Tomcat and TDS issues. (Hint, hint.)
    • Logs files may contain useful information for assessing the security of your system.
    • You will become very familiar with the Tomcat-generated catalina.out and access.yyyy-mm-dd.log files by the end of this workshop.

    $TOMCAT_HOME/webapps

    • Contains web applications directories and WAR files.
    • This is where we will be putting the TDS web application.
    • You will also be using the manager application that comes with Tomcat during this workshop.

Running Tomcat

Starting & stopping Tomcat

  1. Tomcat isn't currently running so we need to start it up.
  2. Move into the $TOMCAT_HOME/bin/ directory and run the startup.sh script:

    $ cd $TOMCAT_HOME/bin
    $  ./startup.sh
    
  3. Verify Tomcat is running.
  4. Look and see if you have a Tomcat process running:

    $ ps -ef | grep tomcat
    thredds   4443     1 21 16:08 pts/0    00:00:03 /usr/bin/java -Djava.util.logging.config.file=/home/thredds/apache-tomcat-6.0.20/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/home/thredds/apache-tomcat-6.0.20/endorsed -classpath :/home/thredds/apache-tomcat-6.0.20/bin/bootstrap.jar -Dcatalina.base=/home/thredds/apache-tomcat-6.0.20 -Dcatalina.home=/home/thredds/apache-tomcat-6.0.20 -Djava.io.tmpdir=/home/thredds/apache-tomcat-6.0.20/temp org.apache.catalina.startup.Bootstrap start
    

    Open a new browser window/tab and go to http://localhost:8080/ to verify Tomcat is running:

    Tomcat Default Home Page

  5. See if you can shutdown Tomcat.
  6. Run the $TOMCAT_HOME/bin/shutdown.sh script:

    $ $TOMCAT_HOME/bin/shutdown.sh
    

Troubleshooting tips

  • Check the logs mostly recently generated in $TOMCAT_HOME/logs for clues about why Tomcat failed to start or stop.
  • Pay particular attention to what is being reported in Tomcat's main log file: $TOMCAT_HOME/logs/catalina.out.

Setting $JAVA_HOME, $JAVA_OPTS and $CATALINA_HOME

We are going to create a file called setenv.sh in the $TOMCAT_HOME/bin directory to:

Why are we setting $JAVA_HOME and $CATALINA_HOME if we already have set them in our environment?

Which Java is Tomcat currently using? (Hint: what was sent to STDOUT when running the startup.sh and shutdown.sh?)

  1. Create setenv.sh file.
  2. Using your favorite text editor (gedit, vi, emacs, nano, etc.), create a new file called setenv.sh in $TOMCAT_HOME/bin:

    $  pwd 
    /home/thredds/apache-tomcat-6.0.20/bin/
    $ vi setenv.sh
    

    Add the following information and save setenv.sh:

    #!/bin/sh
    #
    # ENVARS for Tomcat and TDS environment
    #
    JAVA_HOME="/home/thredds/jdk1.6.0_15"
    export JAVA_HOME
    JAVA_OPTS="-Xmx1500m -Xms512m -server -Djava.awt.headless=true"
    export JAVA_OPTS
    CATALINA_HOME="/home/thredds/apache-tomcat-6.0.20"
    export CATALINA_HOME
    

    Settings

    Whenever possible, Unidata recommends -Xmx1500m for 32-bit systems, and -Xmx2048m - -Xmx4096m for 64-bit systems.

    The parameters we pass to $JAVA_OPTS:

    • -Xms is the initial allocated memory of the JVM (for performance).
    • -Xmx the maximum allocated memory of the JVM (for performance).
    • -server tells the Hostspot compiler to run the JVM in "server" mode.
    • -Djava.awt.headless=true is needed to prevent graphics rendering code to assume that a graphics console exists. Without this, WMS code will crash the server in some circumstances.
  3. Restart Tomcat to implement your changes.
  4. Restart Tomcat and examine the output generated to the terminal window by the startup script:

    $ $TOMCAT_HOME/bin/startup.sh
    sing CATALINA_BASE:   /home/thredds/apache-tomcat-6.0.20
    Using CATALINA_HOME:   /home/thredds/apache-tomcat-6.0.20
    Using CATALINA_TMPDIR: /home/thredds/apache-tomcat-6.0.20/temp
    Using JRE_HOME:       /home/thredds/jdk1.6.0_15
    

    Did you notice any difference in the what is being reported to STDOUT during startup?

    Take a look at the running Tomcat process to see the new $JAVA_OPTS settings:

    $ ps -ef | grep tomcat
    dds   4606     1 99 16:15 pts/0    00:00:03 /home/thredds/jdk1.6.0_15/bin/java -Djava.util.logging.config.file=/home/thredds/apache-tomcat-6.0.20/conf/logging.properties -Xmx256m -Xms256m -server -Djava.awt.headless=true -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/home/thredds/apache-tomcat-6.0.20/endorsed -classpath :/home/thredds/apache-tomcat-6.0.20/bin/bootstrap.jar -Dcatalina.base=/home/thredds/apache-tomcat-6.0.20 -Dcatalina.home=/home/thredds/apache-tomcat-6.0.20 -Djava.io.tmpdir=/home/thredds/apache-tomcat-6.0.20/temp org.apache.catalina.startup.Bootstrap start
    thredds   4626  4207  0 16:15 pts/0    00:00:00 grep tomcat
    

    What allows us to create the setenv.sh file and have its contents read? (Hint: have a look at the $TOMCAT_HOME/bin/catalina.sh starting around line 110).

    Troubleshooting tips

    • Do not forget include the 'm' in your -Xms and -Xmx settings.
    • You may have allocated too much memory for the JVM settings if Tomcat fails to start and you get the following error reported in the Tomcat log catalina.out:
    • Error occurred during initialization of VM
      Could not reserve enough space for object heap
      
    • Likewise, if there is an error with your JVM memory allocation syntax in the setenv.sh file, it will be reported to catalina.out:
    • Error occurred during initialization of VM
      Incompatible minimum and maximum heap sizes specified
      

Exercise Two: Set $JAVA_HOME, $JAVA_OPTS and $CATALINA_HOME

  1. Create a setenv.sh file in $TOMCAT_HOME/bin/ to set $JAVA_HOME, $JAVA_OPTS and $CATALINA_HOME.

Deploying the TDS

About WAR files

Downloading & deploying thredds.war

Upgrading the TDS

The reference documentation contains information on upgrading the TDS.

  1. Download the TDS WAR file from Unidata's web site.
  2. We will be using the current TDS 4.0 (stable) version for this workshop:

    thredds.war

  3. Deploy the TDS in Tomcat.
  4. Put thredds.war in the Tomcat webapps/ directory:

    $ cp thredds.war $TOMCAT_HOME/webapps
    $ cd $TOMCAT_HOME/webapps
    
    $ ls -l
    total 22820
    drwxr-xr-x 10 thredds workshop     4096 2009-08-03 16:04 docs
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:04 examples
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:04 host-manager
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:04 manager
    drwxr-xr-x  3 thredds workshop     4096 2009-08-03 16:04 ROOT
    -rw-r--r--  1 thredds workshop 23317222 2009-08-03 16:22 thredds.war
    
  5. Confirm the TDS has been deployed.
  6. If Tomcat is already running, wait a couple of seconds after placing the WAR file in webapps/ and then verify the thredds.war file was unpacked:

    $ $TOMCAT_HOME/bin/startup.sh
    
    $ ls -l
    total 22824
    drwxr-xr-x 10 thredds workshop     4096 2009-08-03 16:04 docs
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:04 examples
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:04 host-manager
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:04 manager
    drwxr-xr-x  3 thredds workshop     4096 2009-08-03 16:04 ROOT
    drwxr-xr-x  5 thredds workshop     4096 2009-08-03 16:23 thredds
    -rw-r--r--  1 thredds workshop 23317222 2009-08-03 16:22 thredds.war
    

    Go to http://localhost:8080/thredds/ in your browser to verify the TDS has been deployed:

    THREDDS Distribution Catalog

Troubleshooting tips

  • Any error in the deployment will be reported in $TOMCAT_HOME/logs/catalina.out.
  • Be sure you have downloaded and deployed the TDS 4.0 (stable) version for this workshop (the version number will appear in the blue bar at the bottom of TDS catalog pages).

Exercise Three: Deploy your own instance of the THREDDS Data Server

  1. Deploy the TDS in your newly-installed Tomcat.
  2. Once deployed, browse the test catalogs & datasets that come with the distribution.
  3. Look at the directory contents of $TOMCAT_HOME.
  4. Do you notice anything new?

Tomcat Log Files

$TOMCAT_HOME/logs

  1. Look at the different types of log files being generated in $TOMCAT_HOME/logs.
  2. Move into the logs directory to see the type of information being logged:

    $ cd $TOMCAT_HOME/logs
    $ ls -l
    total 12
    -rw-r--r-- 1 thredds workshop 2952 2009-08-03 16:23 catalina.2009-08-03.log
    -rw-r--r-- 1 thredds workshop 3331 2009-08-03 16:23 catalina.out
    -rw-r--r-- 1 thredds workshop    0 2009-08-03 16:08 host-manager.2009-08-03.log
    -rw-r--r-- 1 thredds workshop 2030 2009-08-03 16:23 localhost.2009-08-03.log
    -rw-r--r-- 1 thredds workshop    0 2009-08-03 16:08 manager.2009-08-03.log
    

    Do you see a correspondence between some of the web applications in the $TOMCAT_HOME/webapps directory and the naming of certain log files?

    Is there a difference in the information being logged to catalina.out versus catalina.yyyy-mm-dd.log?

    Are some log files more verbose than others?

  3. Examining catalina.out.
  4. Open another terminal window (hereafter referred to as terminal #2) and run the following command in the new terminal:

    $ tail -f /home/thredds/apache-tomcat-6.0.20/logs/catalina.out
    

    In your original terminal window, start/stop and start Tomcat and watch what is being logged to catalina.out in the terminal #2 window.

    Is it only errors messages being reported to catalina.out?

    What messages in catalina.out are from the TDS?

Things to know about catalina.out

catalina.out

The Tomcat Users mailing list has seen a lot of traffic dedicated to catalina.out logging and rotation.

THREDDS This document is maintained by Unidata. Send comments to THREDDS support.