`
foxxiao
  • 浏览: 105691 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Ehcache集群环境配置

阅读更多
Ehcache支持的分布式缓存支持有三种RMI,JGroups,JMS,这里介绍下MRI和JGrpups两种方式,Ehcache使用版本为1.5.0,关于ehcache的其他信息请参考http://ehcache.sourceforge.net/EhcacheUserGuide.html,关于jgroups的信息请参考http://www.jgroups.org/manual/html_single/index.html。



环境为两台机器 server1 ip:192.168.2.154,server2 ip:192.168.2.23



1. RMI方式:

rmi的方式配置要点(下面均是server1上的配置,server2上的只需要把ip兑换即可)



a. 配置PeerProvider:



Xml代码
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"   
properties="peerDiscovery=manual,rmiUrls=//192.168.2.23:40001/userCache|//192.168.2.23:40001/resourceCache" /> 

<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,rmiUrls=//192.168.2.23:40001/userCache|//192.168.2.23:40001/resourceCache" />配置中通过手动方式同步sever2中的userCache和resourceCache。



b. 配置CacheManagerPeerListener:



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

<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=192.168.2.154, port=40001,socketTimeoutMillis=2000" /> 配置中server1监听本机40001端口。



c. 在每一个cache中添加cacheEventListener,例子如下:



Xml代码
<cache name="userCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" diskPersistent="false" diskExpiryThreadIntervalSeconds="120"> 
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"     properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= false, replicateRemovals= true " /> 
</cache> 

<cache name="userCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= false, replicateRemovals= true " />
</cache> 
2. JGroups方式:

ehcache 1.5.0之后版本支持的一种方式,配置起来比较简单,要点:



a. 配置PeerProvider,使用tcp的方式,例子如下:



Xml代码
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory" 
        properties="connect=TCP(start_port=7800):  
        TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;  
        num_initial_members=3;up_thread=true;down_thread=true):  
        VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):  
        pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):  
        pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;  
        print_local_addr=false;down_thread=true;up_thread=true)"   
        propertySeparator="::" /> 

<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="connect=TCP(start_port=7800):
        TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;
        num_initial_members=3;up_thread=true;down_thread=true):
        VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):
        pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):
        pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;
        print_local_addr=false;down_thread=true;up_thread=true)"
        propertySeparator="::" /> b.为每个cache添加cacheEventListener:



Xml代码
<cache name="userCache" maxElementsInMemory="10000" eternal="true" 
        overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" 
        diskPersistent="false" diskExpiryThreadIntervalSeconds="120"> 
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" 
            properties="replicateAsynchronously=true, replicatePuts=true,  
                replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/> 
</cache> 

<cache name="userCache" maxElementsInMemory="10000" eternal="true"
overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
   replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
</cache> JGroup方式配置的两个server上的配置文件一样,若有多个server,在initial_hosts中将server ip加上即可。

一个完整的ehcache.xml文件:

Xml代码
<?xml version="1.0" encoding="UTF-8"?> 
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd"> 
    <diskStore path="java.io.tmpdir" /> 
 
    <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory" 
        properties="connect=TCP(start_port=7800):  
        TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;  
        num_initial_members=3;up_thread=true;down_thread=true):  
        VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):  
        pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):  
        pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;  
        print_local_addr=false;down_thread=true;up_thread=true)"   
        propertySeparator="::" /> 
 
    <defaultCache maxElementsInMemory="10000" eternal="true" 
        overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" 
        diskPersistent="false" diskExpiryThreadIntervalSeconds="120"> 
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" 
            properties="replicateAsynchronously=true, replicatePuts=true,  
                replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/> 
    </defaultCache> 
 
    <cache name="velcroCache" maxElementsInMemory="10000" eternal="true" 
        overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" 
        diskPersistent="false" diskExpiryThreadIntervalSeconds="120"> 
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" 
            properties="replicateAsynchronously=true, replicatePuts=true,  
                replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/> 
    </cache> 
    <cache name="userCache" maxElementsInMemory="10000" eternal="true" 
        overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" 
        diskPersistent="false" diskExpiryThreadIntervalSeconds="120"> 
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" 
            properties="replicateAsynchronously=true, replicatePuts=true,  
                replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/> 
    </cache> 
    <cache name="resourceCache" maxElementsInMemory="10000" 
        eternal="true" overflowToDisk="true" timeToIdleSeconds="0" 
        timeToLiveSeconds="0" diskPersistent="false" 
        diskExpiryThreadIntervalSeconds="120"> 
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" 
            properties="replicateAsynchronously=true, replicatePuts=true,  
                replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/> 
    </cache> 
</ehcache> 

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
<diskStore path="java.io.tmpdir" />

<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="connect=TCP(start_port=7800):
        TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;
        num_initial_members=3;up_thread=true;down_thread=true):
        VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):
        pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):
        pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;
        print_local_addr=false;down_thread=true;up_thread=true)"
        propertySeparator="::" />

<defaultCache maxElementsInMemory="10000" eternal="true"
overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
   replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
</defaultCache>

<cache name="velcroCache" maxElementsInMemory="10000" eternal="true"
overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
   replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
</cache>
<cache name="userCache" maxElementsInMemory="10000" eternal="true"
overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
   replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
</cache>
<cache name="resourceCache" maxElementsInMemory="10000"
eternal="true" overflowToDisk="true" timeToIdleSeconds="0"
timeToLiveSeconds="0" diskPersistent="false"
diskExpiryThreadIntervalSeconds="120">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
properties="replicateAsynchronously=true, replicatePuts=true,
   replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
</cache>
</ehcache> 
分享到:
评论

相关推荐

    EHcache缓存框架

    EHcache缓存框架,ehcache介绍与说明,Ehcache详细,EHcache集群环境配置

    集群环境中使用_EhCache_缓存系统&Ehcache配置文件的详细说明

    NULL 博文链接:https://jlwangjinshuang-163-com.iteye.com/blog/1058617

    java缓存实现与spring托管

    0. 文档介绍 2 0.1 文档目的 2 0.2 文档范围 2 0.3 读者对象 2 0.4 参考文献 2 0.5 术语与缩写解释 2 1. 概述 3 1.1背景 3 1.2 主要特征 3 ...4. 分布式缓存集群环境配置 19 4.1 集群配置方式 19 5. 测试用例 28

    Ehcache分布式缓存与其在spring中的使用

    主要讲解下encache的原理、分布式缓存集群环境配置、与在spring中的使用

    EHCache详解_技术文档

    详细描述EHCache的用法,和spring的集成,在分布式环境(集群)中的配置

    J2Cache两级缓存框架-其他

    该缓存框架主要用于集群环境中。单机也可使用,用于避免应用重启导致的缓存冷启动后对后端业务的冲击。 数据读取: 读取顺序 -&gt; L1 -&gt; L2 -&gt; DB 数据更新 1、从数据库中读取最新数据,依次更新L1 -&gt; L2 ...

    kaleido-repository:KaleidoFoundry是Java 6+技术基础,具有生产力,可插拔性,可扩展性和可扩展性。 它提供用于配置,缓存,i18n,消息传递的模块...

    从简单开始,当您需要更复杂的体系结构(如集群环境),强大的缓存提供程序解决方案,消息传递系统... kaleido将适合而无需更改Java代码。 主要特点是: 动态和集中式(跨集群或本地)的Configuration管理REST API,...

    Java高并发高性能分布式框架从无到有微服务架构设计.doc

    还有CDN就是用来加速 用户访问的:即用户首先访问到全国各地的CDN节点(使用如ATS、Squid实现),如果C DN没命中,会回源到中央nginx集群,该集群如果没有命中缓存(该集群的缓存不是必须 的,要根据实际命中情况等...

    com.yangc.utils:工作中积累的工具类

    com.yangc.utilsjava工具类作为... 基于redis的工具类,与redis的集群配置无缝结合dbJdbcUtils - 操作jdbc的工具类MongodbUtils - 操作mongodb的工具类emailEmailUtils - 邮件工具类,支持发送带附件的邮件encryptionAe

    spring boot 全面的样例代码

    - chapter2-1-1:[配置文件详解:自定义属性、随机数、多环境配置等](http://blog.didispace.com/springbootproperties/) ### Web开发 - chapter3-1-1:[构建一个较为复杂的RESTful API以及单元测试]...

    jeesuite-libs-其他

    功能列表:cache模块基于配置支持单机、哨兵、分片、集群模式自由切换更加简单的操作API封装一级缓存支持(ehcache &amp; guava cache)、分布式场景多节点自动通知多组缓存配置同时支持 (一个应用多个redis server...

    网络架构师148讲视频课程

    │ 第09节:搭建基础的开发环境.avi │ 第10节:Spring+Mybatis实现DAO.avi │ 第11节:Mybatis的分页实现.avi │ 第12节:Service的实现以及模块化.avi │ 第13节:Spring MVC实现Web层开发.avi │ 第14节:新增和...

    单点登录源码

    单点登录, SSM框架公共模块 ├── zheng-admin -- 后台管理模板 ├── zheng-ui -- 前台thymeleaf模板[端口:1000] ...## 环境搭建(QQ群内有“zheng环境搭建和系统部署文档.doc”) #### 开发工具: ...

    java开源包1

    支持redis的主从集群,可以做读写分离。缓存读取自redis的slave节点,写入到redis的master节点。 Java对象的SQL接口 JoSQL JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL...

    java开源包11

    支持redis的主从集群,可以做读写分离。缓存读取自redis的slave节点,写入到redis的master节点。 Java对象的SQL接口 JoSQL JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL...

    java开源包2

    支持redis的主从集群,可以做读写分离。缓存读取自redis的slave节点,写入到redis的master节点。 Java对象的SQL接口 JoSQL JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL...

    java开源包3

    支持redis的主从集群,可以做读写分离。缓存读取自redis的slave节点,写入到redis的master节点。 Java对象的SQL接口 JoSQL JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL...

    java开源包6

    支持redis的主从集群,可以做读写分离。缓存读取自redis的slave节点,写入到redis的master节点。 Java对象的SQL接口 JoSQL JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL...

    java开源包5

    支持redis的主从集群,可以做读写分离。缓存读取自redis的slave节点,写入到redis的master节点。 Java对象的SQL接口 JoSQL JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL...

Global site tag (gtag.js) - Google Analytics