1、Eureka是Netflix開發的服務組件java
自己是一個基於REST的服務,Spring Cloud將它集成在其子項目spring-cloud-netflix中,以實現Spring cloud的服務發現功能git
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
2、Eureka主要概念github
一、Eureka使用了AWS裏的區域(Region)和可用區(Availability Zone,AZ)spring
二、Eureka架構圖安全
Register:服務註冊架構
Renew:服務的續期app
Cancel:服務下線(客戶端主動發起)spring-boot
Eviction:服務剔除(90秒)微服務
Application Serivce:服務生產者fetch
Application Client:服務消費者
us-east-1c:美東區域
3、Eureka在微服務中的應用
一、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
二、啓動類增長註解@EnableEurekaServer
#加入spring cloud父POM及spring-cloud-starter-eureka-server <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency>
三、爲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