CAS (11) —— CAS TicketRegistry使用Ehcache的集群方案

CAS (11) —— CAS TicketRegistry使用Ehcache的集群方案

摘要

CAS TicketRegistry使用Ehcache的集群方案

版本


tomcat版本: tomcat-8.0.29

jdk版本: jdk1.8.0_65

cas版本: 4.1.3

**cas4.1.3 (4.x还在开发过程中不是很稳定,迭代比较快,也会有些bug) **

cas-client-3.4.1

Ehcache版本: 2.10.1

内容

目标架构

准备

参照下列文章配置好相关环境

配置

  • Ehcache Maven

      <dependency>
                <groupId>org.jasig.cas</groupId>
                <artifactId>cas-server-integration-ehcache</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache-core</artifactId>
                <version>2.6.11</version>
            </dependency>
            <dependency>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache</artifactId>
                <version>2.10.1</version>
            </dependency>
    
  • Ehcache配置文件ehcache-replicated.xml

    • 节点a(以端口8433为例)

        <ehcache name="ehCacheTicketRegistryCache"
         updateCheck="false"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
      
        <diskStore path="java.io.tmpdir/cas"/>
      
        <!--
           | Automatic peer discovery
           | See http://ehcache.org/documentation/user-guide/rmi-replicated-caching#automatic-peer-discovery
           | for more information.
           -->
        <!--
        <cacheManagerPeerProviderFactory
              class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
              properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32"
              propertySeparator="," />
        -->
      
        <!--
           | Manual peer discovery
           | See http://ehcache.org/documentation/user-guide/rmi-replicated-caching#manual-peer-discovery-manual-peer-discovery
           | for more information
           -->
        <!--
        <cacheManagerPeerProviderFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                properties="peerDiscovery=manual,rmiUrls=//peer-2:41001/cas_st|//peer-3:41001/cas_st|//peer-2:41001/cas_tgt|//peer-3:41001/cas_tgt" />
        <cacheManagerPeerListenerFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                properties="port=41001,remoteObjectPort=41002" />
        -->
      
        <cacheManagerPeerProviderFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                properties="peerDiscovery=manual,rmiUrls=//127.0.0.1:41041/cas_st|//127.0.0.1:41041/cas_tgt" />
        <cacheManagerPeerListenerFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                properties="port=41031, remoteObjectPort=41032" />
        
        </ehcache>
      
    • 节点b(以端口8443为例)

         <cacheManagerPeerProviderFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
                properties="peerDiscovery=manual,rmiUrls=//127.0.0.1:41031/cas_st|//127.0.0.1:41031/cas_tgt" />
        <cacheManagerPeerListenerFactory
                class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
                properties="port=41041,remoteObjectPort=41042" />
      

    注意以上ProviderFactory和ListenerFactory中的给出的端口:

    • ListenerFactory是指定本地Cache节点的端口

    • ProviderFactory是配置远程Cache节点的端口

    • 如果二个以上节点,则所有节点都要列出并用 | 符号分隔

  • Ehcache在CAS TicketRegistry.xml 中的配置

      <?xml version="1.0" encoding="UTF-8"?>
      		<beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:c="http://www.springframework.org/schema/c"
             xmlns:p="http://www.springframework.org/schema/p"
             xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               " >
          <description>
              Configuration for the default TicketRegistry which stores the tickets in Ehcache
          </description>
          <bean id="ticketRegistry"
                class="org.jasig.cas.ticket.registry.EhCacheTicketRegistry"
                p:serviceTicketsCache-ref="serviceTicketsCache"
                p:ticketGrantingTicketsCache-ref="ticketGrantingTicketsCache" />
      
          <bean id="abstractTicketCache" abstract="true"
                class="org.springframework.cache.ehcache.EhCacheFactoryBean"
                p:cacheManager-ref="cacheManager"
                p:diskExpiryThreadIntervalSeconds="0"
                p:diskPersistent="false"
                p:eternal="false"
                p:maxElementsInMemory="10000"
                p:maxElementsOnDisk="20000"
                p:memoryStoreEvictionPolicy="LRU"
                p:overflowToDisk="true"
                p:bootstrapCacheLoader-ref="ticketCacheBootstrapCacheLoader" />
      
          <!-- MUST use synchronous repl for service tickets for correct behavior. -->
          <bean id="serviceTicketsCache"
                class="org.springframework.cache.ehcache.EhCacheFactoryBean"
                parent="abstractTicketCache"
                p:cacheName="cas_st"
                p:timeToIdle="0"
                p:timeToLive="300"
                p:cacheEventListeners-ref="ticketRMISynchronousCacheReplicator" />
      
          <bean id="ticketGrantingTicketsCache"
                class="org.springframework.cache.ehcache.EhCacheFactoryBean"
                parent="abstractTicketCache"
                p:cacheName="cas_tgt"
                p:timeToIdle="0"
                p:timeToLive="7201"
                p:cacheEventListeners-ref="ticketRMIAsynchronousCacheReplicator" />
      
          <bean id="cacheManager"
                class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
                p:configLocation="classpath:ehcache-replicated.xml"
                p:shared="false"
                p:cacheManagerName="ticketRegistryCacheManager" />
      
          <bean id="ticketRMISynchronousCacheReplicator"
                class="net.sf.ehcache.distribution.RMISynchronousCacheReplicator"
                c:replicatePuts="true"
                c:replicatePutsViaCopy="true"
                c:replicateUpdates="true"
                c:replicateUpdatesViaCopy="true"
                c:replicateRemovals="true" />
      
          <!--Richard modify cater to 4.1.3-->
          <bean id="ticketRMIAsynchronousCacheReplicator"
                class="net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator"
                parent="ticketRMISynchronousCacheReplicator"
                c:replicatePuts="true"
                c:replicatePutsViaCopy="true"
                c:replicateUpdates="true"
                c:replicateUpdatesViaCopy="true"
                c:replicateRemovals="true"
                c:replicationInterval="10000"
                c:maximumBatchSize="100" />
      
          <bean id="ticketCacheBootstrapCacheLoader"
                class="net.sf.ehcache.distribution.RMIBootstrapCacheLoader"
                c:asynchronous="true"
                c:maximumChunkSize="5000000" />
      
      
      </beans>
    

测试

参考

参考来源:

Ehcache Ticket Registry

结束

posted @ 2016-02-23 11:30  Richaaaard  阅读(1106)  评论(0编辑  收藏  举报