在Linux系统中Apache与Tomcat的整合
2007-09-28 kenthy#qingdaonews.com
#################################################################################
系统环境:Red Hat Enterprise Linux Server release 5 (kernel 2.6.18-8.el5xen)
软件环境:
httpd-2.2.3-6.el5.i386.rpm
apache-tomcat-6.0.14.tar.gz
jdk-6u2-linux-i586.bin
mod_jk-1.2.25-httpd-2.2.4.so
——参考下载地址:
目标功能:
将tomcat整合到apache服务器中,当通过apache访问.jsp文件时自动调用tomcat解释执行。
#################################################################################
注:为简单起见,httpd使用RHEL5系统自带的软件包,并基于默认配置。关于LAMP的整合安装请参考其它资料。
一、安装配置jdk及tomcat
1、安装jdk及tomcat
# tar zxvf apache-tomcat-6.0.14.tar.gz -C /usr/local/
# mv jdk-6u2-linux-i586.bin /usr/local/
# cd /usr/local
# chmod a+x jdk-6u2-linux-i586.bin
# ./jdk-6u2-linux-i586.bin
2、配置环境变量
# ln -sf /usr/local/apache-tomcat-6.0.14 /usr/local/tomcat
# ln -sf /usr/local/jdk1.6.0_02 /usr/local/jdk6
# ln -sf /usr/local/jdk6/bin/java /usr/bin/
# ln -sf /usr/local/tomcat/bin/startup.sh /usr/bin/tomcat-up
# ln -sf /usr/local/tomcat/bin/shutdown.sh /usr/bin/tomcat-down
# vi /usr/local/tomcat/conf/tomcat-users.xml //添加一个名为“zhangsan”的管理员用户
# 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
export JAVA_HOME CATALINA_HOME CLASSPATH PATH
# logout //注销后重新登陆,以便环境变量生效
3、测试tomcat服务
# /usr/bin/tomcat-up //或者直接执行/usr/local/tomcat/bin/startup.sh
# netstat -anp | grep :8080 //检查tomcat是否启动
在浏览器里访问,应能看到tomcat的网页界面,并可以使用用户“zhangsan”登陆管理
# tomcat-down //使用关闭脚本可以停止tomcat服务
二、连接tomcat到apache
1、安装mod_jk模块
# cp mod_jk-1.2.25-httpd-2.2.4.so /etc/httpd/modules/ //将模块文件放置到apache的模块目录
2、修改apache配置文件
# cd /etc/httpd/conf/
# cp -pf httpd.conf httpd.conf.bak
# vi httpd.conf
LoadModule jk_module modules/mod_jk-1.2.25-httpd-2.2.4.so
JkWorkersFile "/usr/local/tomcat/conf/workers.properties"
JkLogFile "/usr/local/tomcat/logs/mod_jk2.log"
JkLogLevel info
JkMount /*/servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /*.do ajp13
AddType application/x-jsp .jsp
3、添加tomcat配置文件
# vi /usr/local/tomcat/conf/workers.properties
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、确认apache、tomcat启动
# /usr/sbin/apachectl -t //对httpd.conf配置文件作语法检查
# service httpd restart
# /usr/bin/tomcat-up
5、测试访问.jsp网页
# vi /var/www/html/showtime.jsp //创建简单的jsp测试页面
< language="java" import="java.util.*"%>
Now Time is : <% out.println(new Date()); %>
在浏览器中访问,应在网页中显示系统时间
阅读(1916) | 评论(0) | 转发(1) |