分类: LINUX
2005-03-21 23:33:36
安装环境:
OS:Redhat Enterprise AS 3
apahce:使用系统自带httpd-2.0.46,使用其它版本的redhat自带的apache安装过程也一样。
Tomcat:Tomcat-5.5.7
jdk:mod_jk:2.0.4
参考:
1. 安装apache
系统自带,无须安装。需要注意的是需要安装httpd开发包,用于编译mod_jk.
查看是否安装httpd-develop
#rpm -qa|grep httpd-devel
httpd-devel-2.0.46-38.ent
如果出现以上信息说明httpd开发包已安装,如果未安装请从redhat第三张盘中安装。
2、安装jdk
从java.sun.com下载jdk-1_5_0_01-linux-i586-rpm.bin,tomcat5需要jdk5的支持。
下载后:
#chmod 755 jdk-1_5_0_01-linux-i586-rpm.bin
#rpm -ivh dk-1_5_0_01-linux-i586.rpm
在/etc/profile文件中加入:
JAVA_HOME=/usr/java/jdk1.5.0_01
export JAVA_HOME
PATH=$PATH:/usr/java/jdk1.5.0_01/bin
export PATH
export CATALINA_HOME=/usr/local/tomcat
export TOMCAT_HOME=/usr/local/tomcat
3.安装Tomcat
#wget
#tar zxvf jakarta-tomcat-5.5.7.tar.gz
#mv jakarta-tomcat-5.5.7 /usr/local/tomcat
4、编译和设置mod_jk
此时注意重新登录服务器使环境变量生效。
#wget http://apache.justdn.org/jakarta/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz
#tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz
#cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/
#./configure --with-apxs2=/usr/sbin/apxs --with-jni --with-apr-lib=/usr/lib
#vi server/apache2/Makefile
将:LIBTOOL=/bin/sh /var/www/build/libtool --silent
改为:LIBTOOL=/usr/bin/libtool
将:
fdef APR_LIBDIR_LA
JK_LDFLAGS=-L${APACHE2_LIBDIR} -lcrypt
else
JK_LDFLAGS=-lcrypt ${APR_LIBS}
endif
改为:
ifdef APR_LIBDIR_LA
JK_LDFLAGS=-L${APACHE2_LIBDIR} -lcrypt
else
JK_LDFLAGS=-lcrypt ${APR_LIBS} -lapr-0 -laprutil-0 -lgdbm -ldb-4.1 -lexpat
endif
如果不修改以上内容,将出现以下错误:
INFO: APR not loaded, disabling jni components: java.io.IOException: java.lang.UnsatisfiedLinkError:
/usr/lib/httpd/modules/libjkjni.so:
/usr/lib/libaprutil-0.so.0: undefined symbol: gdbm_errno
或者:
INFO: APR not loaded, disabling jni components: java.io.IOException: java.lang.UnsatisfiedLinkError:
/usr/lib/httpd/modules/libjkjni.so:
/usr/lib/httpd/modules/libjkjni.so: undefined symbol: apr_md5_final
#make
#libtool --finish /usr/lib/httpd/modules
#cp ../build/jk2/apache2/mod_jk2.so ../build/jk2/apache2/libjkjni.so /usr/lib/httpd/modules/
mod_jk安装完毕。
6、配置tomcat
#vi vi /usr/local/tomcat/bin/catalina.sh
# Get standard environment variables
PRGDIR=`dirname "$PRG"`
CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi
# 添加以下行
serverRoot=/etc/httpd
export serverRoot
#vi /usr/local/tomcat/conf/jk2.properties
handler.list=apr,request,channelJni
channelUnix.file=/usr/local/tomcat/work/jk2.socket
serverRoot=/etc/httpd
apr.NativeSo=/usr/lib/httpd/modules/libjkjni.so
#vi /usr/local/tomcat/conf/server.xml
在前加入
配置其它虚拟主机与此同。
7、设置虚拟主机
比如,我现在有虚拟主机 希望把jsp和servlet都转到tomcat去
在 /etc/httpd/conf/ 下面创建workers2.properties,内容如下:
[shm]
file=/var/log/httpd/shm.file
size=1048576
# Example socket channel, explicitly set port and host.
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1
# Example UNIX domain socket
[channel.un:/usr/local/tomcat/work/jk2.socket]
tomcatId=localhost:8009
debug=0
# define the worker
[ajp13:localhost:8009]
#channel=channel.un:/usr/local/tomcat/work/jk2.socket
# To use the TCP/IP socket instead, just comment out the above
# line, and uncomment the one below
channel=channel.socket:localhost:8009
# Announce a "status" worker
[status:status]
[uri:/status/*]
worker=status:status
# Uri mapping
[uri:/jsp-examples/*]
在/etc/httpd/conf/httpd.conf里面配置:
#tomcat
LoadModule jk2_module modules/mod_jk2.so
JkSet config.file /etc/httpd/conf/workers2.properties
#把下面这段放到VirtualHost之前,可以从全局避免用户用apache访问WEB-INF目录。
Order allow,deny
Deny from all
#典型的VirtualHost配置样本
NameVirtualHost 1.2.3.4 #(1.2.3.4你的服务器IP)
ServerName
DocumentRoot /var/www/abc
DirectoryIndex index.htm index.html default.htm index.php index.jsp
JkUriSet worker ajp13:localhost:8009
ErrorLog logs/
CustomLog logs/ common
这样就可以为每个不同的虚拟主机分别指定使用或者不使用jsp功能。
8、启动、测试
#service httpd start
#/usr/local/tomcat/bin/startup.sh
浏览器里输入
如果没有问题则说明安装成功。
欢迎与我交流
qq:138722
e-mail:xiaowei@beijingnet.com