apache和tomcat整合
第一种方法
第一步,安装Apache2(略)
第二步,安装Java--jdk1.5(略)
第三步,安装Tomcat(略)
第四步,安装apache tomcat连接器
4.1 解压
# tar -xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz
# cd jakarta-tomcat-connectors-1.2.15/jk/native/
4.2 配置
# ./configure --with-apxs=/usr/local/apache/bin/apxs --with-apr-lib=/usr/local/apache/bin
4.3 编译,安装
# make&&make install
4.4 验证mod_jk.so模块是否编译成功
# cd apache-2.0/
# ls //有mod_jk.so模块,说明编译已经成功
# ls /usr/local/apache/modules //有mod_jk.so模块,说明编译已经成功
第五步,整合Tomcat和Apache
5.1 配置apache目录的文件
# cd /usr/local/apache/conf
5.2.1 新建mod_jk.conf
[root@feilin conf]# vi mod_jk.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkMount /*.jsp controller
JkMount /*.js controller
5.2.2 新建workers.properties
[root@feilin conf]# vi workers.properties
worker.list=controller,tomcat1,tomcat2,tomcat3
#============tomcat1================
worker.tomcat1.port=8019
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
#============tomcat2=================
#worker.tomcat2.port=8029
#worker.tomcat2.host=localhost
#worker.tomcat2.type=ajp13
#worker.tomcat2.lbfactor=1
#============tomcat8=================
#worker.tomcat3.port=8039
#worker.tomcat3.host=localhost
#worker.tomcat3.type=ajp13
#worker.tomcat3.lbfactor=1
#============controller================
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1
worker.controller.sticky_session=1
5.2.3 新建uriworkermap.properties
vi uriworkermap.properties
/*=controller
/jkstatus=status
!/*.gif=controller
!/*.jpg=controller
!/*.png=controller
!/*.css=controller
!/*.js=controller
!/*.htm=controller
!/*.html=controller
5.2.4 在apache中增加对mod_jk的装载
# vi /usr/local/apache/conf/httpd.conf
Include conf/mod_jk.conf
5.2.5 修改/usr/local/apache/conf/httpd.conf
<Directory "/">
Options Includes FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
XBitHack on
</Directory>
5.2.6 修改tomcat的server.xml
a.修改相关端口
b.添加虚拟主机:<Host name="域名" appBase="项目目录" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
第二种方法(不适用apache2.0)
apache2.2与tomcat整合方法
1.修改apache中的配置文件:http.conf
打开所有的代理服务:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8009/ loadfactor=1 route=jvm1
</proxy>
在apache中的虚拟主机中配置
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster
2.修改tomcat的配置及端口,并打开群集配置项及端口!
|