ehcache集群实现和遇到的一些问题

redhat6.7服务器两台:

A IP:192.168.1.122

B IP:192.168.1.123

A 服务器ehcache.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd">

    <diskStore path="java.io.tmpdir" />
     
    <cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=manual,rmiUrls=//192.168.1.123:40001/authorizationCache"
        />
        
    <cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost,port=40002,socketTimeoutMillis=2000"
         />


    <defaultCache maxElementsInMemory="10000" eternal="false"
        timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true">
        <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=false,replicateRemovals=true" />
        <bootstrapCacheLoaderFactory
    class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
    </defaultCache>

    <!-- 120秒过期 -->
    <cache name="authorizationCache" maxElementsInMemory="10000"
        eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120"
        overflowToDisk="false" memoryStoreEvictionPolicy="LFU">
        <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=false,replicateRemovals=true " />
        <bootstrapCacheLoaderFactory
            class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
    </cache>
    <!-- properties="bootstrapAsynchronously=false" -->
</ehcache>

 

B 服务器ehcache.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd">

    <diskStore path="java.io.tmpdir" />
     
    <cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=manual,rmiUrls=//192.168.1.122:40001/authorizationCache"
        />
        
    <cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost,port=40001,socketTimeoutMillis=2000"
         />


    <defaultCache maxElementsInMemory="10000" eternal="false"
        timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true">
        <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=false,replicateRemovals=true" />
        <bootstrapCacheLoaderFactory
    class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
    </defaultCache>

    <!-- 120秒过期 -->
    <cache name="authorizationCache" maxElementsInMemory="10000"
        eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120"
        overflowToDisk="false" memoryStoreEvictionPolicy="LFU">
        <cacheEventListenerFactory
            class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=false,replicateRemovals=true " />
        <bootstrapCacheLoaderFactory
            class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
    </cache>
    <!-- properties="bootstrapAsynchronously=false" -->
</ehcache>

 

关于 EhCache RMI 组播发现成员和手动发现集群成员的区别后优缺点可以参考:

http://www.cnblogs.com/onlywujun/p/5745195.html

本文配置采用手动发现集群成员配置。

本次部署遇到的问题:

 

ehcache多次部署缓存无法同步.

经过查找 EhCache RMI 使用的是 java remote 方式与成员通讯.而我们测试环境IP地址变更过一次,

hostname和ip地址不一致,导致一直无法同步。

java remote会通过hostname去调用程序。

用到的命令:

$ hostname -i

$ifconfig 

$telnet ip port

java Remote 参考资料:

http://blog.csdn.net/u014490157/article/details/51726663

http://blog.csdn.net/mixturemay/article/details/3035109

http://staratsky.iteye.com/blog/345593

http://www.cnblogs.com/lwhcs/p/5616497.html

 

 

转载于:https://my.oschina.net/lzdn/blog/879891

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值