1. Eureka configuration :
multiple registration centers need to register with each other.
Registration Center:
server:
port: 7001
spring:
application:
name: cloud-eureka
eureka:
instance:
hostname: eureka.com #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己。
fetch-registry: false #false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
service-url:
#集群指向其它eureka
defaultZone: http://localhost:7002/eureka/
#server:
#关闭自我保护机制,保证不可用服务被及时踢除
#enable-self-preservation: false
#eviction-interval-timer-in-ms: 2000
The @EnableEurekaServer annotation needs to be added to the startup class of the registry.
Server configuration:
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true。
register-with-eureka: true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetchRegistry: true
service-url:
#单机版
# defaultZone: http://localhost:7001/eureka
# 集群版
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
# instance:
# instance-id: payment8001
# #访问路径可以显示IP地址
# prefer-ip-address: true
#Eureka客户端向服务端发送心跳的时间间隔,单位为秒(默认是30秒)
#lease-renewal-interval-in-seconds: 1
#Eureka服务端在收到最后一次心跳后等待时间上限,单位为秒(默认是90秒),超时将剔除服务
#lease-expiration-duration-in-seconds: 2
The startup class of the server needs to be annotated with @EnableEurekaClient
2.
Why does Eureka's self-protection mechanism produce Eureka's self-protection mechanism?
In order to prevent EurekaClient from being able to run normally, but the EurekaServer network is disconnected, EurekaServer will not immediately remove the EurekaClient service.
What is self-protection mode?
By default, if EurekaServer does not receive the heartbeat of a microservice instance within a certain period of time, EurekaServer will log out the instance (90 seconds by default). But when a network partition failure occurs (delay, freeze, congestion), the microservice and EurekaServer cannot communicate normally, the above behavior may become very dangerous-because the microservice itself is healthy, but This microservice should not be unregistered at this time. Eureka uses the "self-protection mode" to solve this problem-when the EurekaServer node loses too many clients in a short period of time (network partition failure may occur), then this node will enter the self-protection mode.
Eureka In the self-protection mode, Eureka will protect the information in the service registry and will not log out any microservice information. (It belongs to the design idea of AP in CAP)
The self-protection mechanism is turned on by default in Eureka, and the configuration is closed as follows:
eureka server (Registration Center)
eureka:
server:
enable-self-preservation: false # 关闭自我保护模式(缺省为打开)
eviction-interval-timer-in-ms: 5000 # 续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms)
eureka client (server)
eureka:
instance:
lease-renewal-interval-in-seconds: 5 # 心跳时间,即服务续约间隔时间(缺省为30s)
lease-expiration-duration-in-seconds: 10 # 发呆时间,即服务续约到期时间(缺省为90s)
client:
healthcheck:
enabled: true # 开启健康检查(依赖spring-boot-starter-actuator)
Eureka 2.0 will not be updated