Resin集群实现

Resin集群实现  

Resin集群实现

一、前言

平台在线用户已达22万,在线会员达8000。系统负载严重,需要利用集群进行负载均衡。

二、环境

a)         resin 版本 3.1.5

b)        三台linux服务器,ip分别为192.168.1.2、192.168.1.3、192.168.1.4

由于服务器有限,故在proxy主机上多配置一个app,分担负载。

 

一、配置文件

由于resin修改配置文件时,resin会自动重启,所以必需为每个app配置一个conf文件。

a)         Proxy主机配置文件

<resin xmlns="http://caucho.com/ns/resin"

       xmlns:resin="http://caucho.com/ns/resin/core">

 

  <class-loader>

    <tree-loader path="${resin.home}/ext-lib"/>

    <tree-loader path="${resin.root}/ext-lib"/>

 

    <tree-loader path="${resin.home}/lib"/>

    <tree-loader path="${resin.root}/lib"/>

  </class-loader>

 

  <management path="${resin.root}/admin">

<user name="admin" password="AaEoRi2XDPUstNgJdOEAqA==" disable="false"/>

    <resin:if test="${resin.professional}">

      <deploy-service enable="true"/>

      <jmx-service enable="true"/>

      <log-service enable="true"/>

      <xa-log-service enable="true"/>

    </resin:if>

  </management>

 

  <log name="" level="info" path="/var/log/resin/log/stdout_main.log"

       timestamp="[%Y-%m-%d %H:%M:%S.%s] {%{thread}} "/>

  <logger name="com.caucho" level="info"/>

 

  <logger name="com.caucho.java" level="config"/>

  <logger name="com.caucho.loader" level="config"/>

 

  <dependency-check-interval>2s</dependency-check-interval>

 

  <system-property mail.smtp.host="127.0.0.1"/>

  <system-property mail.smtp.port="25"/>

 

  <javac compiler="internal" args="-source 1.5"/>

 

  <cluster id="app-tier">

 

    <root-directory>.</root-directory>

 

    <server-default>

 

              <jvm-arg>-server</jvm-arg>

              <jvm-arg>-d64</jvm-arg>

              <jvm-arg>-Xmx3072m</jvm-arg>

              <jvm-arg>-Xms3072m</jvm-arg>

              <jvm-arg>-Xss128k</jvm-arg>

              <jvm-arg>-verbose:gc</jvm-arg>

 

              <jvm-arg>-Xmanagement</jvm-arg>

              <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

 

              <jvm-arg>-agentlib:resin</jvm-arg>

 

      <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>

      <watchdog-port>6600</watchdog-port>

 

 

      <memory-free-min>256k</memory-free-min>

 

      <thread-max>4096</thread-max>

 

 

      <socket-timeout>90s</socket-timeout>

 

 

      <keepalive-max>8912</keepalive-max>

      <keepalive-timeout>15s</keepalive-timeout>

 

      <keepalive-select-max>8912</keepalive-select-max>

 

    </server-default>

 

    <server id="app-002" address="192.168.1.2" port="6800">

        <load-balance-weight>2</load-balance-weight>

    </server>

    <server id="app-003" address="192.168.1.3" port="6800">

        <load-balance-weight>6</load-balance-weight>

    </server>

    <server id="app-004" address="192.168.1.4" port="6801">

        <load-balance-weight>5</load-balance-weight>

    </server>

 

      <persistent-store type="cluster">

        <init path="/cluster/resin/session"/>

      </persistent-store>

    <resin:if test="${resin.professional}">

      <cache path="cache" memory-size="64M">

        <!-- Vary header rewriting for IE -->

        <rewrite-vary-as-private/>

      </cache>

    </resin:if>

 

    <resin:if test="${resin.professional}">

      <ping resin:type="com.caucho.server.admin.PingMailer">

        <url>http://www.1363.cn</url>

              <mail-to>13928189263@139.com</mail-to>

              <mail-from>admin@1363.cn</mail-from>

              <mail-subject>Resin ping has faild for server.</mail-subject>

      </ping>

    </resin:if>

 

    <web-app-default>

      <prologue>

 

        <class-loader>

          <tree-loader path="${resin.root}/ext-webapp-lib"/>

        </class-loader>

 

        <allow-servlet-el/>

      </prologue>

     

      <cache-mapping url-pattern="/" expires="5s"/>

         <cache-mapping url-pattern="*.html" expires="180s"/>

      <cache-mapping url-pattern="*.gif" expires="600s"/>

      <cache-mapping url-pattern="*.jpg" expires="600s"/>

      <cache-mapping url-pattern="*.png" expires="600s"/>

         <cache-mapping url-pattern="*.swf" expires="600s"/>

 

      <session-config>

           <session-timeout>15</session-timeout>

              <session-max>40960</session-max>

        <enable-url-rewriting>false</enable-url-rewriting>

         <use-persistent-store/>

      </session-config>

 

        <jsp>

          <validate-taglib-schema>true</validate-taglib-schema>

          <fast-jstl>true</fast-jstl>

          <fast-jsf>true</fast-jsf>

        </jsp>

    </web-app-default>

 

 

    <resin:import path="${resin.home}/conf/app-default.xml"/>

 

 

    <host-default>

 

       <class-loader>

              <compiling-loader path="WEB-INF/classes"/>

              <library-loader path="/home1/lib"/>

       </class-loader>

 

      <web-app-deploy path="webapps"/>

 

      <ear-deploy path="deploy">

        <ear-default>

          <ejb-server>

            <config-directory>WEB-INF</config-directory>

            <data-source>jdbc/test</data-source>

          </ejb-server>

        </ear-default>

      </ear-deploy>

 

 

      <resource-deploy path="deploy"/>

    </host-default>

 

    <host-deploy path="hosts">

      <host-default>

        <resin:import path="host.xml" optional="true"/>

      </host-default>

    </host-deploy>

 

  </cluster>

 

    <cluster id="web-tier">

      <server-default>

        <http address="*" port="80" connection-max="8192"/>

                <jvm-arg>-server</jvm-arg>

                <jvm-arg>-d64</jvm-arg>

                <jvm-arg>-Xmx3072m</jvm-arg>

                <jvm-arg>-Xms3072m</jvm-arg>

                <jvm-arg>-Xss128k</jvm-arg>

                <jvm-arg>-verbose:gc</jvm-arg>

              <jvm-arg>-Xmanagement</jvm-arg>

                <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

    <jvm-arg>-Dcom.sun.management.jmxremote.port=9991</jvm-arg>

    <jvm-arg>-Dcom.sun.management.jmxremote.ssl=false</jvm-arg>

    <jvm-arg>-Dcom.sun.management.jmxremote.authenticate=true</jvm-arg>

                <jvm-arg>-agentlib:resin</jvm-arg>

 

      <memory-free-min>256k</memory-free-min>

 

      <thread-max>8192</thread-max>

 

      <socket-timeout>90s</socket-timeout>

 

      <keepalive-max>8192</keepalive-max>

      <keepalive-timeout>15s</keepalive-timeout>

       <keepalive-select-max>8192</keepalive-select-max>

 

       </server-default>

      <persistent-store type="cluster">

        <init path="session"/>

      </persistent-store>

 

<web-app-default>

      <cache-mapping url-pattern="/" expires="50s"/>

      <cache-mapping url-pattern="*.gif" expires="600s"/>

      <cache-mapping url-pattern="*.jpg" expires="600s"/>

      <cache-mapping url-pattern="*.png" expires="600s"/>

      <session-config>

         <use-persistent-store/>

           <session-timeout>15</session-timeout>

              <session-max>40960</session-max> 

        <enable-url-rewriting>false</enable-url-rewriting>

      </session-config>

        <jsp>

          <validate-taglib-schema>true</validate-taglib-schema>

          <fast-jstl>true</fast-jstl>

          <fast-jsf>true</fast-jsf>

        </jsp>

    </web-app-default>

       <server id="web-a" address="192.168.1.2"  port="6700"/>

 

      <cache path="cache" memory-size="1024M"/>

 

      <host id="" root-directory=".">

        <web-app id="/" root-directory="/home1/web/default/">

           <rewrite-dispatch>

             <load-balance regexp="" cluster="app-tier"/>

           </rewrite-dispatch>

        </web-app>

      </host>

 

 

      <host id="1363.cn" root-directory=".">

         <host-alias-regexp>([a-zA-Z0-9.]+).1363.cn</host-alias-regexp>

         <host-name>${host-alias-regexp.regexp[1]}.1363.cn</host-name>

        <web-app id="/" root-directory="/home1/web/blog/">

           <rewrite-dispatch>

             <load-balance regexp="" cluster="app-tier"/>

           </rewrite-dispatch>

        </web-app>

      </host>

 

 

      <host id="cy52.cn" root-directory=".">

         <host-alias-regexp>((?!gd).[a-zA-Z0-9.]).cy52.([cn|com|net|org])</host-alias-regexp>

         <host-name>${host-alias-regexp.regexp[1]}.cy52.${host-alias-regexp.regexp[2]}</host-name>

        <web-app id="/" root-directory="/home1/web/cy52/">

           <rewrite-dispatch>

             <load-balance regexp="" cluster="app-tier"/>

           </rewrite-dispatch>

        </web-app>

      </host>

 

      <host id="gd.cy52.cn" root-directory=".">

         <host-alias-regexp>gd.cy52.([cn|com|net|org])</host-alias-regexp>

         <host-name>gd.cy52.${host-alias-regexp.regexp[1]}</host-name>

        <web-app id="/" root-directory="/home1/web/gd/">

           <rewrite-dispatch>

             <load-balance regexp="" cluster="app-tier"/>

           </rewrite-dispatch>

        </web-app>

      </host>

 

    </cluster>

</resin>

 

b)        App-002配置文件、App-003配置文件、App-004配置文件

 

<resin xmlns="http://caucho.com/ns/resin"

       xmlns:resin="http://caucho.com/ns/resin/core">

 

  <class-loader>

    <tree-loader path="${resin.home}/ext-lib"/>

    <tree-loader path="${resin.root}/ext-lib"/>

 

    <tree-loader path="${resin.home}/lib"/>

    <tree-loader path="${resin.root}/lib"/>

  </class-loader>

//密码来源于127.0.0.1/resin-admin成生

  <management path="${resin.root}/admin">

<user name="admin" password="AaEoRi2XDPUstNgJdOEAqA==" disable="false"/>

    <resin:if test="${resin.professional}">

      <deploy-service enable="true"/>

      <jmx-service enable="true"/>

      <log-service enable="true"/>

      <xa-log-service enable="true"/>

    </resin:if>

  </management>

 

  <log name="" level="info" path="/var/log/resin/log/stdout_main.log"

       timestamp="[%Y-%m-%d %H:%M:%S.%s] {%{thread}} "/>

 

  <logger name="com.caucho" level="info"/>

 

  <logger name="com.caucho.java" level="config"/>

  <logger name="com.caucho.loader" level="config"/>

 

  <dependency-check-interval>2s</dependency-check-interval>

 

  <system-property mail.smtp.host="192.168.1.2"/>

  <system-property mail.smtp.port="25"/>

 

 

  <javac compiler="internal" args="-source 1.5"/>

 

  <cluster id="app-tier">

    <root-directory>.</root-directory>

 

    <server-default>

 

              <jvm-arg>-server</jvm-arg>

              <jvm-arg>-d64</jvm-arg>

              <jvm-arg>-Xmx2048m</jvm-arg>

              <jvm-arg>-Xms2048m</jvm-arg>

              <jvm-arg>-Xss128k</jvm-arg>

              <jvm-arg>-verbose:gc</jvm-arg>

 

              <jvm-arg>-Xmanagement</jvm-arg>

 

              <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

    <jvm-arg>-Dcom.sun.management.jmxremote.port=9993</jvm-arg>

    <jvm-arg>-Dcom.sun.management.jmxremote.ssl=false</jvm-arg>

    <jvm-arg>-Dcom.sun.management.jmxremote.authenticate=true</jvm-arg>

              <jvm-arg>-agentlib:resin</jvm-arg>

 

 

      <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>

      <watchdog-port>6601</watchdog-port>

 

      <memory-free-min>256k</memory-free-min>

 

 

      <thread-max>40960</thread-max>

 

 

      <socket-timeout>90s</socket-timeout>

 

 

      <keepalive-max>10240</keepalive-max>

      <keepalive-timeout>15s</keepalive-timeout>

      <keepalive-select-max>40960</keepalive-select-max>

 

    </server-default>

 

    <server id="app-002" address="192.168.1.2" port="6800">

        <load-balance-weight>2</load-balance-weight>

    </server>

    <server id="app-003" address="192.168.1.3" port="6800">

        <load-balance-weight>5</load-balance-weight>

    </server>

    <server id="app-004" address="192.168.1.4" port="6801">

        <load-balance-weight>5</load-balance-weight>

    </server>

 

      <persistent-store type="cluster">

        <init path="/cluster/resin/session"/>

      </persistent-store>

 

      <cache path="cache" memory-size="1024M">

        <rewrite-vary-as-private/>

      </cache>

 

 

    <resin:if test="${resin.professional}">

      <ping resin:type="com.caucho.server.admin.PingMailer">

        <url>http://www.1363.cn</url>

              <mail-to>13928189263@139.com</mail-to>

              <mail-from>admin@1363.cn</mail-from>

              <mail-subject>Resin ping has faild for server.</mail-subject>

      </ping>

    </resin:if>

 

    <web-app-default>

      <prologue>

 

        <class-loader>

          <tree-loader path="${resin.root}/ext-webapp-lib"/>

        </class-loader>

 

        <allow-servlet-el/>

      </prologue>

     

 

      <cache-mapping url-pattern="/" expires="5s"/>

         <cache-mapping url-pattern="*.html" expires="180s"/>

      <cache-mapping url-pattern="*.gif" expires="600s"/>

      <cache-mapping url-pattern="*.jpg" expires="600s"/>

      <cache-mapping url-pattern="*.png" expires="600s"/>

         <cache-mapping url-pattern="*.swf" expires="600s"/>

 

      <session-config>

        <enable-url-rewriting>false</enable-url-rewriting>

              <use-persistent-store/>

           <session-timeout>15</session-timeout>

              <session-max>40960</session-max> 

      </session-config>

 

        <jsp>

          <validate-taglib-schema>true</validate-taglib-schema>

          <fast-jstl>true</fast-jstl>

          <fast-jsf>true</fast-jsf>

        </jsp>

    </web-app-default>

 

  

    <resin:import path="${resin.home}/conf/app-default.xml"/>

 

   

    <host-default>

 

 

       <class-loader>

              <compiling-loader path="WEB-INF/classes"/>

              <library-loader path="/home1/lib"/>

       </class-loader>

 

      <web-app-deploy path="webapps"/>

 

 

      <ear-deploy path="deploy">

        <ear-default>

          <ejb-server>

            <config-directory>WEB-INF</config-directory>

            <data-source>jdbc/test</data-source>

          </ejb-server>

        </ear-default>

      </ear-deploy>

 

 

      <resource-deploy path="deploy"/>

    </host-default>

 

 

    <host-deploy path="hosts">

      <host-default>

        <resin:import path="host.xml" optional="true"/>

      </host-default>

    </host-deploy>

 

    <host id="" root-directory=".">

      <web-app id="/" root-directory="/home1/web/default/"/>

         <web-app id="/album/" document-directory="/data/album/"/>

         <web-app id="/ebook/" document-directory="/data/ebook/"/>

 

 

      <web-app id="/resin-admin" root-directory="${resin.home}/php/admin">

        <prologue>

          <resin:set var="resin_admin_external" value="true"/>

          <resin:set var="resin_admin_insecure" value="true"/>

        </prologue>

      </web-app>

    </host>

 

 

<host id="1363.cn">

  <host-alias-regexp>([a-zA-Z0-9.]+).1363.cn</host-alias-regexp>

  <host-name>${host-alias-regexp.regexp[1]}.1363.cn</host-name>

  <root-directory>.</root-directory> 

  <web-app id="/" document-directory="/home1/web/blog_oracle/"/>

  <web-app id="/album/" document-directory="/data/album/"/>

  <web-app id="/ebook/" document-directory="/data/ebook/"/>

</host>

 

<host id="cy52.cn">

  <host-alias-regexp>((?!gd).[a-zA-Z0-9.]).cy52.([cn|com|net|org])</host-alias-regexp>

  <host-name>${host-alias-regexp.regexp[1]}.cy52.${host-alias-regexp.regexp[2]}</host-name>

  <root-directory>.</root-directory>

  <web-app id="/" document-directory="/home1/web/cy52_oracle/"/>

  <web-app id="/album/" document-directory="/data/album/"/>

  <web-app id="/ebook/" document-directory="/data/ebook/"/>

</host>

 

<host id="gd.cy52.cn">

  <host-alias-regexp>gd.cy52.([cn|com|net|org])</host-alias-regexp>

  <host-name>gd.cy52.${host-alias-regexp.regexp[1]}</host-name>

  <root-directory>.</root-directory>

  <web-app id="/" document-directory="/home1/web/gd"/>

</host>

 

  </cluster>

 

 

</resin>

 

二、Session的持久化配置

      <persistent-store type="cluster">

        <init path="/cluster/resin/session"/>

      </persistent-store>

      <session-config>

           <session-timeout>15</session-timeout>

              <session-max>40960</session-max>

        <enable-url-rewriting>false</enable-url-rewriting>

         <use-persistent-store/>

      </session-config>

三、优化集群

a)         最大连接数

<http address="*" port="80" connection-max="8192"/>

b)        最大线程数

如果线程数设置得过大,会导致resin 出现缰死的情况。所以不适宜设置过大。

<thread-max>8192</thread-max>

c)        App负载设置

由于192.168.1.2除了负责Proxy,需要另外负责一个app,据以把字的负载设置了2,其它两台分别是5,即是2:5:5

    <server id="app-002" address="192.168.1.2" port="6800">

        <load-balance-weight>2</load-balance-weight>

    </server>

    <server id="app-003" address="192.168.1.3" port="6800">

        <load-balance-weight>5</load-balance-weight>

    </server>

    <server id="app-004" address="192.168.1.4" port="6801">

        <load-balance-weight>5</load-balance-weight>

    </server>

d)        Keepalive-max

      <keepalive-max>8192</keepalive-max>

      <keepalive-timeout>15s</keepalive-timeout>

e)         Keepalive-max-select

       <keepalive-select-max>8192</keepalive-select-max>

f)         <user name="admin" password="AaEoRi2XDPUstNgJdOEAqA==" disable="false"/>

密码的来源于127.0.0.1/resin-admin成生

g)        分发器web-a配置中,找到文件最底部,删除<resin:if test="${resin.professional}">判断,否则启动不了。

h)        集群配置和分发器配置文件端口注释,不要,在分发器请求中设置就可以了

<!-- The http port

      <http address="*" port="8080"/>

 -->

<server-default>

       <!-- The http port -->

       <http address="*" port="8080"/>  //默认是9080,改成80或8080,这样所有请求将从这里接受

</server-default>

<server id="web-a" address="127.0.0.1" port="6700"/>

四、编写启动脚本

[root@proxy resin]# cat bin/startup.sh

#! /bin/sh

export JAVA_HOME="/jdk/"

export RESIN_HOME="/resin/"

export JAVA_BIN=$JAVA_HOME/bin

 

bin/httpd.sh -conf conf/resin-$1$2.conf -server $1-$2 $3

五、启动方法

Bin/startup.sh app 002 start/stop/restart/kill/shutdown

Bin/startup.sh app 003 start/stop/restart/kill/shutdown

Bin/startup.sh app 004 start/stop/restart/kill/shutdown

Bin/startup.sh web a start/stop/restart/kill/shutdown
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值