主要原理:通过一个RESIN配置多个WEB应用,实际上也就是利用resin做分发,分别将请求分发到RESIN配置的多个端口,(每一个端口类似另外启动一个RESIN).
我用的是resin-pro-3.0.22_bl
假设现在配置:一个web-a 作为转发服务,然后配置两个app-a.sh和app-b.sh
web-a.sh
./bin/httpd.sh -conf ./conf/WebA.conf -server web-a -Xmn100M -Xms312M -Xmx512M -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true
红色部分表示运行的文件,然后加载/conf/WebA.conf文件
app-a.sh
./bin/httpd.sh -conf ./conf/APP-tier_log.conf -server app-a -Xmn100M -Xms312M -Xmx512M -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m -Djava.awt.headless=true
红色加粗地方文件:
WebA.conf 系统的转发配置文件
<!--
- Resin 3.0 configuration file.
-->
<resin xmlns="http://caucho.com/ns/resin" xmlns:resin="http://caucho.com/ns/resin/core">
<log name="" path="stdout:" timestamp="[%H:%M:%S.%s] "/>
<logger name="com.caucho.java" level="config"/>
<logger name="com.caucho.loader" level="config"/>
<dependency-check-interval>2s</dependency-check-interval>
<javac compiler="internal" args=""/>
<thread-pool>
<thread-max>2024</thread-max>
<spare-thread-min>10</spare-thread-min>
</thread-pool>
<min-free-memory>1M</min-free-memory>
<server>
<class-loader>
<tree-loader path="${resin.home}/lib"/>
<tree-loader path="${server.root}/lib"/>
</class-loader>
<!-- Configures the keepalive -->
<keepalive-max>1500</keepalive-max>
<keepalive-timeout>120s</keepalive-timeout>
<select-manager enable="true"/>
<!-- listen to the http ports only after the server has started. -->
<bind-ports-after-start/>
<!-- The http port -->
<http id="web-a" port="80"/>
<!--该地方是配置将请求转发给下面配置的端口,一个端口类似启动一个RESIN服务器-->
<cluster id="app-tier">
<srun id="app-a" host='127.0.0.1' port='6808'/>
<srun id="app-b" host='127.0.0.1' port='6809'/>
<srun id="app-c" host='127.0.0.1' port='6810'/>
<srun id="app-d" host='127.0.0.1' port='6811'/>
<srun id="app-e" host='127.0.0.1' port='6812'/>
</cluster>
<ignore-client-disconnect>true</ignore-client-disconnect>
<cache path="cache" memory-size="118M"/>
<web-app-default>
<class-loader>
<tree-loader path="${server.root}/ext-webapp"/>
</class-loader>
<cache-mapping url-pattern="/" expires="5s"/>
<cache-mapping url-pattern="*.gif" expires="60s"/>
<cache-mapping url-pattern="*.jpg" expires="60s"/>
<allow-servlet-el/>
</web-app-default>
<host-default>
<!--配置的日志文件的路径-->
<access-log path="/usr/local/workspace/boss/web/access.log"
format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
rollover-period="1h"/>
<!--web-app-deploy path="webapps"/-->
<ear-deploy path="deploy">
<ear-default>
</ear-default>
</ear-deploy>
<resource-deploy path="deploy"/>
<web-app-deploy path="deploy"/>
</host-default>
<resin:import path="${resin.home}/conf/app-default.xml"/>
<host-deploy path="hosts">
<host-default>
<resin:import path="host.xml" optional="true"/>
</host-default>
</host-deploy>
<host id="">
<class-loader>
<compiling-loader path="/WEB-INF/classes"/>
<library-loader path="/WEB-INF/lib"/>
</class-loader>
<web-app id="">
<servlet>
<servlet-name>balance-a</servlet-name>
<servlet-class>com.caucho.servlets.LoadBalanceServlet</servlet-class>
<init cluster="app-tier"/>
</servlet>
<servlet-mapping url-pattern="/*" servlet-name="balance-a"/>
</web-app>
</host>
</server>
</resin>
以上除了红色部分,其他部分采用默认配置
App-tier_log.conf
<!--
- Resin 3.0 configuration file.
-->
<resin xmlns="http://caucho.com/ns/resin" xmlns:resin="http://caucho.com/ns/resin/core">
<log name="" path="stdout:" timestamp="[%H:%M:%S.%s] "/>
<logger name="com.caucho.java" level="config"/>
<logger name="com.caucho.loader" level="config"/>
<dependency-check-interval>2s</dependency-check-interval>
<javac compiler="internal" args=""/>
<thread-pool>
<thread-max>2024</thread-max>
<spare-thread-min>10</spare-thread-min>
</thread-pool>
<min-free-memory>1M</min-free-memory>
<server>
<class-loader>
<tree-loader path="${resin.home}/lib"/>
<tree-loader path="${server.root}/lib"/>
</class-loader>
<!-- Configures the keepalive -->
<keepalive-max>1500</keepalive-max>
<keepalive-timeout>120s</keepalive-timeout>
<select-manager enable="true"/>
<!-- listen to the http ports only after the server has started. -->
<bind-ports-after-start/>
<!-- The http port -->
<!--该部分对应的是app-a.sh中的 server后面的参数,表示匹配开启具体哪个应用-->
<cluster id="app-tier">
<srun id="app-a" host='127.0.0.1' port='6808'/>
<srun id="app-b" host='127.0.0.1' port='6809'/>
<srun id="app-c" host='127.0.0.1' port='6810'/>
<srun id="app-d" host='127.0.0.1' port='6811'/>
<srun id="app-e" host='127.0.0.1' port='6812'/>
</cluster>
<persistent-store type="cluster">
<init path="cluster"/>
</persistent-store>
<ignore-client-disconnect>true</ignore-client-disconnect>
<cache path="cache" memory-size="118M"/>
<web-app-default>
<class-loader>
<tree-loader path="${server.root}/ext-webapp"/>
</class-loader>
<cache-mapping url-pattern="/" expires="5s"/>
<cache-mapping url-pattern="*.gif" expires="60s"/>
<cache-mapping url-pattern="*.jpg" expires="60s"/>
<allow-servlet-el/>
<session-config>
<!--enable-url-rewriting>false</enable-url-rewriting-->
<!--use-persistent-store/-->
<!--always-save-session/-->
<session-max>4096</session-max>
<session-timeout>300</session-timeout>
<enable-cookies>true</enable-cookies>
<enable-url-rewriting>true</enable-url-rewriting>
<use-persistent-store>WEB-INF/sessions</use-persistent-store>
</session-config>
</web-app-default>
<!--访问日志文件信息-->
<host-default>
<access-log path="/usr/local/workspace/boss/web/access.log"
format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
rollover-period="1h"/>
<!--web-app-deploy path="webapps"/-->
<ear-deploy path="deploy">
<ear-default>
</ear-default>
</ear-deploy>
<resource-deploy path="deploy"/>
<web-app-deploy path="deploy"/>
</host-default>
<resin:import path="${resin.home}/conf/app-default.xml"/>
<host-deploy path="hosts">
<host-default>
<resin:import path="host.xml" optional="true"/>
</host-default>
</host-deploy>
<!--项目应用目录文件-->
<host id="" root-directory="/usr/local/workspace/boss/web">
<!--控制台访问文件信息-->
<stderr-log path='/usr/local/workspace/boss/web/stderr.log'
rollover-period='1h'/>
<class-loader>
<compiling-loader path="/WEB-INF/classes"/>
<library-loader path="/WEB-INF/lib"/>
</class-loader>
<web-app id="/">
<security-constraint>
<web-resource-collection>
<url-pattern>/bulletin/leftpicture/*</url-pattern>
</web-resource-collection>
<ip-constraint>
<deny>192.168.63.133</deny>
</ip-constraint>
</security-constraint>
</web-app>
<web-app id="/Upload" document-directory="/data1/webFiles/bossSite_Common" />
<resin:if test="${java.isJava5()}">
<resin:set var="resin_admin_password" value=""/>
<resin:set var="resin_admin_localhost" default="false"/>
<web-app id="/resin-admin" document-directory="${resin.home}/php/admin"/>
</resin:if>
</host>
</server>
</resin>
启动方式:
我的resin路径:usr:/resin-pro-3.0.22_bl
root$:cd usr:/resin-pro-3.0.22_bl/
root$:./web-a.sh
然后启动
root$:./app-a.sh
root$:./app-b.sh
然后就可以开始访问你的WEB页面了