思科技术论坛's Archiver
思科技术论坛 » web服务器 » apache2.0和tomcat的整合无忧 发表于 2009-4-19 19:53
apache2.0和tomcat的整合
Linux下apache2.0和tomcat的整合
1.所需软件
Apache安装程序:httpd-2.0.63.tar.gz
Tomcat5安装程序:apache-tomcat-5.5.23.tar.gz
JDK安装程序:JDK 6.bin
(上传安装文件到/usr/local/下)
2.安装JDK
1).安装JDK
# cd /usr/local/
# chmod +x jdk6.bin
# ./jdk6.bin
出现问题输入:Y确定
2).jdk默认安装在/usr/local/jdk1.6.0_01目录下
用mv命令把jdk1.6.0_01 给它改个名字叫jdk6
3). 开始设置环境变量
vi /etc/profile.d/java.sh
在profile.d/java.sh 文件的最后添加如下代码
#set java environment
JAVA_HOME=/usr/local/jdk6
export JAVA_HOME
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export CLASSPATH
PATH=$PATH:$JAVA_HOME/bin
export PATH
保存退出
使变量生效source ./profile.d/java.sh
4).检查是否安装成功
命令java -version
如果安装成功会出现java的版本信息
3.安装Apache(下载地址
http://apache.justdn.org/httpd/)
# cd /usr/local/
# tar xvfz httpd-2.0.63.tar.gz
# cd httpd-2.0.63
# ./configure --prefix=/usr/local/apache --enable-module=so
(备注:prefix定义apache的安装路径)
# make
# make install
# cd /usr/local/apache/conf
# vi ./httpd.conf
将ServerName 修改为ServerName LocalHost:80 (291行)
在DirectoryIndex中添加 index.jsp (394行)
# cd /usr/local/apache/bin/
# ./apachectl configtest
显示Syntax ok则表明安装成功
#./apachectl start
在地址栏输入http://ip地址 看到欢迎界面,表示安装成功
# ./apachectl stop
关闭服务
4.安装Tomcat
# cd /usr/local/
# tar xvfz jakarta-tomcat-5.5.23.tar.gz
# cd /usr/local/tomcat/bin/
#./startup.sh 启动tomcat
在地址栏输入http://ip:8080就可以看见熟悉的大猫了,表示安装成功
# ./usr/local/tomcat/bin/shutdown.sh 关闭tomcat
5.安装JK(如果有mod_jk.so文件,就不需要安装JK)
# cd /usr/local/
# tar xzvf jakarta-tomcat-connectors-1.2.14-src.tar.gz
# cd jakarta-tomcat-connectors-1.2.14-src/jk/native
# chmod 755 buildconf.sh
# ./buildconf.sh
# ./configure --with-apxs=/usr/local/apache/bin/apxs
# make
# make install
#cd /usr/local/jakarta-tomcat-connectors-jk1.2.14-src/jk/native/apache-2.0/
# cp mod_jk.so /usr/local/apache/modules/
6.Apache2.0与Tomcat的整合
1).# vi /usr/local/apache/conf/httpd.conf
在文件最末尾加上如下语句
#Load mod_jk
LoadModule jk_module modules/mod_jk.so
# Configure mod_jk
JkWorkersFile tomcat安装目录/conf/workers.properties
JkLogFile tomcat安装目录/logs/mod_jk.log
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /hzcms/* ajp13 (应用为hzcms)
为了以后配置域名方便,我们在Apache安装目录/conf/httpd.conf文件末尾加上:
include "tomcat安装目录/web/cmsdomain.conf"
2).新建workers.properties文件
在tomcat安装目录/conf下新建workers.properties文件,对其内容为(根据实际环境进行修改,包括Tomcat目录,JDK目录,ajp端口等):
#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
# Tomcat安装目录,例如/usr/local/tomcat
workers.tomcat_home=/usr/local/tomcat
#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
# JDK安装目录,例如/usr/local/jdk1.6
workers.java_home=/usr/local/jdk1.6
#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=\
# Define 1 real worker using ajp13
worker.list=ajp13
# Set properties for worker1 (ajp13)
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300
3).解决常见问题
下面接着解决Apache与Tomcat整合之后的常见问题:
apache与tomcat整合后经常出现以下错误:
connection timeout reached
这需要修改server.xml文件的一个参数值,在<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->注释下的<Connector>标签中修改connectionTimeout=-1就能解决联接超时的问题。
解决java.lang.IllegalStateException: Post too large错误,这是由于tomcat默认只能传递2M大小的内容,在<!-- Define a non-SSL Coyote HTTP/1.1 Connector on the port specified during installation -->以及<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->的Connector标签中都加上maxPostSize="0"即可,表示不限制大小。同时在这两个标签里都加上URIEncoding="GBK",可以解决常见的传递中文问题。
则修改后的两个标签分别为:
<Connector port="8080" maxPostSize="0" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="-1" disableUploadTimeout="true" URIEncoding="GBK" />
<Connector port="8009" maxPostSize="0" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" connectionTimeout="-1" URIEncoding="GBK"/>
4).配置域名
最后我们在Tomcat安装目录中的web(存放静态网页的目录)文件夹下创建域名配置文件:cmsdomain.conf,其内容为(根据实际环境进行修改):
NameVirtualHost *:80
#软件
<VirtualHost *:80>
ServerAdmin [email]
[email protected][/email]
ServerName
www.hingesoft.com.cn
DocumentRoot D:/Apache/Tomcat5/web
DirectoryIndex hingesoft.htm
ErrorLog logs/www.hingesoft.com.cn-error_log
CustomLog logs/www.hingesoft.com.cn-access_log common
</VirtualHost>
# 教育部科技发展中心
<VirtualHost *:80>
ServerAdmin [email]
[email protected][/email]
ServerName
www.cutech.edu.cn
DocumentRoot D:/Apache/Tomcat5/web
DirectoryIndex cn.htm
ErrorLog logs/www.cutech.edu.cn-error_log
CustomLog logs/www.cutech.edu.cn-access_log common
</VirtualHost>
7.测试整合是否成功
最后我们来测试Apache与Tomcat整合部署是否成功,先启动Apache服务器再启动Tomcat服务器。在浏览器里输入http://localhost,如果看到的界面与http://localhost:8080的界面相同,表明整合部署成功。
8.设置自启动
以便系统启动后开启apache,tomcat服务
将如下内容添加至/etc/rc.d/rc.local文件末尾
#vi /etc/rc.d/rc.local
修改/etc/rc.d/rc.local文件,添加以下内容:
export JDK_HOME=/usr/local/jdk6
export JAVA_HOME=/usr/local/jdk6
/usr/local/tomcat/bin/startup.sh
/usr/local/apache/bin/apachectl start
页: [1] 查看完整版本: apache2.0和tomcat的整合
Powered by Discuz! Archiver 6.1.0 © 2001-2007 Comsenz Inc.