配置环境:
OS:RHEL5withkernel2.6.18-8.1.1.el5
httpd-2.2.3-6.el5.i386.rpm
apache-tomcat-6.0.14.tar.gz
jdk-6u3-linux-i586.bin
mod_jk-1.2.23-apache-2.2.x-linux-i686.so
官方宣称mod_jk-1.2.26-httpd-2.2.6.so支持Apache2.2.x及2.2.6以后的版本,但经实验,1.2.26的mod_jk在RHEL5中会报错。
下载地址:
http://java.sun.com/javase/downloads/index.jsp
http://www.apache.org/dist/tomcat/tomcat-connectors
http://apache.mirror.phpchina.com/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.23/
一、安装配置jdk及tomcat
1、安装jdk及tomcat
[root@wardking~]#tarzxvfapache-tomcat-6.0.14.tar.gz-C/usr/local/
[root@wardking~]#mvjdk-6u3-linux-i586.bin/usr/local/
[root@wardking~]#cd/usr/local
[root@wardkinglocal]#chmoda+xjdk-6u3-linux-i586.bin
[root@wardkinglocal]#./jdk-6u3-linux-i586.bin
2、配置环境变量
[root@wardking~]#ln-sf/usr/local/apache-tomcat-6.0.14/usr/local/tomcat
[root@wardking~]#ln-sf/usr/local/jdk1.6.0_03/usr/local/jdk6
[root@wardking~]#ln-sf/usr/local/jdk6/bin/java/usr/bin/
[root@wardking~]#ln-sf/usr/local/tomcat/bin/startup.sh/usr/bin/tomcat-up
[root@wardking~]#ln-sf/usr/local/tomcat/bin/shutdown.sh/usr/bin/tomcat-down
添加一个名为michael的管理员用户
[root@wardking~]#vi/usr/local/tomcat/conf/tomcat-users.xml
设置环境变量
[root@wardking~]#vi/etc/profile
JAVA_HOME=/usr/local/jdk6
CATALINA_HOME=/usr/local/tomcat
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar
PATH=$JAVA_HOME/bin:$PATH
exportJAVA_HOMECATALINA_HOMECLASSPATHPATH
[root@wardking~]#source/etc/profile
3、测试tomcat服务
[root@wardking~]#/usr/bin/tomcat-up
或者直接执行
/usr/local/tomcat/bin/startup.sh
检查tomcat是否启动
[root@wardking~]#netstat-anp|grep8080
在浏览器里访问http://localhost:8080/,可以看到tomcat的网页界面,并可以使用
用户michael登陆管理
停止tomcat服务
[root@wardking~]#tomcat-down
二、连接tomcat到apache
1、安装mod_jk模块
[root@wardking~]#cpmod_jk-1.2.23-apache-2.2.x-linux-i686.so/etc/httpd/modules/
2、修改apache配置文件
[root@wardking~]#vi/etc/httpd/conf.d/mod_jk.conf
LoadModulejk_modulemodules/mod_jk-1.2.23-apache-2.2.x-linux-i686.so
JkWorkersFile"/etc/httpd/conf/workers.properties"
JkShmFile/var/log/httpd/mod_jk.shm
JkLogFile"/var/log/httpd/mod_jk.log"
JkLogLevelinfo
JkMount/*/servlet/*ajp13
JkMount/*.jspajp13
JkMount/*.doajp13
AddTypeapplication/x-jsp.jsp
3、添加tomcat配置文件
[root@wardking~]#vi/etc/httpd/conf/workers.properties
[shm]
file=/etc/httpd/logs/shm.file
size=1048576
[channel.socket:localhost:8009]
tomcatId=localhost:8009
[uri:/jsp-examples/*]
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/jdk6
ps=\
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
4、设置tomcat主目录
[root@wardking~]#vi/usr/local/tomcat/conf/server.xml
unpackWARs="true"autoDeploy="true"
xmlValidation="false"xmlNamespaceAware="false">
5、确认apache、tomcat启动
[root@wardking~]#httpd-t
[root@wardking~]#servicehttpdrestart
[root@wardking~]#/usr/bin/tomcat-up
6、分别测试访问php和jsp网页
[root@wardking~]#vi/var/www/html/showtime.jsp
<%@pagelanguage="java"import="java.util.*"%>
NowTimeis:<%out.println(newDate());%>
[root@wardking~]#echo''>phpinfo.php
在浏览器中访问http://localhost/showtime.jsp,应在网页中显示系统时间
访问http://localhost/phpinfo.php,显示php及服务器相关配置信息
另一种整合办法,在httpd.conf中使用反向代理:
ProxyPass/images!
ProxyPass/icons!
ProxyPass/ajp://127.0.0.1:8009/
ProxyPassReverse/ajp://127.0.0.1:8009/