配置Apache+tomcat

配置apache + tomcat

① 加载jkMount模块:

在 /etc/httpd/conf/httpd.conf中 LoadModule的地方 加上一句

LoadModule jk_module modules/mod_jk.so【可以从其他地方找这个模块】

②在 /etc/httpd/conf.d 下新建一个 mod_jk.conf 文件

JkWorkersFile /etc/httpd/conf/workers.properties
JkLogFile /website/logs/mod_jk.log
JkLogLevel warn
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /servlet/* work1
#JkMount /*.jsp work1

这样就完成 JKmount的配置

 

 

(一) 修改 /etc/httpd/conf.d/vhost.conf 这个是apache的重要配置文件。截图如下

#<VirtualHost *:80>
#        ServerName test.genomics.cn
#        DocumentRoot "/website/webApplications/Events"
#        DirectoryIndex index.jsp
#        JkMount /* work1
#        JkMount /*.do work1
#        JkUnMount /uploadfile/*   work1
#        ErrorLog logs/events-error_log
#        CustomLog logs/events-access_log common
#</VirtualHost>
<VirtualHost *:80>
        ServerName test.genomics.cn
        DocumentRoot "/website/webApplications/BGI"
        DirectoryIndex index.jsp
        JkMount /* work3
        JkMount /*.do work3
        ErrorLog logs/events-error_log
        CustomLog logs/events-access_log common
</VirtualHost>
Listen 9527
<VirtualHost *:9527>
        ServerName test.genomics.cn
        DocumentRoot "/website/webApplications/HIMS_Customer/customer"
        DirectoryIndex index.jsp
        JkMount /* work3
        JkMount /*.do work3
        ErrorLog logs/customer-error_log
        CustomLog logs/customer-access_log common
</VirtualHost>
<VirtualHost *:80>
        ServerName 192.168.224.85
        DocumentRoot "/website/webApplications/GeneBookHttps"
        <Directory /website/webApplications/GeneBookHttps>
           Order allow,deny
           Allow from all
        </Directory>
        DirectoryIndex index.jsp
        JkMount /* work5
        JkMount /*.do work5
        ErrorLog logs/GenebookHttps-error_log
        CustomLog logs/GenebookHttps-access_log common
</VirtualHost>

 

(二)

配置 apache 跟 tomcat 的交互转发

vim   /etc/httpd/conf/workers.properties


# Defining a worker named worker1 and of type ajp13
ps=/
worker.list=work1,work2,work3,work4,work5
# Set properties for TEST
worker.work1.type=ajp13
worker.work1.host=localhost
worker.work1.port=8009
worker.work1.lbfactor=1
#Set properties for BGI
worker.work2.type=ajp13
worker.work2.host=localhost
worker.work2.port=8010
worker.work2.lbfactor=1
#Set for customer
worker.work3.type=ajp13
worker.work3.host=localhost
worker.work3.port=8116
worker.work3.lbfactor=1
#Set for PgappWeb
worker.work4.type=ajp13
worker.work4.host=localhost
worker.work4.port=8011
worker.work4.lbfactor=1

#Set for GenebookHttps
worker.work5.type=ajp13
worker.work5.host=localhost
worker.work5.port=8060
worker.work5.lbfactor=1
可以配置转发多个 ajp13(apache跟tomcat通信的协议)协议的端口也就是多个  tomcat服务

 

(三)上面 8060端口配置必须和Tomcat 的 ajp1.3协议对应的端口一致

  vim $tomcat_home/conf/server.xml

 

 <!-- Define an AJP 1.3 Connector on port 8009 -->
  <Connector port="8060" protocol="AJP/1.3" redirectPort="8443" />
 这就是 Apache跟 tomcat通信(使用AJP/1.3协议)使用的自定义端口,也是平时开发中很少用到的端口。

其他两个端口分别是关闭的 shutdown端口,和Http协议端口。还有一个用的比较少的是Https的端口。

 

最后编辑Tomcat的配置文件server.xml,在HOST段中加入:
<Context path="" docBase="/var/wwwroot" 
      debug="0" reloadable="true" crossContext="true"/>

 

 

这样配置之后,可以直接地址栏输入ip地址,即可访问work5对应的项目。

附:机器配置

[**@template icon]$ uname -a
Linux template 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

 

 [**@template icon]$ cat /proc/version
Linux version 2.6.18-194.el5 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Mar 16 21:52:39 EDT 2010

 

 

 

============================================

以下是本人亲自实践的步骤:

cd /usr/local

cp /mnt/hgfs/Share/tomcat-connectors-1.2.37-src.tar.gz  ./

tar -zxvf tomcat-connectors-1.2.37-src.tar.gz

cd tomcat-connectors-1.2.37-src/native

 

apt-get install apache2-prefork-dev  anzhuang apxs2

where is apxs2  =========> /usr/lib/apxs2

./configure --with-apxs=/usr/lib/apxs2

make

make install

cp apache-2.0/mod_jk.so          /usr/lib/apache2/modules/

 后面步骤略,参见:http://www.cnblogs.com/buffer/archive/2009/12/20/1628375.html

 

[Mon May 19 21:56:50 2014] [notice] SIGHUP received.  Attempting to restart
[Mon May 19 21:56:50 2014] [notice] Apache/2.2.22 (Ubuntu) mod_jk/1.2.37 configured -- resuming normal operations

本来apache上面这样启动的时候,已经Ok了,但是结果不加端口(即默认使用80端口)怎么都转发不到tomcat上,网上搜了一个周,有的说加 tomcat_home ,有的说 加 java_home 等等,版本神马的,在我这都不好使,结果今天同事说可能是缓存,火狐的缓存全部清空,再访问,果然好了!!!!!!

真是被这个缓存害死。

 

负载均衡参见:http://xmong.iteye.com/blog/1288740#bc2302287

 

 

 

 

 

-------------------------------------

这样卸载就不会遇到烦人的 交互提问,直接卸载干净。

apt-get autoremove mysql-server-5.5

 

 

 

 

你可能感兴趣的:(apache,tomcat,linux,配掉tomcat端口)