亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

tomcat 集群下ehcache 整合spring cache-annota

系統 2126 0
系統環境:win7
部署環境:apache2.2 tomcat4
應用程序版本:spring3.2 ehcache2.6

1:tomcat 負載和集群配置
1.1 模型圖

[img]
tomcat 集群下ehcache 整合spring cache-annotation
[/img]

tomcat負載需要apache協助,apache啟的作用就是,接受client請求,調度tomcat.
各個tomcat分載請求,均衡流量,降低web server壓力。通過tomcat cluster 可以實現各tomcat數據同步和共享。
1.2 配置
??? 解壓兩個統一版本的tomcat 分別命名為apache-tomcat-6080 和apache-tomcat-7080
?? 修改6080tomcat srever。xml
    
 <Server port="6005" shutdown="SHUTDOWN"> 
   <Connector port="6080" protocol="HTTP/1.1" 
        connectionTimeout="20000" 
        redirectPort="6443"  
        useBodyEncodingForURI ="true" 
        URIEncoding="UTF-8"
   />
   <Connector port="6009" protocol="AJP/1.3" redirectPort="6443" />
   <!--jvmRoute 是apache 檢測通道名--> 
   <Engine name="Catalina" defaultHost="localhost"   
    jvmRoute="tomcat1">
   
   <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                 channelSendOptions="8">

          <Manager className="org.apache.catalina.ha.session.DeltaManager"
                   expireSessionsOnShutdown="false"
                   notifyListenersOnReplication="true"/>

          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
                        address="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <!--port 不同tomcat 設置不同-->
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="auto"
                      port="4001"
                      autoBind="100"
                      selectorTimeout="5000"
                      maxThreads="6"/>

            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
          </Channel>

          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                 filter=""/>
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/tmp/war-temp/"
                    deployDir="/tmp/war-deploy/"
                    watchDir="/tmp/war-listen/"
                    watchEnabled="false"/>

          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
        </Cluster>


  

修改7080tomcat srever。xml
    
 <Server port="7005" shutdown="SHUTDOWN"> 
   <Connector port="7080" protocol="HTTP/1.1" 
        connectionTimeout="20000" 
        redirectPort="7443"  
        useBodyEncodingForURI ="true" 
        URIEncoding="UTF-8"
   />
   <Connector port="7009" protocol="AJP/1.3" redirectPort="7443" />
   <!--jvmRoute 是apache 檢測通道名--> 
   <Engine name="Catalina" defaultHost="localhost"   
    jvmRoute="tomcat1">
   
   <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                 channelSendOptions="8">

          <Manager className="org.apache.catalina.ha.session.DeltaManager"
                   expireSessionsOnShutdown="false"
                   notifyListenersOnReplication="true"/>

          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
                        address="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <!--port 不同tomcat 設置不同-->
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="auto"
                      port="4002"
                      autoBind="100"
                      selectorTimeout="5000"
                      maxThreads="6"/>

            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
          </Channel>

          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                 filter=""/>
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

          <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/tmp/war-temp/"
                    deployDir="/tmp/war-deploy/"
                    watchDir="/tmp/war-listen/"
                    watchEnabled="false"/>

          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
        </Cluster>


  


?? 配置apache
?? 將mod_jk-1.2.31-httpd-2.2.3.so 復制到apache moudles 中。
??? 在conf中創建mod_jk.conf 和workers.properties。
??? mod_jk.conf? 主要定義mod_jk模塊的位置以及mod_jk模塊的連接日志設置,還有定義worker.properties文件的位置。
???
    
    LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so
JkWorkersFile conf/workers.properties
JkMount /*.* controller

    
  

??
??? workers.properties 定義worker的參數,主要是連接tomcat主機的地址和端口信息。如果Tomcat與apache不在同一臺機器上,或者需要做多臺機器上tomcat的負載均衡只需要更改workers.properties文件中的相應定義即可。
???
    
    #server
worker.list = controller,tomcat1,tomcat2
#========tomcat1========
worker.tomcat1.port=6009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
#========tomcat2========
worker.tomcat2.port=7009
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=false
worker.controller.sticky_session_force=1
#worker.controller.sticky_session=1


   
  

??
將conf/httpdf.conf 文件末尾追加:
    Include conf/mod_jk.conf
  


2 ehcache 與 spring-cache 整合
? 2.1 添加ehcache.xml
    
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
    <diskStore path="F:/eclipse_workspace/springmvc3.2/cache"/>
    <defaultCache
     maxElementsInMemory="500"
     eternal="false"
     timeToIdleSeconds="300"
     timeToLiveSeconds="1200"
     overflowToDisk="true"/>
    <cache name="user" maxElementsInMemory="150" eternal="false" timeToLiveSeconds="36000" timeToIdleSeconds="3600" overflowToDisk="true">
          <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
              properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= true, replicateRemovals= true " />
          <!-- <cacheEventListenerFactory class="cn.com.dwsoft.test.ehcache.EventFactory" />    -->
    </cache>
   <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
   properties="peerDiscovery=manual,rmiUrls=//127.0.0.1:40002/user"/>

    <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=127.0.0.1,port=40001,socketTimeoutMillis=2000"/>
</ehcache>

  


cacheManagerPeerProviderFactory 其他tomcat 多個url 可以用,分割
cacheManagerPeerListenerFactory 當前tomcat
部署時,需要根據tomcat 集群監聽端口 修改各自的ehcache.xml配置.


applictionContext.xml 配置
    
<!-- cacheManager工廠類 -->

	<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"

     p:configLocation="classpath:ehcache.xml"

     p:shared="false" />


	<!-- 聲明cacheManager -->
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"
	   p:cacheManager-ref="cacheManagerFactory"/>

  


spring 注解緩存使用
    

package com.cn.ld.modules.user.service.impl;

import java.util.Arrays;

@EnableCaching
@Service
public class UserServiceImpl implements UserService ,UserDetailsService{
	private User[] users = null;
	{
		users = new User[5];
		users[0] = new User("java小生0", "111111", 21, '男');
		users[1] = new User("java小生1", "222222", 22, '男');
		users[2] = new User("java小生2", "333333", 23, '男');
		users[3] = new User("java小生3", "444444", 24, '男');
		users[4] = new User("java小生4", "555555", 25, '女');
	}

	@Cacheable(value = "user" , condition="#id < 3" ,unless="#result.age == 25")
	public User findById(int id) {
		System.out.println("--------findById start-----------");
		System.out.println("agrs{id:"+id+"}");
		User u = Arrays.asList(users).get(id);
		System.out.println("--------findById end-----------");
		return u;
	}

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
	{
		User user = new User(username, "111111", 25, '男');
		return user ;
	}
}


  

tomcat 集群下ehcache 整合spring cache-annotation


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲色视频 | 日本高清无吗免费播放 | 日本天天谢天天要天天爱 | 日韩欧美国产综合 | 成人在线91 | 日韩经典欧美精品一区 | 看片福利| 在线色资源 | 麻豆日韩| 一级做a爱片久久毛片 | 日韩一区二区国色天香 | 欧美综合国产精品日韩一 | 国产香蕉久久 | 久久久久免费精品国产小说 | 成人免费www在线高清观看 | 伊人国产在线播放 | 一级毛片在线看 | 青青青青久久国产片免费精品 | 国产精品免费一级在线观看 | 婷婷亚洲激情 | 天天干天天谢 | 国产欧美日韩中文久久 | 欧美日韩高清在线 | 欧美午夜艳片欧美精品 | 高清二区 | 亚洲视频一区在线观看 | 色婷婷免费视频 | 亚洲高清一区二区三区四区 | 国产美女流白浆的免费视 | 欧美视频性 | 精品国产麻豆 | 欧美激情一区二区三区视频 | 波多野结衣视频一区 | 不卡一区| 欧美高清成人 | 国产视频第二页 | 成人在线视频国产 | 免费一级特黄 欧美大片 | 91在线亚洲综合在线 | 日韩欧美伊人久久大香线蕉 | 一级黄色毛片子 |