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 地址