我们使用spring-session-hazelcast + hazelcast-kubernetes在OpenShift/Kubernetes集群上部署了一个spring-boot应用程序。
由于我们平台的性质,我们只能使用service-dns配置。我们在端口5701上公开一个用于多播的服务,并将service-dns属性设置为多播服务名称。
下面是用于创建Hazelcast实例的代码片段。
@Bean
public HazelcastInstance hazelcastInstance() {
var config = new Config();
config.setClusterName("spring-session-cluster");
var join = config.getNetworkConfig().getJoin();
join.getTcpIpConfig().setEnabled(false);
join.getMulticastConfig().setEnabled(false);
join.getKubernetesConfig().setEnabled(true)
.setProperty("service-dns", "<multicast-service-name>");
var attribute = new AttributeConfig()
.setName(Hazelcast4IndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
.setExtractorClassName(Hazelcast4PrincipalNameExtractor.class.getName());
config.getMapConfig(Hazelcast4IndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
.addAttributeConfig(attribute)
.addIndexConfig(new IndexConfig(IndexType.HASH, Hazelcast4IndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
var serializer = new SerializerConfig();
serializer.setImplementation(new HazelcastSessionSerializer())
.setTypeClass(MapSession.class);
config.getSerializationConfig().addSerializerConfig(serializer);
return Hazelcast.newHazelcastInstance(config);
}当我们为这个应用程序运行2个pods时,我们会看到以下错误日志:
com.hazelcast.internal.cluster.impl.operations.SplitBrainMergeValidationOp
Message: [<private-ip>]:5701 [spring-session-cluster] [4.2] Target is this node! -> [<private-ip>]:5701有人能解释一下如何修复这个错误,仍然使用"service-dns“配置吗?
发布于 2021-06-10 06:03:47
只需添加分裂脑保护配置即可
SplitBrainProtectionConfig splitBrainProtectionConfig = new SplitBrainProtectionConfig();
splitBrainProtectionConfig.setName("splitBrainProtectionRuleWithFourMembers")
.setEnabled(true)
.setMinimumClusterSize(4);
MapConfig mapConfig = new MapConfig();
mapConfig.setSplitBrainProtectionName("splitBrainProtectionRuleWithFourMembers");
Config config = new Config();
config.addSplitBrainProtectionConfig(splitBrainProtectionConfig);
config.addMapConfig(mapConfig);您可以在hazelcast文档中阅读更多信息:https://docs.hazelcast.com/imdg/4.2/network-partitioning/split-brain-protection.html
发布于 2021-06-11 20:00:47
您需要在openshift中为您的服务启用无头模式。
https://github.com/hazelcast/hazelcast-kubernetes#dns-lookup
https://stackoverflow.com/questions/67886031
复制相似问题