springcloud 配置⽂件 application.yml,相關配置說明
Eureka Server 的yml 配置:
server:
port: 80
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:80/eureka/
屬性說明
server.port :當前 Eureka Server 服務端⼝。
eureka.client.register-with-eureka :是否將當前的 Eureka Server 服務作爲客戶端進⾏註冊。
eureka.client.fetch-fegistry :是否獲取其他 Eureka Server 服務的數據。
eureka.client.service-url.defaultZone :註冊中⼼的訪問地址。
提供服務者 yml 配置:
server:
port: 8010
spring:
application:
name: provider
eureka:
client:
service-url:
defaultZone: http://localhost:80/eureka/
instance:
prefer-ip-address: true
屬性說明:
spring.application.name :當前服務註冊在 Eureka Server 上的名稱。
eureka.client.service-url.defaultZone :註冊中⼼的訪問地址。
eureka.instance.prefer-ip-address :是否將當前服務的 IP 註冊到 Eureka Server
註冊中心: yml 配置
server:
port: 8030
spring:
application:
name: gateway
eureka:
client:
service-url:
defaultZone: http://localhost:80/eureka/
zuul:
routes:
provider: /p/**
zuul.routes.provider :給服務提供者 provider 設置映射
服務熔斷,application.yml 添加熔斷機制。
feign.hystrix.enabled :是否開啓熔斷器。
Spring Cloud 配置中⼼
Spring Cloud Config,通過服務端可以爲多個客戶端提供配置服務。Spring Cloud Config 可以將配置
⽂件存儲在本地,也可以將配置⽂件存儲在遠程 Git 倉庫,創建 Config Server,通過它管理所有的配置
⽂件。
本地⽂件系統
server:
port: 8762
spring:
application:
name: nativeconfigserver
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/shared
註解說明
spring.profiles.active :配置⽂件的獲取⽅式
spring.cloud.config.server.native.search-locations :本地配置⽂件存放的路徑
resources 路徑下創建 shared ⽂件夾,並在此路徑下創建 configclient-dev.yml。
server:
port: 8070
foo: foo version 1
創建客戶端讀取本地配置中⼼的配置⽂件
spring:
application:
name: configclient
profiles:
active: dev
cloud:
config:
uri: http://localhost:8762
fail-fast: true
cloud.config.uri :本地 Config Server 的訪問路徑
cloud.config.fail-fase :設置客戶端優先判斷 Config Server 獲取是否正常。
通過 spring.application.name 結合 spring.profiles.active 拼接⽬標配置⽂件名,
configclient-dev.yml,去 Config Server 中查找該⽂件。
創建 Config Client:
spring:
cloud:
config:
name: configclient
label: master
discovery:
enabled: true
service-id: configserver
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
spring.cloud.config.name :當前服務註冊在 Eureka Server 上的名稱,與遠程倉庫的配置⽂件名
對應。
spring.cloud.config.label :Git Repository 的分⽀。
spring.cloud.config.discovery.enabled :是否開啓 Config 服務發現⽀持。
spring.cloud.config.discovery.service-id :配置中⼼在 Eureka Server 上註冊的名稱。
服務追蹤:
創建配置⽂件 application.yml
server:
port: 8090
spring:
application:
name: zipkinclient
sleuth:
web:
client:
enabled: true
sampler:
probability: 1.0
zipkin:
base-url: http://localhost:9090/
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
屬性說明
spring.sleuth.web.client.enabled :設置開啓請求跟蹤
spring.sleuth.sampler.probability :設置採樣⽐例,默認是 1.0
srping.zipkin.base-url :Zipkin Server 地址