linux 部署分布式ehcache,两个实例无法同步数据的一个坑

在Linux上部署的两个Ehcache实例遇到数据同步问题,经过排查,发现是由于Jboss 4.2.3.GA版本导致的。通过更新Jboss到4.0.5.GA版本,成功解决了实例间的数据同步问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux 部署分布式ehcache,两个实例无法同步数据的一个坑

windows系统测试过分布式ehcache,两个实例ehcache数据彼此之间可以同步,到了linux环境无法同步:

  • linux实例1:192.168.0.228
  • linux实例2:192.168.0.77
  • jdk版本: JDK1.6
  • web容器: jboss-4.2.3.GA
  • ehcache版本: ehcache-2.10.5-distribution

linux实例1配置

<cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
            properties="peerDiscovery=manual,rmiUrls=//192.168.0.77:40000/cdmsObjectCache"
            propertySeparator=","
            />

<cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
            properties="hostName=192.168.0.228,port=40000,socketTimeoutMillis=120000" 
            propertySeparator="," />

    <!-- cacheEventListenerFactory - 监听缓存中element的put, remove, update和expire事件 -->
    <!-- bootstrapCacheLoaderFactory - 启动时加载缓存的element每个用来做分布式缓存都必须设定element的事件监听器,用来在各个CacheManager节点复制消息。 -->
    <!-- eternal:boolean类型,表示是否永恒,默认为false。 如果设为true,将忽略timeToIdleSeconds和timeToLiveSeconds,Cache内的元素永远都不会过期,也就不会因为元素的过期而被清除了。 -->
    <cache name="cdmsObjectCache"
           maxEntriesLocalHeap="10000"
           maxEntriesLocalDisk="10000000"
           eternal="true"
           diskSpoolBufferSizeMB="20"
           memoryStoreEvictionPolicy="LFU"
           transactionalMode="off">
        <persistence strategy="localTempSwap"/>
        <cacheEventListenerFactory
                class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
                properties="replicateAsynchronously=true, replicatePuts=true,
                            replicatePutsViaCopy=true, replicateUpdates=true,
                            replicateUpdatesViaCopy=true, replicateRemovals=true,
                            asynchronousReplicationIntervalMillis=200"/>
        <bootstrapCacheLoaderFactory
                class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
    </cache>

linux实例2配置

<cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
            properties="peerDiscovery=manual,rmiUrls=//192.168.0.228:40000/cdmsObjectCache"
            propertySeparator=","
            />

<cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
            properties="hostName=192.168.0.77,port=40000,socketTimeoutMillis=120000" 
            propertySeparator="," />

    <!-- cacheEventListenerFactory - 监听缓存中element的put, remove, update和expire事件 -->
    <!-- bootstrapCacheLoaderFactory - 启动时加载缓存的element每个用来做分布式缓存都必须设定element的事件监听器,用来在各个CacheManager节点复制消息。 -->
    <!-- eternal:boolean类型,表示是否永恒,默认为false。 如果设为true,将忽略timeToIdleSeconds和timeToLiveSeconds,Cache内的元素永远都不会过期,也就不会因为元素的过期而被清除了。 -->
    <cache name="cdmsObjectCache"
           maxEntriesLocalHeap="10000"
           maxEntriesLocalDisk="10000000"
           eternal="true"
           diskSpoolBufferSizeMB="20"
           memoryStoreEvictionPolicy="LFU"
           transactionalMode="off">
        <persistence strategy="localTempSwap"/>
        <cacheEventListenerFactory
                class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
                properties="replicateAsynchronously=true, replicatePuts=true,
                            replicatePutsViaCopy=true, replicateUpdates=true,
                            replicateUpdatesViaCopy=true, replicateRemovals=true,
                            asynchronousReplicationIntervalMillis=200"/>
        <bootstrapCacheLoaderFactory
                class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
    </cache>

百度的答案没有解决我的问题

jboss服务器起来后报错,然后根据错误提示,搜索说是要改 修改/etc/hosts
Linux系统使用/etc/hosts文件中localhost解析ip为127.0.0.1,当客户端向服务器Lookup时,服务端就会把解析出来的地址发给客户端,让客户端再根据这个地址去连接,客户端收到127.0.0.1这个地址,也使用/etc/hosts文件中localhost解析ip去连接,实际连接的是自己本身,当然也就不行了。
我把服务器的IP地址加到服务器的/etc/hosts文件中,并放在127.0.0.1之前,以让该服务能先解析到这个IP,从而正确解析出来机器名所对应的IP。
机器的实际IP为192.168.0.77,则可以添加以下内容
192.168.0.77 77Linux localhost


17:46:09,496 ERROR [STDERR] 2018-8-10 17:46:09 net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator writeReplicationQueue
警告: Unable to send message to remote peer. Message was: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
at net.sf.ehcache.distribution.RMICachePeer_Stub.send(Unknown Source)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.writeReplicationQueue(RMIAsynchronousCacheReplicator.java:314)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.replicationThreadMain(RMIAsynchronousCacheReplicator.java:127)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator.access$000(RMIAsynchronousCacheReplicator.java:58)
at net.sf.ehcache.distribution.RMIAsynchronousCacheReplicator$ReplicationThread.run(RMIAsynchronousCacheReplicator.java:389)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory.createSocket(ConfigurableRMIClientSocketFactory.java:70)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 8 more

就在我百思不得其解时,各种尝试,在确定ehcache.xml配置都是正确的情况下,我终于发现是web容器jboss的坑。我换成以前的jboss-4.0.5.GA版本,问题就解决了。两个实例之间彼此之间终于可以同步数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值