Java 设置 ehcache 复制 - 我需要什么多播设置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/884760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:39:56  来源:igfitidea点击:

Setting up ehcache replication - what multicast settings do I need?

javaehcachemulticast

提问by Darren Greaves

I am trying to set up ehcache replication as documented here: http://ehcache.sourceforge.net/EhcacheUserGuide.html#id.s22.2
This is on a Windows machine but will ultimately run on Solaris in production.

我正在尝试按照此处记录的方式设置 ehcache 复制:http: //ehcache.sourceforge.net/EhcacheUserGuide.html#id.s22.2
这是在 Windows 机器上,但最终将在 Solaris 上运行。

The instructions say to set up a provider as follows:

说明说设置提供程序如下:

 <cacheManagerPeerProviderFactory
     class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
     properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
     multicastGroupPort=4446, timeToLive=32"/>

And a listener like this:

还有这样的听众:

<cacheManagerPeerListenerFactory
    class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
    properties="hostName=localhost, port=40001,
    socketTimeoutMillis=2000"/>

My questions are:
Are the multicast IP address and port arbitrary (I know the address has to live within a specific range but do they have to be specific numbers)?
Do they need to be set up in some way by our system administrator (I am on an office network)?

我的问题是:
多播 IP 地址和端口是否是任意的(我知道地址必须位于特定范围内,但它们是否必须是特定数字)?
它们是否需要由我们的系统管理员以某种方式设置(我在办公网络上)?

I want to test it locally so am running two separate tomcat instances with the above config. What do I need to change in each one? I know both the listeners can't listen on the same port - but what about the provider?
Also, are the listener ports arbitrary too?

我想在本地测试它,所以我使用上述配置运行两个单独的 tomcat 实例。每一项我需要改变什么?我知道两个侦听器不能在同一个端口上侦听 - 但是提供者呢?
此外,侦听器端口也是任意的吗?

I've tried setting it up as above but in my testing the caches don't appear to be replicated - the value added in one tomcat's cache is not present in the other cache.
Is there anything I can do to debug this situation (other than packet sniffing)?

我已经尝试按照上面的方式进行设置,但是在我的测试中,缓存似乎没有被复制 - 在一个 tomcat 的缓存中添加的值在另一个缓存中不存在。
我可以做些什么来调试这种情况(除了数据包嗅探)?

Thanks in advance for any help, been tearing my hair out over this one!

在此先感谢您的任何帮助,我一直在为这个而烦恼!

采纳答案by Steffen Opel

I want to test it locally so am running two separate tomcat instances with the above config.

我想在本地测试它,所以我使用上述配置运行两个单独的 tomcat 实例。

As I have just submitted an answer regarding cherouvims related questionI'd just like to highlight here too that they are in fact providing an example doing something similar at least (multiple nodes per host, though one instance only): see section Full Examplein the RMI Distributed Cachingdocumentation.

正如我刚才提交了关于cherouvims回答相关问题,我只是想在这里也以突出它们实际上是提供了一个例子至少做类似的事情(每个主机多个节点,虽然只有一个实例):见完整的例子在在RMI分布式缓存文件。

It's indeed important to change the TCP port for each cacheManagerPeerListenerFactorybut the multicast settings can (I'd think they must) stay the same: you can see this in action within the ehcache.xml'sfor the Full Examplementioned above: the port number is increased one by one from 40001 up to 40006 per node while the multicast settings stay identical.

为每个端口更改 TCP 端口确实很重要,cacheManagerPeerListenerFactory但多播设置可以(我认为它们必须)保持不变:您可以在上面提到的完整示例ehcache.xml 中看到这一点:端口号增加每个节点从 40001 到 40006 一个接一个,而多播设置保持不变。

If you have obeyed that, your problem might just be related to Tomcat running on Windows - see the related paragraph within section Common Problemsin RMI Distributed Caching:

如果你听从的是,您的问题可能只是在Windows上运行相关的Tomcat -见内相关段落的常见问题RMI分布式缓存

There is a bug in Tomcat and/or the JDK where any RMI listener will fail to start on Tomcat if the installation path has spaces in it.
[...]
As the default on Windows is to install Tomcat in "Program Files", this issue will occur by default.

Tomcat 和/或 JDK 中存在一个错误,如果安装路径中有空格,则任何 RMI 侦听器都将无法在 Tomcat 上启动。
[...]
由于 Windows 上的默认设置是在“程序文件”中安装 Tomcat,因此默认情况下会出现此问题。

回答by Gandalf

Make sure your servers have multicast enabled for starters. Not sure what platform you are running on.

确保您的服务器为初学者启用了多播。不确定您在哪个平台上运行。

回答by Darren Greaves

Just as a quick follow-up.

就像快速跟进一样。

We did get this working with two separate machines which solved the original problem of getting it to work at all. As far as I recall Multicast should work "out of the box" but it's worth checking with your local sysadmin (ours suggested a tweak to the multicastGroupAddress).

我们确实使用两台独立的机器完成了这项工作,这完全解决了让它工作的原始问题。据我回忆,多播应该“开箱即用”,但值得与您的本地系统管理员核对(我们建议对多播组地址进行调整)。

We eventually hit all sorts of problems on Solaris and ended up abandoning multicast for Manual Peer Discoveryinstead.

我们最终在 Solaris 上遇到了各种各样的问题,最终放弃了多播,转而使用手动对等发现

Finally, in terms of debugging, using jconsole to monitor cache values proved to be the best way to do it. Didn't have to resort to packet sniffing. :-)

最后,在调试方面,使用 jconsole 监控缓存值被证明是最好的方法。不必求助于数据包嗅探。:-)

回答by Roshan Kulkarni

One mistake I encountered during EHCache peer replication. This might be useful so someone attempting peer replication on a single local box.

我在 EHCache 对等复制过程中遇到的一个错误。这可能很有用,因此有人尝试在单个本地机器上进行对等复制。

I wanted to run 3 peer-replicated instances of EhCache on a single Windows Vista box using peerDiscovery=automatic (the eventual target environment was Linux).

我想使用 peerDiscovery=automatic(最终目标环境是 Linux)在单个 Windows Vista 机器上运行 EhCache 的 3 个对等复制实例。

The peer-replication did not work. Oddly, all EhCache instances were starting-up without any errors or complaints in the log.

对等复制不起作用。奇怪的是,所有 EhCache 实例都在启动,日志中没有任何错误或抱怨。

Took me a while to figure my mistake; without anything in the logs I had to grok around: I was using the same listenerPort (40001) in the peer listener configuration for each of the EhCache instances. Using different listenerPorts (40001, 40002...) did the trick.

我花了一段时间才弄明白我的错误;日志中没有任何内容,我不得不摸索:我在每个 EhCache 实例的对等侦听器配置中使用相同的 listenerPort (40001)。使用不同的 listenerPorts (40001, 40002 ...) 可以解决问题。

<cacheManagerPeerListenerFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
properties="port=40001, socketTimeoutMillis=3000"/>

<cacheManagerPeerListenerFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
properties="port=40002, socketTimeoutMillis=3000"/>

Note that this is the 'peer listener' configuration that needed different port numbers. The multicast 'peer discovery' still uses identical multicast address and port numbers for every ehcache instance.

请注意,这是需要不同端口号的“对等侦听器”配置。多播“对等发现”仍然为每个 ehcache 实例使用相同的多播地址和端口号。

回答by Jeryl Cook

 <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/>

just doing the above, ehcache will use the next available one ! So you don't have to worry about configuration on new nodes that you want to deploy in the cluster.

只需执行上述操作,ehcache 将使用下一个可用的!因此,您不必担心要在集群中部署的新节点上的配置。

回答by Jajikanth pydimarla

May help Someone implementing multicasting. I have verified by running my app in my local tomcat from eclipse and running the same app in the local tomcat from eclipse of my colleague.

可以帮助某人实现多播。我已经通过在我的本地 tomcat 中从 eclipse 运行我的应用程序并在我同事的 eclipse 中在本地 tomcat 中运行相同的应用程序进行了验证。

Running below on your Windows Machine will show you some ips and ensures that multi-casting should work.

在您的 Windows 机器上运行下面将显示一些 ips 并确保多播应该工作。

netsh interface ip show joins

the attribute multicastGroupAddress=230.0.0.1 means that your application want to use this IP, this can be changed but ensure to use the Class D IP Range only. After running your application, you could see this IP 230.0.0.1 Also in as below enter image description here

属性 multicastGroupAddress=230.0.0.1 表示您的应用程序想要使用此 IP,这可以更改,但请确保仅使用 D 类 IP 范围。运行您的应用程序后,您可以看到这个 IP 230.0.0.1 也如下所示 在此处输入图片说明

To see all magics, ensure to enable logs properly.

要查看所有魔法,请确保正确启用日志。

    <logger name="net.sf.ehcache">  <level value="debug"/></logger>
   <logger name="net.sf.ehcache.distribution.RMICachePeer" level="debug" />

Ensure to Have below lisners in your default cache or required cache configuration

确保在您的默认缓存或所需的缓存配置中有以下 lisner

         <cacheManagerPeerProviderFactory
       class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
       properties="port=40003, peerDiscovery=automatic,
                   multicastGroupAddress=230.0.0.1,
                   multicastGroupPort=4446,
                   timeToLive=32"/>
    <cacheManagerPeerListenerFactory 
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="port=40001, socketTimeoutMillis=3000" />
    <cacheManagerPeerListenerFactory 
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" 
        properties="port=40002, socketTimeoutMillis=3000"/>
 <defaultCache
     eternal="false"
     timeToIdleSeconds="300"
     timeToLiveSeconds="300"
     diskExpiryThreadIntervalSeconds="305"
     memoryStoreEvictionPolicy="LRU"
     statistics="true">
     <persistence strategy="localTempSwap"/>
     <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/>
     <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"/>
        </defaultCache>

After Deploying the application you could see below in logs

部署应用程序后,您可以在日志中看到以下内容

13:31:27.073  DEBUG n.s.e.d.PayloadUtil assembleUrlList - Cache peers for this CacheManager to be advertised:......
15:15:14.110  DEBUG net.sf.ehcache.distribution.MulticastKeepaliveHeartbeatReceiver processPayload rmiUrls received....(YOur configured caches with Ips)

Which will be helpfull if you need to configure manual peer discovery process.

如果您需要配置手动对等发现过程,这将很有帮助。