ehcache集群配置

ehcache集群方式有几种,可以去官网看文档。http://www.ehcache.org/documentation/2.7/replication/

我这里主要说的是RMI方式。

RMI节点发现方式分为自动发现与手动配置。

我接下来要说的是自动发现。

自动发现很简单。只要在ehcache.xml添加如下配置即可。

        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"

        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446,

    multicastPacketTimeToLive=32" />


ehcache集群配置_第1张图片
1


这里我忽略了hostName的配置,查看他们的源码发现如果不填写hostName,

他们就会通过JDK中的InterAddress.getLocalHost().getHostAddress()获取本机的ip地址,

所以在这里我没有填写hostName的配置,方便部署到多台硬件服务器上。

但是如果一台已经服务器上有多个网卡,这里一定要指定hostName的IP,原因参考InterAddress源码。

post这里我指定的时40001,如果这里不填写port配置,ehcache就会通过ServerSocket的getLocalPort获取一个本机没有被占用的端口 -->

        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"

        properties="hostName=127.0.0.1,port=1000,socketTimeoutMillis=120000" />


ehcache集群配置_第2张图片
2

上面的127.0.0.1是我本地测试时。 port =1000并不是是你起动的tomcat端口,而是你自己给这个节点的一个端口。假设你启动第二个tomcat,这里你就可以写2000.等


        name="sessionNoMap"

        eternal="false"

        maxElementsInMemory="100"

        overflowToDisk="false"

        diskPersistent="false"

        timeToIdleSeconds="0"

        timeToLiveSeconds="300"

        memoryStoreEvictionPolicy="LRU">


        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"

        properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy=false, replicateRemovals=true " />


        class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />


ehcache集群配置_第3张图片
3

上面是我自己需要集群的一个缓存。添加下面标记即可。

你可能感兴趣的:(ehcache集群配置)