所需安装包(latest version):
j2sdk-1_4_2_06-linux-i586.bin
httpd-2.0.52.tar.gz
jakarta-tomcat-5.0.28.tar.gz
jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
额外安装包:
apr-1.0.0.tar.gz
apr-util-1.0.0.tar.gz
libtool-1.5.6.tar.gz (or the latest version 1.5.10 from http://www.gnu.org/software/libtool/)
安装目录:
j2sdk --> /usr/local/j2sdk
apache --> /usr/local/apache2
tomcat --> /usr/local/tomcat
1.安装J2sdk1.4.2 , tomcat的运行需要j2sdk支持。
下载地址:http://java.sun.com/j2se/1.4.2/download.html
cp /path/to/j2sdk-1_4_2_06-linux-i586.bin /usr/local/
cd /usr/local
chmod +x j2sdk-1_4_2_06-linux-i586.bin
./j2sdk-1_4_2_06-linux-i586.bin
ln -s j2sdk1.4.2_06 j2sdk
2.设置环境变量,java的运行需要设置一下环境变量。
在/etc/profile中设置如下参数:
JAVA_HOME=/usr/local/j2sdk
CLASSPATH=$JAVA_HOME/lib/tools.jar
PATH=$PATH:$JAVA_HOME/bin
LANG=zh_CN.GBK
LC_ALL=zh_CN.GBK
并且export它们。
修改原来的export语句为:
export JAVA_HOME CLASSPATH LANG LC_ALL PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
若要立即生效,在shell下边依次执行一遍上边的语句。
输入java -version能看到版本信息,即安装j2sdk成功了。
3.安装Aapache.
必须编译成允许动态加载模块的方式,即在configure时要加--enable-so选项,以便加载mod_jk2.so这个整合模块。
wget http://apache.intissite.com/httpd/httpd-2.0.52.tar.gz
tar zxvf httpd-2.0.52.tar.gz
./configure --prefix=/usr/local/apache2 --enable-module=most --enable-shared=max --enable-so
make
make install
4.安装Tomcat,最简单是下载binary版本,直接tar -xzvf jakarta-tomcat-x.x.x 即可。
下载地址:http://jakarta.apache.org/site/binindex.cgi
wget http://apache.247available.com/jakarta/tomcat-5/v5.0.28/bin/jakarta-tomcat-5.0.28.tar.gz
tar zxvf jakarta-tomcat-5.0.28.tar.gz
cp -R jakarta-tomcat-5.0.28 /usr/local
ln -s jakarta-tomcat-5.0.28 tomcat
测试tomcat是否正常:
启动tomcat服务:/usr/local/tomcat/bin/startup.sh
访问 http://ip:8080 是否看到tomcat页面
关闭:/usr/local/tomcat/bin/shutdown.sh
5.tomcat-connectors 用来整合apache和tomcat,编译生成mod_jk2.so模块,apache加载之后,就能将不属于自己的请求转发给tomcat。
***所有步骤中,这步最为复杂。***
选择从source编译生成最符合自己环境的mod_jk2.so ,如果编译不成功,但是大致环境是Redhat DS3,apache2,tomcat4/5的,
可以跟我要一个mod_jk2.so,拷贝在/usr/local/apache2/modules/下就ok。
下载地址:http://apache.osuosl.org/jakarta/tomcat-connectors/jk2/
wget http://apache.osuosl.org/jakarta/tomcat-connectors/jk2/source/jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
tar zxvf jakarta-tomcat-connectors-jk2-2.0.4-src.tar.gz
cd jakarta-tomcat-connectors-jk2-2.0.4-src/
cd jk/native2
#make clean
./configure --with-apxs2=/usr/local/apache2/bin/apxs
make
不出问题的话:
cd ../build/jk2/apache2/
这里会有一个mod_jk2.so,拷贝到/usr/local/apache2/modules目录下。
cp mod_jk2.so /usr/local/apache2/modules/
------------------------------
如果configure通不过,提示:
need to check for Perl first, apxs depends on it...
checking for perl... /usr/bin/perl
configure: error: can't locate libapr
则需安装libapr和libaprutil
wget http://apache.osuosl.org/apr/apr-1.0.0.tar.gz
wget http://apache.osuosl.org/apr/apr-util-1.0.0.tar.gz
tar zxvf apr-1.0.0.tar.gz
cd apr-1.0.0
./configure
make
make install
tar zxvf apr-util-1.0.0.tar.gz
cd apr-util-1.0.0
./configure --with-apr=../apr-1.0.0
make
make install
cd /usr/local/apache2/lib/
ln -s /usr/local/apr/lib/libapr-1.so.0.0.0 libapr-1.so
ln -s /usr/local/apr/lib/libapr-1.so.0.0.0 libapr-1.so.0
ln -s /usr/local/apr/lib/libaprutil-1.so.0.0.0 libaprutil-1.so
ln -s /usr/local/apr/lib/libaprutil-1.so.0.0.0 libaprutil-1.so.0
------------------------------
如果make通不过,/path/to/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/build/jk2/apache2目录下并无mod_jk2.so产生,则需安装新版libtool。
redhat ADS 3自带的libtool是
[root@test apache2]# libtool --version
ltmain.sh (GNU libtool) 1.4.3 (1.922.2.111 2002/10/23 02:54:36
这个版本的libtool编译最新的
jakarta-tomcat-connectors-jk2-2.0.4-src
是不会成功的。
wget http://ftp.gnu.org/gnu/libtool/libtool-1.5.6.tar.gz
tar zxvf libtool-1.5.6.tar.gz
cd libtool-1.5.6
make
make install
[root@test apache2]# /usr/local/bin/libtool --version
ltmain.sh (GNU libtool) 1.5.6 (1.1220.2.94 2004/04/10 16:27:27)
ln -s /usr/local/bin/libtool /usr/local/apache2/build/libtool
再configure,make就ok了。
6.配置:
修改/usr/local/apache2/conf/httpd.conf
DocumentRoot "/var/www/html"
<Directory />
Options None
AllowOverride None
Order deny,Allow
Allow from all
</Directory>
<Directory "/var/www/html">
Options Includes FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
XBitHack on
</Directory>
LoadModule jk2_module modules/mod_jk2.so
DirectoryIndex index.htm index.jsp index.html
<Directory "/var/www/html/WEB-INF">
Deny from all
</Directory>
创建/usr/local/apache2/conf/workers2.properties,内容如下:
[logger]
level=ERROR
[config:]
file=/usr/local/apache2/conf/workers2.properties
debug=0
debugEnv=0
# Alternate file logger
[logger.file]
#level=DEBUG
level=ERROR
file=/var/log/httpd/jk2.log
[shm:]
info=Scoreboard. Required for reconfiguration and status with multiprocess servers
file=/var/log/httpd/jk2.shm
size=1048576
debug=0
disabled=0
[channel.socket:localhost:8009]
info=Ajp13 forwarding over socket
debug=0
tomcatId=localhost:8009
keepalive=1
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
debug=0
[status:]
info=Status worker, displays runtime informations
[uri:/jkstatus/*]
info=Display status information and checks the config file for changes.
worker=ajp13:localhost:8009
[uri:/*.jsp]
worker=ajp13:localhost:8009
context=/
修改/usr/local/tomcat/conf/server.xml
在
<Host name="localhost" debug="0" appBase="apps"
unpackWARs="true" autoDeploy="true">
段中添加:
<Context path="" docBase="/var/www/html" debug="0"
reloadable="true" crossContext="true"/>
保存退出。
7.测试:
在/var/www/html/下创建test.jsp,
内容:
<%@ page import="java.util.*,java.sql.*,java.text.*" contentType="text/html;charset=gb2312" %>
<%
out.println("test page");
%>
访问http://IP/test.jsp,内容正常则说明connector正常。
至此配置全部完成。