当前位置: 首页 > 工具软件 > Hazelcast > 使用案例 >

HazelCast独立集群配置

澹台华采
2023-12-01

HazelCast

独立配置成集群

配置文件hazelcast.xml,默认配置:

Specifies the name and password for a cluster group you connect to.
Cluster groups allow you to create separate sub-cluster with different
names. The password is only checked when security is enabled on
Hazelcast members (Enterprise edition feature)

group:
	name: dev
	password: dev-pass

若想要hazelcast成群,node之间需要配置为相同的group name。

when Hazelcast instances are created, they are put in a global
registry with their creation names. “instance-name” gives you the
ability to get a specific Hazelcast instance from this registry by
giving the instance’s name.

instance-name: CLIENT_NAME

集群发现
Tcp机制发现集群
1、设置节点下除了以外的其他所有节点的设置enabled为false。
2、设置节点下节点的属性enabled为true
3、设置节点下为需要绑定的本机ip地址。
4、为集群中已启动节点的ip, 可只设置其中一个节点的ip。第一个启动的节点可配置为自己的ip地址。


```yaml
 hazelcast:
  #  serialization:
  #    serializers:
  #      - type-class: tech.deepq.info.common.message.ItemMessage
  #        class-name: info.jerrinot.subzero.Serializer

  network:
    join:
      multicast:
        enabled: false
      tcp-ip:
        enabled: true
#        interface: 127.0.0.1
#        required-member: 127.0.0.1:5701
#        member-list:
#          - 127.0.0.1:5751
#          - 127.0.0.1:5752
#          - 127.0.0.1:5753

如上文的第4点,member list 可以写入具体的节点地址。如果能用一些手段自动获取到部署的节点ip, 想更灵活一些可以不配置, 自动解析出ip端口后可以调用以下方法自动成群

config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(instance.getHost() + ":" + port) 
 类似资料: