Tomcat 5 on RedHat Enterprise Linux using JPackage.org Packages
Contents
Overview
A guide for setting up Tomcat 5 using Sun Java 1.4.2 on RedHat Enterprise Linux using JPackage.org RPM files. Apache 2.0 with mod_jk will also be configured to provide access to Tomcat from Apache.
If you have any comments or feedback on this guide please leave comments on my blog.
This guide is current as of 8th February 2006. It uses JPackage 1.6. Througout I reference full path names that include versions, these will without a doubt change as the JPackage team makes progress, you can always find full paths and links on their site.
I am using CentOS 4.2 as my development platform, it is a RedHat Entperise clone, on RedHat Enterprise itself you will need to configure YUM to use this guide.
I have a local Yum repository and this guide will put locally build RPM's into this repository. It is out of the scope of this article to detail the setup of such a repository though you can find a rough guide here.
Add JPackage Repositories
The JPackage project provides it's RPM's through apt, yum, urpmi or up2date using yum repositories. This guide will use the yum method but it is easy to use other methods, there is a guide to setting up other methods on their site.
Yum on CentOS stores its repositories in /etc/yum.repos.d you'll simply need to copy the provided repository there and edit it to your needs:
cd /etc/yum.repos.d wget http://jpackage.org/jpackage.repo
Edit the jpackage.repo file you retrieved and enable the repositories appropriate to your distribution. In the case of CentOS I set enabled=1 on the jpackage-rhel sections.
The JPackage RPMs are digitally signed using a GPG key, import their key into your RPM keyring
rpm --import http://jpackage.org/jpackage.asc
Before being able to use the new repositories you'll need to build a local cache of their metadata, running this will access the mirrors and might take some time depending on your connection and CPU speed.
yum makecache
Configure RedHat for building RPMs
The JPackage project may not distribute all Java related software as pre-build binaries, this is due to legalities in the Java license, you'll need to go to the Sun website and download some source files then use JPackage provided Source RPMs to build the resulting binary RPMs yourself.
This sounds like a big job but it is not really, it's very simple. First we need to prepare RedHat to be able to build RPM files, all you need is to install the rpm-build package, with yum on CentOS:
yum install rpm-build
That sets it all up for you to be able to build RPMs from source.
Build Non-Free RPMs
In order to get the basic Tomcat 5 going you'll need to get at least the Java 1.4.2 Environment including JTA built from source.
Generic guides for building the non free parts of JPackage are provided on their site, I'll show a quick run through on what I did here using CentOS though.
First you need to retrieve and install the Source RPMs for java-1.4.2-sun-1.4.2.10-1jpp.nosrc.rpm and jta-1.0.1-0.b.4jpp.nosrc.rpm
rpm -ivh http://mirrors.dotsrc.org/jpackage/1.6/generic/non-free/SRPMS/java-1.4.2-sun-1.4.2.10-1jpp.nosrc.rpm rpm -ivh http://mirrors.dotsrc.org/jpackage/1.6/generic/non-free/SRPMS/jta-1.0.1-0.b.4jpp.nosrc.rpm
Visit java.sun.com and download the "J2SE SDK", there are many versions and types of files available, you want the one called j2sdk-1_4_2_10-linux-i586.bin put it in /usr/src/redhat/SOURCES
Building the binary RPMs is very easy if you got the above right:
cd /usr/src/redhat/SPECS ; rpmbuild -ba java-1.4.2-sun.spec
If all goes well the last few lines you'll see from the above command should be:
Wrote: /usr/src/redhat/SRPMS/java-1.4.2-sun-1.4.2.10-1jpp.nosrc.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-devel-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-src-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-demo-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-plugin-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-fonts-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-alsa-1.4.2.10-1jpp.i586.rpm Wrote: /usr/src/redhat/RPMS/i586/java-1.4.2-sun-jdbc-1.4.2.10-1jpp.i586.rpm
Download the JTA source and docs from java.sun.com and place these in the /usr/src/redhat/SOURCES directory then build the binary package:
cd /usr/src/redhat/SPECS ; rpmbuild -ba jta.spec
If all goes well the last few lines you'll see from the above command should be:
Wrote: /usr/src/redhat/SRPMS/jta-1.0.1-0.b.4jpp.nosrc.rpm Wrote: /usr/src/redhat/RPMS/noarch/jta-1.0.1-0.b.4jpp.noarch.rpm Wrote: /usr/src/redhat/RPMS/noarch/jta-javadoc-1.0.1-0.b.4jpp.noarch.rpm
All that is left now is for you to add the RPM files listed above - for JTA and the Java 1.4.2 - local yum repository.
Install All Required RPMs
All the required packages should now be available in binary format. You can use yum to install them, you can do all the below in one big yum command, I'll split it out here for clarity.
For any additional servers you'll only need to configure your local Yum repository and follow the steps from this point onward.
First we need to get Java onto the machine, you'll need the SDK since Tomcat must compile servlets and JSPs.
Since I am using Yum and a Yum repository the next command will sort out all dependencies on it's own, I've not tried this without Yum though I've had reports of users having some difficulty using just pure RPM to get the depency hell sorted, I'd strongly recommend you look at Yum
yum install java-1.4.2-sun-devel-1.4.2.10
We will use RedHat's standard Apache 2.0 with mod_jk to talk to Tomcat, so first we install these two:
yum install httpd mod_jk-ap20
Tomcat 5.0 requires some crypto libs but Yum's own dependency resolution gets a bit confused here so we need to help it along by satisfying that dependency first:
yum install gnu-crypto-sasl-jdk1.4
Now we're ready to install Tomcat 5.0, this step will add a large number of dependencies to your machine therefore it can take quite some time depending on your network speed.
yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps
Create an Admin User for Tomcat
The Tomcat Manager and Administration tool requires a user to be setup, users are by default configured in /etc/tomcat5/tomcat-users.xml. Edit the file and add a user, the example below adds 2 roles - admin and manager - and a new admin user with both roles assigned.
Replace the password in the XML below with one of your own, leaving this with a weak password will seriously compromise your site.
<?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="manager"/> <role rolename="admin"/> <user username="admin" password="password" roles="admin,manager"/> </tomcat-users>
Start and Test Tomcat
With the users defined to access the admin tools you are now ready to start the Tomcat 5 server and perform simple tests showing that it works.
# service tomcat5 start
Now browse to http://localhost:8080/ and you should see the Tomcat welcome page. If you click on any of the links under the Administration heading you can login using the admin username and password you chose, there are also a number of test JSPs and Servlets provided that you can test. All of these should work at this point.
Configuring Apache with mod_jk
Having confirmed that accessing Tomcat directly works all that is left now is to configure mod_jk to facilitate accessing files served by Tomcat via your normal port 80 webroot as served up by Apache.
RedHat Apache configuration has a directory for custom configuration files in /etc/httpd/conf.d we will add the mod_jk config there in a seperate file called mod_jk.conf
LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/tomcat5/jk/workers.properties JkLogFile /var/log/tomcat5/mod_jk.log JkLogLevel error JkMount /jsp-examples/* ajp13
Create a directory for the mod_jk properties file in /etc/tomcat5/jk and put the following in a file called workers.properties in that directory. Using this file you can change location of the log files and the log level later on. Full details on the commands available in this file can be found in the Tomcat Documentation
workers.tomcat_home=/usr/share/tomcat5 workers.java_home=/usr/lib/jvm/java ps=/ worker.list=ajp13 worker.ajp13.port=8009 worker.ajp13.host=localhost worker.ajp13.type=ajp13 worker.ajp13.cache_timeout=15 worker.inprocess.type=jni
Restart Apache using the command:
# service httpd restart
You should now be able to access the Tomcat examples through Apache as http://localhost/jsp-examples/ it should act the same as http://localhost:8080/jsp-examples/
Changelog
12/11/2006 |
Fix the workers.properties sample after blog feedback |
08/02/2006 |
Initial Release |
