#tomcat4只支持servlet2.2/jsp1.2
#推荐使用tomcat5.0.29,支持servlet2.4/jsp2.0
参考网站:http://ezine.daemonnews.org/200203/tomcat-jakarta.html
一、Tomcat Installation:
1、download Jakarta-Tomcat from http://jakarta.apache.org. Get the binary to start. Remember this is Java so the binary will work on FreeBSD.
解压文件:
tar -xvzf jakarta-tomcat-4.0.2.tar.gz
2、设置环境变量(以下四种环境变量设置都可以,两个csh,两个bsh):
3、Free# vi .cshrc(csh用户环境变量设置)
set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin $HOME/bin /usr/local/jdk1.4.2/bin /usr/local/jdk1.4.2/jre/bin)
setenv ALT_BOOTDIR /usr/local/linux-sun-jdk1.4.2/bin/java #设置jdk的环境变量
setenv ALT_JAVAWS_BOOTDIR /usr/local/linux-sun-jdk1.4.2/bin/java #设置jdk的环境变量
setenv JAVA_HOME /usr/local/jdk1.4.2 #设置tomcat的环境变量
setenv CLASSPATH .:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre:$JAVA_HOME/bin:/usr/local/jakarta-tomcat-4.1.31/common/lib/servlet.jar #设置tomcat的环境变量
setenv CATALINA_HOME /usr/local/jakarta-tomcat-4.1.31 #设置tomcat的环境变量
或
Free# vi /etc/csh.login(csh系统环境变量设置)
setenv PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/local/jdk1.4.2/bin:/usr/local/jdk1.4.2/jre/bin
setenv JAVA_HOME=/usr/local/jdk1.4.2
setenv CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre:/usr/local/jakarta-tomcat-4.1.31/common/lib/servlet.jar
setenv CATALINA_HOME=/usr/local/jakarta-tomcat-4.1.31
或
Free# vi .profile(bsh用户环境变量设置)
set PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
set JAVA_HOME=/usr/local/jdk1.4.2
set CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre:/usr/local/jakarta-tomcat-4.1.31/common/lib/servlet.jar
set CATALINA_HOME=/usr/local/jakarta-tomcat-4.1.31
#export CLASSPATH=/usr/local/jakarta-tomcat-4.1.31/common/lib/servlet.jar
或
Free# vi /etc/profile(bsh系统环境变量设置)
set PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/local/jdk1.4.2/bin:/usr/local/jdk1.4.2/jre/bin
set JAVA_HOME=/usr/local/jdk1.4.2
set CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre:/usr/local/jakarta-tomcat-4.1.31/common/lib/servlet.jar
set CATALINA_HOME=/usr/local/jakarta-tomcat-4.1.31
若是b_shell,启动/etc/profile和用户根目录下的 .profile文件(若是c_shell,则执行/etc/csh.login和用户根目录下的.login和.cshrc;若是korn shell,则会执行环境变量ENV所定义的文件)配置用户环境变量。
要查看用户使用何种shell,用这个命令:finger "用户"
二、Tomcat Running
Test the installation by changing directory to the jakarta-tomcat-4.0.2/bin and type:
./startup.sh
If you get a bad interpreter error, you need to run
chmod +x *.sh
(For production machines set executable permissions accordingly.)
Point your browser to:
You should see the Tomcat home page with several examples of both Servlets and Java Server Pages. As I mentioned earlier, Servlets and JSPs do not require a Java capable browser.
To stop Tomcat just run:
/usr/jakarta-tomcat-4.0.2/bin/shutdown.sh
整合及涉及到的4个配置文件
Apache 的 httpd.conf 和 workers.properties (创建)
Tomcat 的 server.xml 和 jk2.properties (不过这两个文件,我没改过也成功了)
三、mod_jk的配置(tomcat与apache整合的包)二进制包安装,可以直接使用
所需软件包:mod_jk-apache2.tbz(主要就是需要mod_jk.so的动态连接库文件,见第一步)
1、把mod_jk-apache2\libexec\apache2\mod_jk.so文件考到/usr/local/apache2/modules/下
2、在以下目录建一个文件:workers.properties
#cd /usr/local/apache2/conf
#vi workers.properties
workers.tomcat_home=/usr/local/jakarta-tomcat-4.1.31
workers.java_home=/usr/local/jdk1.4.2
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
四、apache的配置
#vi httpd.conf
在LoadModule处增加下面一行
LoadModule jk_module modules/mod_jk.so
另外要增加mod_jk的配置文件
<IfModule mod_jk.c>
JkWorkersFile /usr/local/apache2/conf/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel error
</IfModule>
增加要通过mod_jk匹配的文件类型
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /*.do ajp13
JkMount /servlet/* ajp13
</IfModule>
或
五、源码安装
#cd /usr/local/
#tar -xzvf jakarta-tomcat-connectors-jk2-2.0.2-src.tar.gz
#cd jakarta-tomcat-connectors-jk2-2.0.2-src
#cd jk/native2
#chmod 755 buildconf.sh
#./configure --with-apxs2=/usr/local/apache/bin/apxs --enable-EAPI
#make
#make install
#如果make install 不成功需要手工发布mod_jk2.so
#cd /usr/local/src/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/build/jk2/apache2
#cp *.so /usr/local/apache/modules/
--- 好男儿
yhj1065