多个项目,放在独立的tomcat上,并没有实现负载,要求实现静态化交给apache处理。
配置了3个tomcat通过jk和apache建立关系:
- tom1存放项目名:d1
- tom2存放项目名:news
- 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.propertiesjkworkersfile conf/workers2.properties# where to find uriworkermap.propertiesjkmountfile conf/uriworkermap-root.propertiesjkmountfile conf/uriworkermap-news.propertiesjkmountfile conf/uriworkermap-d1.properties# where to put jk logsjklogfile logs/mod_jk.log# set the jk log level [debug/error/info]jkloglevel info# select the log formatjklogstampformat "[%a %b %d %h:%m:%s %y] "# jkoptions indicate to send ssl key size,jkoptions +forwardkeysize +forwarduricompat -forwarddirectories# jkrequestlogformat set the request formatjkrequestlogformat "%w %v %t"#关掉主机lookup,如果为on,很影响性能,可以有10多秒钟的延迟。hostnamelookups off
workers2.properties
worker.list=root-loadbalancer,news-loadbalancer,d1-loadbalancer#主工程worker.root.type=ajp13worker.root.host=localhostworker.root.port=9009worker.root.lbfactor=1worker.root-loadbalancer.type=lbworker.root-loadbalancer.balance_workers=root#新闻工程(news)worker.news.type=ajp13worker.news.host=localhostworker.news.port=9019worker.news.lbfactor=1worker.news-loadbalancer.type=lbworker.news-loadbalancer.balance_workers=news#文件服务器工程(d1)worker.d1.type=ajp13worker.d1.host=localhostworker.d1.port=9029worker.d1.lbfactor=1worker.d1-loadbalancer.type=lbworker.d1-loadbalancer.balance_workers=d1worker.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] "d:\apache-tomcat-5.5.26-root\webapps\insurance"servername *.demo.comjkmountfile conf/uriworkermap-root.propertieserrorlog logs/demo-error.logcustomlog logs/demo-access.log commondirectoryindex 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] "d:\apache-tomcat-5.5.26-news\webapps\news"servername news.demo.comjkmountfile conf/uriworkermap-news.propertieserrorlog logs/news-error.logcustomlog logs/news-access.log commondirectoryindex 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] "d:\apache-tomcat-5.5.26-d1\webapps\d1"servername d1.demo.comjkmountfile conf/uriworkermap-d1.propertieserrorlog logs/d1-error.logcustomlog logs/d1-access.log commondirectoryindex 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