使用cache.xml

时间:2016-02-05 20:51:57

标签: java xml gemfire

如何在cache.xml配置文件中仅使用静态定义的服务器列表来创建GemFire服务器的GemFire 8.2.0 P2P集群?

我无法使用多播。我不想使用单独的定位器过程。

我的服务器节点cache.xml

<!DOCTYPE cache PUBLIC
"-//GemStone Systems, Inc.//GemFire Declarative Caching 8.0//EN"
"http://www.gemstone.com/dtd/cache8_0.dtd">
<cache>
  <cache-server port="40404" />
  <pool name="serverPool">
      <server host="10.0.0.192" port="40404" />
      <server host="10.0.0.193" port="40404" />
  </pool>
</cache>

我在文档中读到我可以在池中有一个静态的服务器列表,我在客户端看到,这种配置方式有效。我的客户端连接到服务器列表。 但是,仅使用静态集群配置的GemFire服务器/对等集群对我来说不起作用。

我现在正在使用 serverCache = new CacheFactory().set("cache-xml-file", "server-cache.xml").set("mcast-port", "0") .set("start-locator","localhost[13489]").set("locators", "localhost[13489]").create();

在这个jmv的日志中我看到了

``` [info 2016/02/08 15:47:34.922 UTC tid = 0x1]在localhost / 127.0.0.1上启动分发定位器的对等位置[13489]

[info 2016/02/08 15:47:34.925 UTC tid = 0x1]在localhost / 127.0.0.1上启动分发定位器[13489]

[info 2016/02/08 15:47:48.093 UTC tid = 0x1]在localhost / 127.0.0.1上启动分发定位器的服务器位置[13489] ```

在我使用的第二个盒子上

serverCache = new CacheFactory().set("cache-xml-file", "server-cache.xml").set("mcast-port", "0").set("locators", "IP-of-1stbox[13489]").create();

com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[ip-of-1stbox(null)<v0>:13489]". at com.gemstone.org.jgroups.protocols.TCPGOSSIP.sendGetMembersRequest(TCPGOSSIP.java:222) at com.gemstone.org.jgroups.protocols.PingSender.run(PingSender.java:85) at java.lang.Thread.run(Thread.java:745) Exception in thread "main" com.gemstone.gemfire.GemFireConfigException: Unable to contact a Locator service. Operation either timed out or Locator does not exist. Configured list of locators is "[54.173.123.102(null)<v0>:13489]". at com.gemstone.org.jgroups.protocols.TCPGOSSIP.sendGetMembersRequest(TCPGOSSIP.java:222) at com.gemstone.org.jgroups.protocols.PingSender.run(PingSender.java:85) at java.lang.Thread.run(Thread.java:745)

我打开13489端口

我可以看到 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN - tcp 0 0 ::ffff:127.0.0.1:13489 :::* LISTEN 5137/java tcp 0 0 :::40404 :::* LISTEN 5137/java tcp 0 0 :::22 :::* LISTEN - tcp 0 0 ::ffff:10.0.0.193:21145 :::* LISTEN 5137/java tcp 0 0 ::ffff:10.0.0.193:65148 :::* LISTEN 5137/java udp 0 0 0.0.0.0:68 0.0.0.0:* - udp 0 0 10.0.0.193:123 0.0.0.0:* - udp 0 0 127.0.0.1:123 0.0.0.0:* - udp 0 0 0.0.0.0:123 0.0.0.0:* - udp 0 0 ::ffff:10.0.0.193:2300 :::* 5137/java

端口13489正在第一个框中使用

当我确实连接它时我发现了这个

[warn 2016/02/08 16:38:12.688 UTC <locator request thread[1]> tid=0x20] Expected one of these: [class com.gemstone.gemfire.cache.client.internal.locator.LocatorListRequest, class com.gemstone.gemfire.management.internal.JmxManagerLocatorRequest, class com.gemstone.gemfire.cache.client.internal.locator.ClientReplacementRequest, class com.gemstone.gemfire.cache.client.internal.locator.QueueConnectionRequest, class com.gemstone.org.jgroups.stack.GossipData, class com.gemstone.gemfire.cache.client.internal.locator.ClientConnectionRequest, class com.gemstone.gemfire.cache.client.internal.locator.LocatorStatusRequest, class com.gemstone.gemfire.cache.client.internal.locator.GetAllServersRequest] but received ConfigurationRequest for groups : cluster[cluster]

2 个答案:

答案 0 :(得分:1)

您可以使用start-locator gemfire属性在嵌入模式下启动定位器(即在GemFire Server进程内。)

一种方法是:

  1. start-locator=address1[port1]放入gemfire.properties文件。
  2. 使用

    启动服务器

    gfsh&gt;启动服务器--name = server1 --properties-file = / path / to / gemfire.properties

  3. 通过将第二台服务器指向第一台服务器中的定位器端口来启动第二台服务器:

    gfsh&gt;启动服务器--name = server2 --locators = address1 [port1]

答案 1 :(得分:1)

cache.xml中有混淆。您将需要两组cache.xml,一组用于服务器,一组用于客户端。在服务器cache.xml上,您可以定义服务器将侦听客户端通信的端口,定义您的区域等。如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<cache
    xmlns="http://schema.pivotal.io/gemfire/cache"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schema.pivotal.io/gemfire/cache http://schema.pivotal.io/gemfire/cache/cache-8.1.xsd"
    version="8.1">
<cache-server port="40404" />
<region name="MyRegion" refid="PARTITION" />
</cache>

要启动嵌入式定位器并将服务器指向系统中其他正在运行的服务器,您可以执行

CacheFactory cf = new CacheFactory();
cf.set("cache-xml-file", "server-cache1.xml");
cf.set("mcast-port", "0");
cf.set("start-locator", "12345");
cf.set("locators","localhost[12345],localhost[6789]");

在第二个过程中,使用完全相同的locators属性,并使用6789作为start-locator端口。

对于客户端cache.xml,您可以定义连接池并为其提供正在运行的服务器列表:

<?xml version="1.0" encoding="UTF-8"?>
<client-cache
    xmlns="http://schema.pivotal.io/gemfire/cache"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schema.pivotal.io/gemfire/cache http://schema.pivotal.io/gemfire/cache/cache-8.1.xsd"
    version="8.1">
<pool name="serverPool">
  <server host="localhost" port="40404" />
  <server host="localhost" port="40405" />
</pool>
<region name="MyRegion" refid="CACHING_PROXY"/>
</client-cache>

对于您的客户端应用程序,您应该使用上面的cache.xml创建ClientCache,如下所示:

ClientCacheFactory ccf = new ClientCacheFactory();
ccf.set("cache-xml-file", "client.xml");
ClientCache clientCache = ccf.create();
Region r = clientCache.getRegion("MyRegion");
r.put("1", "one");