Eureka-服务注册与发现组件

时间:2022-10-14 15:50:15

一、Eureka是Netflix开发的服务组件

  本身是一个基于REST的服务,Spring Cloud将它集成在其子项目spring-cloud-netflix中,以实现Spring cloud的服务发现功能

  Eureka-服务注册与发现组件

Eureka 他的源码在github上面:
https://github.com/Netflix/eureka/
他的文档:
https://github.com/Netflix/eureka/wiki
他的架构介绍:High level architecture:
https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance

二、Eureka主要概念

  1、Eureka使用了AWS里的区域(Region)和可用区(Availability Zone,AZ)

  Eureka-服务注册与发现组件

2、Eureka架构图

  Eureka-服务注册与发现组件

  Register:服务注册

  Renew:服务的续期

  Cancel:服务下线(客户端主动发起)

  Eviction:服务剔除(90秒)

  Application Serivce:服务生产者

  Application Client:服务消费者

us-east-1c:美东区域

三、Eureka在微服务中的应用

  1、Application.properties:

server.port=8761
#取消向eureka server(注册中心)注册
eureka.client.register-with-eureka=false
#取消向eureka server(注册中心)获取注册信息
eureka.client.fetch-registry=false
#eureka 提供服务发现的地址
eureka.client.service-url.defaultZone=http://localhost:8761/eureka

  2、启动类增加注解@EnableEurekaServer

#加入spring cloud父POM及spring-cloud-starter-eureka-server
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>

  3、为Eureka增加安全访问

    a、EurekaServer中:pom.xml

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

    b、EurekaServer中:application.properties

#eureka 提供服务发现的地址
eureka.client.service-url.defaultZone=http://zhy:777@localhost:8761/eureka
#eureka.client.service-url.defaultZone=http://localhost:8761/eureka
# 安全模块
security.basic.enabled=true
security.user.name=zhy
security.user.password=777