Howto install Tomcat 5 on CentOS 4
Posted by Jason on Saturday, October 14, 2006
Howto install tomcat 5 on CentOS 4This howto is assuming that you have a working, minimal installation of CentOS. I will repeat that because if not properly understood it will cause you lots of headaches later. A MINIMAL installation of CentOS. This means that when you are doing your installation, you should scroll to the bottom and check that pretty little box that says "minimal" so that only the bare essentials are installed. We will let yum take care of the rest.
cd /etc/yum.repos.d
wget -P /etc/yum.repos.d http://jpackage.org/jpackage.repo
Other repo's you will want to install are:
wget -P /etc/yum.repos.d http://centos.karan.org/kbsingh-CentOS-Extras.repo
wget -P /etc/yum.repos.d http://www.sipfoundry.org/pub/sipX/3.2/sipx-centos.repo
wget -P /etc/yum.repos.d http://dev.centos.org/centos/4/CentOS-Testing.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
Import extra keys
rpm --import /usr/share/rhn/RPM-GPG-KEY
rpm --import /usr/share/rhn/RPM-GPG-KEY-centos4
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
Check to see if we have necessary packages to manipulate the RPM's
rpm -qi rpm-build
rpm -qi fedora-rpmdevtools
If not, get them:
yum install fedora-rpmdevtools rpm-build
Get some devel tools:
yum install gcc gcc-c++ autoconf automake libtool subversion
yum install rpm-build doxygen fedora-rpmdevtools
Install java tools:
yum install ant-commons-logging ant-junit ant-trax ant-nodeps
yum install jakarta-commons-beanutils jakarta-commons-collections
Please read the man page for alternatives:
man alternatives
Next, since Sun does not make available its jdk via yum, you have to go to the sun site and download it. If you point your browser over to:
http://java.sun.com/javase/downloads/index.jsp
You can download the one you see fit. I downloaded JDK 5.0 Update 7, which at the time of this howto was the current one. When you see the Sun download page, accept the agreement and pick the "Linux RPM in self-extracting file" (the one that ends in rpm.bin).
When your Sun JDK Linux RPM self-extracting file finally arrives you need to execute it, since it is a shell script. It contains the license agreement and the compressed RPM package with Sun JDK. It will ask you if you agree to the long license. Say yes, then it will uncompress the RPM with JDK, and then it will install it. To run it do:
chmod 755 jdk-1_5_0_07-linux-i586-rpm.bin
./jdk-1_5_0_07-linux-i586-rpm.bin
Unfortunately, the Sun RPM package puts files in different locations than the ones required by CentOS. After running the script you will see a new directory /usr/java/jdk1.5.0_07 with JDK files. Note that the actual RPM is left in the directory where you ran the Sun's jdk-1_5_0_07-linux-i586-rpm.bin script, however, you do not need to process the RPM, since script already did it. You may, however, use the RPM package if you want to install the JDK on another machine or if you erased the JDK at some point with a the RPM's rpm -e jdk-1.5.0_07-fcs command. Now, we are ready to install the SUN JDK compatibility RPM from the JPackage.org
yum --enablerepo=jpackage-generic-nonfree install java-1.5.0-sun-compat
This will create a bunch of links in the /etc/alternatives and /usr/lib/jvm directories and others to the /usr/java/jdk1.5.0_07 directory where the Sun JDK distribution resides. To check which files were affected do:
rpm -q -l java-1.5.0-sun-compat
Check if the Sun JDK is really a default by doing:
java -version
If you get:
java version "1.4.2"
gij (GNU libgcj) version 4.1.1 20060525 (Red Hat 4.1.1-1)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
(or similar) then something did NOT work. If you get:
java version "1.5.0_07"Java(TM) 2 Runtime Environment,
Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)
then the Sun JDK is your default. You can use alternatives to check (or change) the default JDK by:
alternatives --config java
It should show something like:
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2 /usr/lib/jvm/jre-1.5.0-sun/bin/java
Enter to keep the current selection[+], or type selection number:
Hit [Enter] key if you want Sun JDK to be a default, or enter 1 if you want to
change back to GNU Java.
Now, there will be times, when you want to get rid of Sun JDK and its entries for alternatives. DO NOT TOUCH THESE LINKS WITH YOUR BARE HANDS. Use yum to uninstall the JPackage Java compatibility package first and then erase the Sun JDK with rpm:
yum erase java-1.5.0-sun-compat
rpm -e jdk-1.5.0_07-fcs
Sometimes yum breaks. A popular situation is when you used rpm to install some package (or the package was installed with an install (older package is kept) rather than an update (older package is removed). In this case, yum gets confused with dependencies and complains, and it does not want to install a package. To see if this is a case (as it was when installing all of this), list all the installed rpm packages for some package name with a command:
rpm -qa | grep "java"
for example. If you see two versions of the same rpm, just erase the old one. Use the
rpm -e full_package_name_with_version
(but skip the .rpm) and then try yum update or yum install again. I am telling you this, since we will definitely have more javas and compats coming, and the mess happens. For example (at this time a hypothetical one), if you got stuck with two compat packages when updates to the JDK were processed:
rpm -qa | grep "java-1.5.0-sun-compat"
java-1.5.0-sun-compat-1.5.0.07-1jppjava-1.5.0-sun-compat-1.5.0.08-1jpp
remove the older package as:
yum erase java-1.5.0-sun-compat-1.5.0.07-1jpp
or, if still no go:
rpm -e java-1.5.0-sun-compat-1.5.0.07-1jpp
and try again.
So... JAVA_HOME. In your shell, type:
JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME
or if you are C-shellish:
setenv JAVA_HOME /usr/lib/jvm/java
For some reason yum was bugging out and not recognizing the xml-commons-apis, i downloaded the RPM from jpackage.org and "rpm -ivh xml-commons-apis" it in place and you can now install tomcat5 without a hitch. (I guess this may be a case of screwy obsoletes and provides with some of the jpp packages)
yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps
We will use redhats standard apache2 with mod_jk to talk to Tomcat, so first we install:
yum install httpd mod_jk-ap20
Check to make sure the default tomcat users are located in /etc/tomcat5/tomcat-users.xml.
[root@centos tomcat5]# cat /etc/tomcat5/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
</tomcat-users>
[root@centos tomcat5]#
Test tomcat5:
service tomcat5 start
If all is well, you can see the tomcat welcome page on 8080. Now we will configure apache to work with mod_jk to grab everything on port 80. 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. So, open up your favorite editor and enter the following in a file named mod_jk.conf in the /etc/httpd/conf.d dirctory:
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.
LoadModule jk_modules/mod_jk.so
JkWorkersFile /etc/tomcat5/jk/workers.properties
JkLogFile /var/log/tomcat5/mod_jk.log
JkLogLevel error
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkMount /jsp-examples/* ajp13
Restart apache:
service httpd restart
Now, when you point your browser at your application you should be able to see everything that is at port 8080 on port 80. As in:
www.mydomain.com:8080
and
www.mydomain.com
Should now be the same. This shows that mod_jk is setup and that apache is proxying tomcat. I hope the howto helped, good luck with your new tomcat config.
'IT' 카테고리의 다른 글
Snow Leopard Endangers Vista (0) | 2008.11.21 |
---|---|
WebSite Design (0) | 2008.11.14 |
Final Glance: Internet companies (0) | 2008.11.05 |
10 best features in Windows 7 for IT professionals (0) | 2008.10.29 |
OpenLDAP password trouble shooting (0) | 2008.10.29 |