本文共 3068 字,大约阅读时间需要 10 分钟。
定义:Eureka 是 Netflix 开发的,一个基于 REST 服务的,服务注册与发现的组件
它主要包括两个组件:Eureka Server 和 Eureka Client Eureka Client:一个Java客户端,用于简化与 Eureka Server 的交互(通常就是微服务中的客户端和服务端) Eureka Server:提供服务注册和发现的能力(通常就是微服务中的注册中心)server:
port: 8761 eureka: instance: lease-renewal-interval-in-seconds: 60 #每间隔1s,向服务端发送一次心跳,代表我还活着 lease-expiration-duration-in-seconds: 30 # 2s之内没有给你发心跳,就代表我“死”了,将我剔除 hostname: localhost server: enable-self-preservation: false # 测试时关闭自我保护机制,保证不可用服务及时踢出 client: register-with-eureka: false #防止eureak自己注册自己 fetch-registry: true #因为这是一个单点的EurekaServer,不需要同步其它EurekaServer节点的数据,故设为false service-url: defaultZone: http:// e u r e k a . i n s t a n c e . h o s t n a m e : {eureka.instance.hostname}: eureka.instance.hostname:{server.port}/eureka/#指定环境
eureka.environment=work 设置是否将自己作为客户端注册到注册中心(缺省true) 这里为不需要(查看@EnableEurekaServer注解的源码,会发现它间接用到了@EnableDiscoveryClient) eureka.client.register-with-eureka=false 设置是否从注册中心获取注册信息(缺省true) 因为这是一个单点的EurekaServer,不需要同步其它EurekaServer节点的数据,故设为false eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/ #是否开启自我保护模式,默认为true。 eureka.server.enable-self-preservation=true #续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms) eureka.server.eviction-interval-timer-in-ms=10000eureka:
client: serviceUrl: defaultZone: http://localhost:8761/eureka/eureka.client.serviceUrl.defaultZone=http://localhost:8081/eureka/
服务端地址 eureka.instance.instance-id= s p r i n g . a p p l i c a t i o n . n a m e : {spring.application.name}: spring.application.name:{server.port} 设置微服务调用地址为IP优先(缺省为false) eureka.instance.prefer-ip-address=true 心跳时间,即服务续约间隔时间(缺省为30s) eureka.instance.lease-renewal-interval-in-seconds=30 发呆时间,即服务续约到期时间(缺省为90s) eureka.instance.lease-expiration-duration-in-seconds=90服务端:
org.springframework.cloud spring-cloud-starter-netflix-eureka-server
客户端:
org.springframework.cloud spring-cloud-starter-netflix-eureka-client 2.0.0.RELEASE
---server: port: 2001 context-path: /eureka: instance: hostname: eureka2001.lingerqi.com client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://eureka2002.lingerqi.com:2002/eureka/,http://eureka2003.lingerqi.com:2003/eureka/spring: profiles: eureka2001---server: port: 2002 context-path: /eureka: instance: hostname: eureka2002.lingerqi.com client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://eureka2001.lingerqi.com:2001/eureka/,http://eureka2003.lingerqi.com:2003/eureka/spring: profiles: eureka2002---server: port: 2003 context-path: /eureka: instance: hostname: eureka2003.lingerqi.com client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://eureka2001.lingerqi.com:2001/eureka/,http://eureka2002.lingerqi.com:2002/eureka/spring: profiles: eureka2003
转载地址:http://nqul.baihongyu.com/