ehCache集群JGroups方式配置

11 篇文章 0 订阅
3 篇文章 0 订阅

参考了https://my.oschina.net/u/866380/blog/501082的内容

下面直接贴代码

pom.xml

		<!-- Ehcache实现,用于参考 -->
		<dependency>
			<artifactId>ehcache</artifactId>
			<groupId>net.sf.ehcache</groupId>
			<version>2.7.2</version>
		</dependency>
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache-jgroupsreplication</artifactId>
			<version>1.7</version>
		</dependency>
		<dependency>
			<groupId>org.jgroups</groupId>
			<artifactId>jgroups</artifactId>
			<version>3.0.9.Final</version>
		</dependency>
ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
	monitoring="autodetect">
	<diskStore path="java.io.tmpdir" />
	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
		properties="jgroups_tcp.xml" />

	<defaultCache maxElementsInMemory="1000" eternal="false"
		timeToLiveSeconds="120" overflowToDisk="false" />
	<cache name="myCache" maxElementsInMemory="100" eternal="false"
		timeToLiveSeconds="5" overflowToDisk="false" diskPersistent="false">
		<cacheEventListenerFactory
			class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true,
              replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
		<bootstrapCacheLoaderFactory
			class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
			properties="bootstrapAsynchronously=false" />
	</cache>
</ehcache>

需要缓存的cache加上红色标签内容

jgroups_tcp.xml

<TCP bind_port="7800" />
<TCPPING timeout="3000"
         initial_hosts="192.168.1.80:7800,192.168.1.81:7800,192.168.1.82:7800"
         port_range="10"
         num_initial_members="3"/>
<VERIFY_SUSPECT timeout="1500"  />
<pbcast.NAKACK2 use_mcast_xmit="false" gc_lag="100"
               retransmit_timeout="300,600,1200,2400,4800"
               discard_delivered_msgs="true"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
               max_bytes="400000"/>
<pbcast.GMS print_local_addr="true" join_timeout="3000" shun="false"
               view_bundling="true"/>

inittaial_hosts是我的三台服务器ip

第一次运行没成功,原因是我的服务器没有关闭防火墙,关了之后就可以了

遇到异常的可以看看我另一篇博客http://blog.csdn.net/haiyang4988/article/details/54288754,或许能帮到你






  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值