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 /webserver/ ajp13 (应用为webserver)
为了以后配置域名方便,我们在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>
serveradminservice hingesoft.com.cn
servernamewww.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>
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