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