注册中心
服务简码
HREG
默认端口
8000
组件编码
hzero-register
简介
.1 概述
基于Eureka的平台注册中心服务
.2 组件坐标
<dependency>
<groupId>org.hzero</groupId>
<artifactId>hzero-register</artifactId>
<version>${hzero.service.version}</version>
</dependency>
.3 主要功能
- 服务注册发现
- 服务健康检查
- 服务监控
- 注册中心其他功能
服务配置
.1 Eureka 版本配置
eureka:
client:
# 检索服务选项,注册中心不需要检索服务
fetch-registry: false
# 注册中心将自己作为客户端来尝试注册自己,注册中心集群环境下需开启此配置
register-with-eureka: false
serviceUrl:
# 注册中心地址,集群时,用逗号分隔多个地址
defaultZone: http://dev.hzero.org:8000/eureka
registryFetchIntervalSeconds: 10
server:
# Eureka server 清理无效节点的时间间隔,默认60000毫秒,即60秒
evictionIntervalTimerInMs: 4000
# 自我保护模式,当出现出现网络分区、eureka在短时间内丢失过多客户端时,会进入自我保护模式。
# 即一个服务长时间没有发送心跳,eureka 也不会将其删除,默认为true。
# 自我保护模式是一种应对网络异常的安全保护措施。开启自我保护模式可以让Eureka集群更加的健壮、稳定
enable-self-preservation: false
.2 启动类配置
register 的启动类上需排除 SecurityAutoConfiguration 配置类,因为注册中心不需要 Security 安全配置。
@EnableHZeroRegister
@EnableEurekaServer
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
public class RegisterApplication {
public static void main(String[] args) {
SpringApplication.run(RegisterApplication.class, args);
}
}
.3 高可用注册中心配置
-
注册中心配置
eureka: instance: # 配置 hostname hostname: peer1 # 多注册中心时,注册中心需以 hostname 形式互相注册 preferIpAddress: false instance-id: ${eureka.instance.hostname}:${server.port} client: # 设置为 true,需拉取其它注册中心的实例 fetch-registry: true # 设置为 true,注册中心也将作为客户端注册到其它注册中心 register-with-eureka: true serviceUrl: # 配置其它注册中心的地址,多个以逗号隔开 defaultZone: http://peer2:8010/eureka/,http://peer3:8020/eureka/
-
服务客户端配置
eureka: client: serviceUrl: # 注册中心地址 defaultZone: http://peer1:8000/eureka/,http://peer2:8010/eureka/,http://peer3:8020/eureka/
-
多注册中心