多个tomcat同一个apache,使用jk建立关系时常出错!

多个项目,放在独立的tomcat上,并没有实现负载,要求实现静态化交给apache处理。

配置了3个tomcat通过jk和apache建立关系:

  1. tom1存放项目名:d1
  2. tom2存放项目名:news
  3. tom3存放项目名:root


环境:(一台win2003服务器,,zip版本5.5.26的tomcat装了3个,,jk是1.2.26的,apache2.2.×)

我的实现方式:

每个tomcat根目录下写个bat脚本,用于同一个机器上启动多个tomcat

D:\Program\Tomcat5.5.26\startup_proname.bat

set CATALINA_HOME=D:\Program\Tomcat5.5.26
bin/startup.bat
(此处只写一个tomcat的配置server.xml就不多说了,其他的也如此)

贴出我的配置文件,一共5个:
  • mod_jk.conf
  • workers2.properties
  • uriworkermap-d1.properties
  • uriworkermap-news.properties
  • uriworkermap-root.properties 
  • httpd-vhosts.conf



mod_jk.conf

# Load mod_jk module. Specify the filename
# of the mod_jk lib you’ve downloaded and
# installed in the previous section

#加载mod_jk模块
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers2.properties

# Where to find uriworkermap.properties
JkMountFile conf/uriworkermap-root.properties
JkMountFile conf/uriworkermap-news.properties
JkMountFile conf/uriworkermap-d1.properties

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

#关掉主机Lookup,如果为on,很影响性能,可以有10多秒钟的延迟。
HostnameLookups Off

workers2.properties

worker.list=root-loadbalancer,news-loadbalancer,d1-loadbalancer

#主工程
worker.root.type=ajp13
worker.root.host=localhost
worker.root.port=9009
worker.root.lbfactor=1

worker.root-loadbalancer.type=lb
worker.root-loadbalancer.balance_workers=root

#新闻工程(news)
worker.news.type=ajp13
worker.news.host=localhost
worker.news.port=9019
worker.news.lbfactor=1

worker.news-loadbalancer.type=lb
worker.news-loadbalancer.balance_workers=news

#文件服务器工程(d1)
worker.d1.type=ajp13
worker.d1.host=localhost
worker.d1.port=9029
worker.d1.lbfactor=1

worker.d1-loadbalancer.type=lb
worker.d1-loadbalancer.balance_workers=d1

worker.status.type=status

uriworkermap-d1.properties

/*=d1-loadbalancer

!/*.gif=d1-loadbalancer
!/*.jpg=d1-loadbalancer
!/*.png=d1-loadbalancer
!/*.css=d1-loadbalancer
!/*.js=d1-loadbalancer
!/*.htm=d1-loadbalancer
!/*.html=d1-loadbalancer

uriworkermap-news.properties

/*=news-loadbalancer

!/*.gif=news-loadbalancer
!/*.jpg=news-loadbalancer
!/*.png=news-loadbalancer
!/*.css=news-loadbalancer
!/*.js=news-loadbalancer
!/*.htm=news-loadbalancer
!/*.html=news-loadbalancer

uriworkermap-root.properties

/*=root-loadbalancer

!/*.gif=root-loadbalancer
!/*.jpg=root-loadbalancer
!/*.png=root-loadbalancer
!/*.css=root-loadbalancer
!/*.js=root-loadbalancer
!/*.htm=root-loadbalancer
!/*.html=root-loadbalancer


httpd-vhosts.conf

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

#网站主工程
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:\apache-tomcat-5.5.26-root\webapps\insurance"
ServerName *.demo.com
JkMountFile conf/uriworkermap-root.properties
ErrorLog logs/demo-error.log
CustomLog logs/demo-access.log common
DirectoryIndex index.jsp

    <Directory "D:\apache-tomcat-5.5.26-root\webapps\insurance">
        Options FollowSymLinks
        AllowOverride None
        order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_rewrite.c>

        Rewriteengine on

        #配置满足什么条件进行重写
        RewriteCond %{HTTP_HOST} ^[a-z0-9\-]+\.demo\.com$
        RewriteCond %{HTTP_HOST} !^www.demo.com
        RewriteCond %{HTTP_HOST} !^bbs.demo.com
	RewriteCond %{HTTP_HOST} !^d1.demo.com
	RewriteCond %{HTTP_HOST} !^news.demo.com
	RewriteCond %{REQUEST_URI} !(\.css|\.js|\.jpg|\.gif|\.png|\.html|\.htm)$

        RewriteRule ^/(.*)$ /%{HTTP_HOST}/$1

	#网站后台进行二级域名解析
	RewriteRule ^/manage\.demo\.com/?$ /panel/login.do [L,PT]

	#频道的首页进行二级域名解析
	RewriteRule ^/zx\.demo\.com/?$ /advisory/index.do [L,PT]
	RewriteRule ^/bid\.demo\.com/?$ /bid/bid_index.do [L,PT]
	RewriteRule ^/job\.demo\.com/?$ /job/job_index.do [L,PT]
	RewriteRule ^/download\.demo\.com/?$ /download/downloadIndex.do [L,PT]
	RewriteRule ^/ts\.demo\.com/?$ /complain/complain_index.do [L,PT]
	RewriteRule ^/video\.demo\.com/?$ /shipin/videoIndex.do [L,PT]
	RewriteRule ^/yellow\.demo\.com/?$ /yellow/yellow_index.do [L,PT]
	RewriteRule ^/fun\.demo\.com/?$ /fun/index.do [L,PT]

        #空间会员进行泛域名解析
	RewriteRule ^/([a-z0-9\-]+)\.demo\.com/?$ /space/index.do?SLD=$1 [L,PT]
    RewriteRule ^/([a-z0-9\-]+)\.demo\.com/space(/(.*))*$ /space/$2?SLD=$1&%{QUERY_STRING} [L,PT]
    </IfModule> 

</VirtualHost>


#保险新闻工程
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:\apache-tomcat-5.5.26-news\webapps\news"
ServerName news.demo.com
JkMountFile conf/uriworkermap-news.properties
ErrorLog logs/news-error.log
CustomLog logs/news-access.log common
DirectoryIndex index.jsp

    <Directory "D:\apache-tomcat-5.5.26-news\webapps\news">
        Options FollowSymLinks
        AllowOverride None
        order allow,deny
        Allow from all
    </Directory>

</VirtualHost>


#文件服务器工程
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:\apache-tomcat-5.5.26-d1\webapps\d1"
ServerName d1.demo.com
JkMountFile conf/uriworkermap-d1.properties
ErrorLog logs/d1-error.log
CustomLog logs/d1-access.log common
DirectoryIndex index.jsp

    <Directory "D:\apache-tomcat-5.5.26-d1\webapps\d1">
        Options FollowSymLinks
        AllowOverride None
        order allow,deny
        Allow from all
    </Directory>

</VirtualHost>



最后一个配置了,强调:我这里是3个项目分别用了3个tomcat,主要工程root实现了二级域名,其他两个功能有相应的域名

现在运行了2,3天时间发现偶尔会有异常,打不开现象,重启下影响不大,不过不知道原因很痛苦!

tomcat日志:

2008-10-28 13:18:59 org.apache.jasper.compiler.TldLocationsCache processWebDotXml
警告: Internal Error: File /WEB-INF/web.xml not found
2008-10-28 13:50:22 org.apache.jk.core.MsgContext action
警告: Error sending end packet
java.net.SocketException: Software caused connection abort: socket write error

你可能感兴趣的:(apache,tomcat,jsp,css,Access)