English 中文(简体)
确立多标准事例
  • 时间:2024-11-03

Hazelcast - Setting up multi node instances


Previous Page Next Page  

鉴于Hazelcast是一个分布式的IMDG,而且通常以多台机器安装,因此需要进入内部/外部网络。 最重要的使用案例是发现一个组群内的哈兹尔群岛 no子。

Hazelcast需要以下港口——

    1个港口,接收来自其他哈兹尔预报点/客户的纸浆/数据

    n 须向该组其他成员发送纸浆/数据的外部港口数目。

这种发现很少发生:

    使用多种语文

    TCP/IP

    亚马孙中心2

Of this, we will look at 使用多种语文 and TCP/IP

使用多种语文

使用多种语文 joining mechanism is enabled by default. https://en.wikipedia.org/wiki/使用多种语文 is a way of communication form in which message is transmitted to all the nodes in a group. And this is what Hazelcast uses to discover other members of the cluster. All the examples that we have looked at earper use multicast to discover members.

Example

我现在要明确谈谈这个问题。 Save the following in hazelcast-multicast.xml


<hazelcast
   xsi:schemaLocation="http://www.hazelcast.com/schema/config
   http://www.hazelcast.com/schema/config/hazelcast-config-3.12.12.xsd"
   xmlns="http://www.hazelcast.com/schema/config"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <network>
      <join>
         <multicast enabled="true" />
      </join>
   </network>
</hazelcast>

那么,让我们执行以下行动:


java -Dhazelcast.config=hazelcast-multicast.xml -cp .	argetdemo-0.0.1-
SNAPSHOT.jar com.example.demo.XMLConfigLoadExample

Output

在产出中,我们注意到哈兹尔群岛的以下线,这实际上意味着多台广播公司被用来发现成员。


Jan 30, 2021 5:26:15 PM com.hazelcast.instance.Node
INFO: [localhost]:5701 [dev] [3.12.12] Creating 使用多种语文Joiner

使用多种语文, by default, accepts communication from all the machines in the multicast group. This may be a security concern and that is why typically, on-premise, multicast communication is firewalled. So, while multicast is good for development work, in production, it is best to use TCP/IP based discovery.

TCP/IP

Due to the drawbacks stated for 使用多种语文, TCP/IP is the preferred way for communication. In case of TCP/IP, a member can connect to only known/psted members.

Example

让TCP/IP用于发现机制。 Save the following in hazelcast-tcp.xml


<hazelcast
   xsi:schemaLocation="http://www.hazelcast.com/schema/config
   http://www.hazelcast.com/schema/config/hazelcast-config-3.12.12.xsd"
   xmlns="http://www.hazelcast.com/schema/config"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <network>
      <join>
         <multicast enabled="false" />
         <tcp-ip enabled="true">
            <members>localhost</members>
         </tcp-ip>
      </join>
   </network>
</hazelcast>

那么,让执行以下指挥系统:


java -Dhazelcast.config=hazelcast-tcp.xml -cp .	argetdemo-0.0.1-SNAPSHOT.jar
com.example.demo.XMLConfigLoadExample

Output

output:


INFO: [localhost]:5701 [dev] [3.12.12] Creating TcpIpJoiner
Jan 30, 2021 8:09:29 PM
com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl

以上产出显示,TCP/IP加入公司是为了加入两个成员。

如果你在指挥两枚不同的炮弹后执行——


java  -Dhazelcast.config=hazelcast-tcp.xml  -cp .	argetdemo-0.0.1-SNAPSHOT.jar
com.example.demo.MultiInstanceHazelcastExample

我们看到以下产出:


Members {size:2, ver:2} [
   Member [localhost]:5701 - 62eedeae-2701-4df0-843c-7c3655e16b0f
   Member [localhost]:5702 - 859c1b46-06e6-495a-8565-7320f7738dd1 this
]

上述产出意味着,这些节点能够加入使用TCP/IP,而这两个节点都使用当地东道方作为IP地址。

请注意,我们可以在XML组合档案中具体说明更多的IP或机器名称(将由英国航天中心解决)。


<hazelcast
   xsi:schemaLocation="http://www.hazelcast.com/schema/config
   http://www.hazelcast.com/schema/config/hazelcast-config-3.12.12.xsd"
   xmlns="http://www.hazelcast.com/schema/config"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <network>
      <join>
         <multicast enabled="false" />
         <tcp-ip enabled="true">
            <members>machine1, machine2....</members>
         </tcp-ip>
      </join>
   </network>
</hazelcast>
Advertisements