您的位置:首页 > 运维架构 > Tomcat

terracotta3.7.7+apche2.2+tomcat6集群配置

2016-12-28 18:56 316 查看
         

terracotta是一家美国公司做的集群框架。是分布式缓存线性扩展平台。它巧妙得隐藏了多个分布式JVM带来的复杂性,使得java对象能够透明得在多个JVM集群中进行分享和同步,并能够进行持久化。

terracotta是怎么样的框架这里不多做叙述。大家可以百度了解。

下面开始集群的配置。

需要用到的软件如,terracotta3.7.7,apche2.2X(32),tomcat6(32).环境windows7

先配置apche跟tomcat集群。

首先下载好apche2.2X(32)。按流程装好apche

然后下载tomcat6(免安装).

下载负载均衡插件tomcat-connectors-1.2.40-windows-i386-httpd-2.0.x 注意tomcat 版本和apache版本

下载好后解压tomcat-connectors-1.2.40-windows-i386-httpd-2.0.x 将里面的mod_jk.so 放到apached的modules下面。

之后新建mod_jk.conf

内容如下:

LoadModule jk_module "D:/Program Files (x86)/Apache Group/Apache2.2/modules/mod_jk.so"  

JkWorkersFile "conf/workers.properties"  

JkMount /*.jsp controller  

JkMount /*.do controller

然后将mod_jk.conf文件复制到apche conf文件夹下面

之后新建workers.properties文件

内容如下

    #server  

    worker.list = controller  

    #========tomcat1========  

    worker.tomcat1.port=7010  

    worker.tomcat1.host=localhost  

    worker.tomcat1.type=ajp13  

    worker.tomcat1.lbfactor = 1  

    #========tomcat2========  

    worker.tomcat2.port=7011  

    worker.tomcat2.host=localhost  

    worker.tomcat2.type=ajp13  

    worker.tomcat2.lbfactor = 1  

    #========controller,负载均衡控制器========  

    worker.controller.type=lb  

    worker.controller.balanced_workers=tomcat1,tomcat2  

    worker.controller.sticky_session=true

    #worker.controller.sticky_session_force=1  

    #worker.controller.sticky_session=1

然后也将此文件复制到apche conf文件夹下面。

在apche conf文件夹下面找到httpd.conf

在最下面加上这句include "D:\Program Files (x86)\Apache Group\Apache2.2\conf\mod_jk.conf"

apche 配置基本完成

tomcat主要是配置conf下面的service文件修改端口等。如ajp访问协议主要是联通apche跟tomcat的。

修改service文件如下

tomcat1

    <?xml version='1.0' encoding='utf-8'?>  

    <!--  

      Licensed to the Apache Software Foundation (ASF) under one or more  

      contributor license agreements.  See the NOTICE file distributed with  

      this work for additional information regarding copyright ownership.  

      The ASF licenses this file to You under the Apache License, Version 2.0  

      (the "License"); you may not use this file except in compliance with  

      the License.  You may obtain a copy of the License at  

      

          http://www.apache.org/licenses/LICENSE-2.0  

      

      Unless required by applicable law or agreed to in writing, software  

      distributed under the License is distributed on an "AS IS" BASIS,  

      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  

      See the License for the specific language governing permissions and  

      limitations under the License.  

    -->  

    <!-- Note:  A "Server" is not itself a "Container", so you may not  

         define subcomponents such as "Valves" at this level.  

         Documentation at /docs/config/server.html  

     -->  

    <Server port="8006" shutdown="SHUTDOWN">  

      

      <!--APR library loader. Documentation at /docs/apr.html -->  

      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  

      <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->  

      <Listener className="org.apache.catalina.core.JasperListener" />  

      <!-- Prevent memory leaks due to use of particular java/javax APIs-->  

      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  

      <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->  

      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />  

      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  

      

        

      <GlobalNamingResources>  

        

        <Resource name="UserDatabase" auth="Container"  

                  type="org.apache.catalina.UserDatabase"  

                  description="User database that can be updated and saved"  

                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  

                  pathname="conf/tomcat-users.xml" />  

      </GlobalNamingResources>  

      

      

      <Service name="Catalina">  

        

         

        <Connector port="8081" protocol="HTTP/1.1"   

                   connectionTimeout="20000"   

                   redirectPort="8445" />  

          

               

        

        <Connector port="7010" protocol="AJP/1.3" redirectPort="8445" />  

      

      

         

      

          

        <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">  

      

          

                  

     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>  

          

          

      

          <!-- This Realm uses the UserDatabase configured in the global JNDI  

               resources under the key "UserDatabase".  Any edits  

               that are performed against this UserDatabase are immediately  

               available for use by the Realm.  -->  

          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  

                 resourceName="UserDatabase"/>  

      

          

          <Host name="localhost"  appBase="webapps"  

                unpackWARs="true" autoDeploy="true"  

                xmlValidation="false" xmlNamespaceAware="false">  

      

              

             

           

      

          </Host>  

        </Engine>  

      </Service>  

    </Server>   

tomcat2

    <?xml version='1.0' encoding='utf-8'?>  

    <!--  

      Licensed to the Apache Software Foundation (ASF) under one or more  

      contributor license agreements.  See the NOTICE file distributed with  

      this work for additional information regarding copyright ownership.  

      The ASF licenses this file to You under the Apache License, Version 2.0  

     
4000
(the "License"); you may not use this file except in compliance with  

      the License.  You may obtain a copy of the License at  

      

          http://www.apache.org/licenses/LICENSE-2.0  

      

      Unless required by applicable law or agreed to in writing, software  

      distributed under the License is distributed on an "AS IS" BASIS,  

      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  

      See the License for the specific language governing permissions and  

      limitations under the License.  

    -->  

    <!-- Note:  A "Server" is not itself a "Container", so you may not  

         define subcomponents such as "Valves" at this level.  

         Documentation at /docs/config/server.html  

     -->  

    <Server port="8006" shutdown="SHUTDOWN">  

      

      <!--APR library loader. Documentation at /docs/apr.html -->  

      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  

      <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->  

      <Listener className="org.apache.catalina.core.JasperListener" />  

      <!-- Prevent memory leaks due to use of particular java/javax APIs-->  

      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  

      <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->  

      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />  

      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  

      

        

      <GlobalNamingResources>  

        

        <Resource name="UserDatabase" auth="Container"  

                  type="org.apache.catalina.UserDatabase"  

                  description="User database that can be updated and saved"  

                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  

                  pathname="conf/tomcat-users.xml" />  

      </GlobalNamingResources>  

      

      

      <Service name="Catalina">  

        

         

        <Connector port="8081" protocol="HTTP/1.1"   

                   connectionTimeout="20000"   

                   redirectPort="8445" />  

          

               

        

        <Connector port="8010" protocol="AJP/1.3" redirectPort="8445" />  

      

      

         

      

          

        <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">  

      

          

                  

     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>  

          

          

      

          <!-- This Realm uses the UserDatabase configured in the global JNDI  

               resources under the key "UserDatabase".  Any edits  

               that are performed against this UserDatabase are immediately  

               available for use by the Realm.  -->  

          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  

                 resourceName="UserDatabase"/>  

      

          

          <Host name="localhost"  appBase="webapps"  

                unpackWARs="true" autoDeploy="true"  

                xmlValidation="false" xmlNamespaceAware="false">  

      

              

             

           

      

          </Host>  

        </Engine>  

      </Service>  

    </Server>  

tomcat2

    <?xml version='1.0' encoding='utf-8'?>  

      

      

    <Server port="8007" shutdown="SHUTDOWN">  

      

      <!--APR library loader. Documentation at /docs/apr.html -->  

      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  

      <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->  

      <Listener className="org.apache.catalina.core.JasperListener" />  

      <!-- Prevent memory leaks due to use of particular java/javax APIs-->  

      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  

      <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->  

      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />  

      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  

      

      

      <GlobalNamingResources>  

        

        <Resource name="UserDatabase" auth="Container"  

                  type="org.apache.catalina.UserDatabase"  

                  description="User database that can be updated and saved"  

                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  

                  pathname="conf/tomcat-users.xml" />  

      </GlobalNamingResources>  

      

        

      <Service name="Catalina">  

        

          

          

      

        <Connector port="8083" protocol="HTTP/1.1"   

                   connectionTimeout="20000"   

                   redirectPort="8446" />  

         

                 

        

         

      

         

        <Connector port="7011" protocol="AJP/1.3" redirectPort="8446" />  

      

      

        

      

        

        <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">  

      

            

         <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>  

      

          

      

          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  

                 resourceName="UserDatabase"/>  

      

           

          <Host name="localhost"  appBase="webapps"  

                unpackWARs="true" autoDeploy="true"  

                xmlValidation="false" xmlNamespaceAware="false">  

      

           

      

      

          </Host>  

        </Engine>  

      </Service>  

    </Server>  

自此集群已经配置好。

现在开始配置terracotta

首先配置tc-config文件

内容如下

    <?xml version="1.0" encoding="UTF-8" ?>  

    <tc:tc-config xmlns:tc="http://www.terracotta.org/config"  

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

      xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-6.xsd">  

      

      <tc-properties>  

        <property name="l2.nha.dirtydb.autoDelete" value="true"/>  

        <property name="l1.cachemanager.enabled" value="true"/>  

        <property name="logging.maxLogFileSize" value="1024"/>  

      </tc-properties>  

        

      

      <system>  

        <configuration-model>development</configuration-model>  

      </system>  

      

      

      <servers>  

      

        <server host="127.0.0.1" name="localhost" bind="0.0.0.0">  

      

      

      

          

          <statistics>/opt/terracotta/server-statistics</statistics>   

          <dso-port bind="127.0.0.1">9510</dso-port>  

          <jmx-port bind="127.0.0.1">9520</jmx-port>  

          <l2-group-port bind="127.0.0.1">9530</l2-group-port>  

          <authentication/>  

      

         

          <dso>  

      

           

            <client-reconnect-window>120</client-reconnect-window>  

      

           

            <persistence>  

              

              <mode>temporary-swap-only</mode>  

            </persistence>  

      

            

            <garbage-collection>  

      

              <enabled>true</enabled>  

      

              <verbose>false</verbose>  

      

              <interval>3600</interval>  

            </garbage-collection>  

      

          </dso>  

        </server>  

         

        <mirror-groups>  

           

          <mirror-group group-name="group1">  

            <members>  

              <member>localhost</member>  

            </members>  

             

            <ha>  

              <mode>networked-active-passive</mode>  

              <networked-active-passive>  

                <election-time>5</election-time>  

              </networked-active-passive>  

            </ha>  

           </mirror-group>  

        </mirror-groups>       

        <ha>  

          <mode>networked-active-passive</mode>  

          <networked-active-passive>  

            <election-time>5</election-time>  

          </networked-active-passive>  

        </ha>  

        <update-check>  

          <enabled>true</enabled>  

          <period-days>10</period-days>  

        </update-check>  

      </servers>  

      <clients>  

        <logs>logs-%i</logs>  

      </clients>  

      

    </tc:tc-config>

然后在terracotta解压下的bin文件下面把tc-config.xml复制过来。

然后将terracotta session文件夹下面 terracotta-session-1.3.7跟common下面的

terracotta-toolkit-1.6-runtime-5.7.0复制到tomcat, lib下面。

然后cmd 命令窗口cd到terracotta3.7.7-bin下执行tim-get.bat tc-config.xml

之后执行start-tc-server.bat

会看到如下

 

然后在需要应用的tomcat的应用下面的META-INF 新建context.xml 并将一下内容复制进去

<?xml version="1.0" encoding="UTF-8"?>

<Context>

    <Valve className="org.terracotta.session.TerracottaTomcat60xSessionValve" tcConfigUrl="127.0.0.1:9510" />

</Context>

之后分别启动两个tomcat,apche

测试页面见附件

有一点要提醒的是请注意jdk跟tomcat版本对应。

本文过程经过实践。也参考了csdn的其他博友的文章。

参考过如博友飞*天的文章。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  tomcat 框架 terracotta