springcloud配置参数说明

本文详细介绍了SpringCloud的关键配置,包括Eureka的服务发现,Zuul的网关设置,Ribbon的负载均衡策略,Hystrix的容错管理,以及Config的集群配置中心。通过这些配置,可以有效地构建和管理微服务架构。
摘要由CSDN通过智能技术生成

springcloud配置参数说明

1. eureka配置
server.port: 
#设置web项目服务端口号  

spring.application.name=eureka-service:  
#设置服务名称  

eureka.instance.hostname=localhost: 
#设置服务主机IP 

eureka.client.register-with-eureka: false  
#false:注册中心不需要注册自己。true(默认): 需要注册自己

eureka.client.fetch-registry: false  
#注册中心不需要去发现服务。true(默认): 需要发现服务

eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka:
#设置服务注册中心的URL,这里的${}是占位符。最终显示例如:http://localhost:1111/eureka

eureka.server.lease-expiration-duration-in-seconds:
#设置服务器多长时间没有收到心跳可以清理实例的时间,默认为90秒

eureka.server.lease-renewal-interval-in-seconds:
#设置客户端向服务器发送心跳周期,默认为30秒

eureka.server.eviction-interval-timer-in-ms:
#修改注册表的清理时间间隔,单位是毫秒,默认是60秒

eureka.server.enable-self-preservation: false 
#将值设置为 false 来关闭自我保护机制

hello-service.ribbon.ConnectTimeout: 500
#为某服务指定的负载均衡超时设置 @FeignClient(value="hello-service")


feign.compression.request.enabled: true
feigan.compression.response.enabled: true
#请求压缩配置,支持对请求和响应进行GZIP压缩,以减少通信过程中的性能损耗。


spring.cloud.config.server.git.uri: https://gitlab.com/xxx/xxx.git 
#配置仓库路径下的相对搜索位置,可以配置多个 

spring.cloud.config.server.git.search-paths: spring-cloud-config-file
#这里配置你的Git仓库的用户名

spring.cloud.config.server.git.username: xxx 
#这里配置你的Git仓库的密码

spring.cloud.config.server.git.password: 123SpringCloud
#自己创建的管理配置中心的服务端配置

spring.profiles.active: default
#指定服务运行什么配置,比如application-dev.properties,就设置值为dev

spring.cloud.config.server.encrypt.enabled: false
#显式关闭输出属性的解密。

spring.datasource.password: "{cipher}d495ce8603af9676450736e119"
#SpringCloud配置服务器要求所有已加密的属性前面加上{cipher}
2. Zuul(网关配置)
# 1. 动态加载过滤器配置

zuul.filter.root : "groovy/filters"
#动态过滤器的根目录

zuul.filter.refresh!nterval: 5
#刷新间隔,单位秒


# 2. 网关路由配置

zuu.routes.serviceid: zuul-sale-service
#路由到id为zuul-sale-service的服务进行处理请求

zuul.ignoredPatterns : /sale/noRoute
#忽略路由到 /sale/noRoute 路径

zuul.routes.api-a.path: /api-a/** 
zuul.routes.api-a.url: http://localhost:9001 zuul.routes.api-a.path: /api-a/** 
zuul.routes.api-a.serviceId: hello-service 
或 
zuul.routes.hello-service.path: /hello-service/** 
zuul.routes.hello-service.serviceId: hello-service

#请求示例:http://localhost:5555/api-a/feign-consumer 请到http://localhost:9001这个url地址找**(/feign-consumer)匹配的http接口,因为我把这个url的服务命名为api-a了。 推荐使用serviceId来代替url地址。
# 注意:zuul.routes.api-a.url=hello-service也能实现功能,但是它不能进行正常的负载均衡和容错保护。 不配置默认路由规则。当zuul.ignored-services=*的时候,所有的服务都不会自动创建路由规则,这个时候需要通过前面的配置进行相关路由配置了。

# 3. 禁用过滤器

zuul : 
  SendForwardFilter : 
	route: 
	  disable: true
#以上配置会将 ndForwardFilte 转路由的过滤器)禁用 如果再为 url 属性使用forward:进行配置的话,将不会产生 转效果。同样 禁同其他过滤器也会导致失去相应的功能。


3. ribbon(负载均衡配置)


ribbon.ConnectTimeout: 500
#全局配置负载均衡超时设置 ribbon.<key>=<value>

ribbon.ReadTimeout: 5000
#全局配置负载均衡读超时设置 


4. hystrix (熔断配置)
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
#hystrix.command.default.xxx进行全局配置

hystrix.command.hello.execution.isolation.thread.timeoutInMilliseconds: 5000
#hystrix.command.<commandKey>.xxx进行指定配置,这里的<commandKey>可以为方法名

5. config(集群配置中心)
1. 配置server

server: 
  port : 8888 
management : 
  security : 
    enabled : false 
spring : 
  application:
    name: configserver
  profiles: 
	active: subversion 
cloud: 
  config : 
    server:
      svn : 
		uri : https : //localhost/svn/test-project 
		username: admin 
		password: 123456 
		default-label : default-config
		
# git 默认值 表示去 Git 库读取配置文件。
# subversion 表示去 SYN 仓库读取配置文件。
# native 将去本地的文件系统中读取配置文件。
# vault Vault 中读 配置文件, Vault 款资源控制工具 可对资源实现安全访

# spring.profiles active 配置以上四个值,可让配置服务器访问不同的仓库。

2. 配置client
spring:
  application:
    name: user
  profiles:
    active: dev
  cloud:
    config:
      uri: http://localhost:8762
      fail-fast: false	
# 读取配置中心下的user-dev.yml 配置文件

3. 重试机制

spring.cloud.config.retry.initial-interval: 
# 初始的重试问隔,默认为 1000 毫秒
spring.cloud.config.retry.max-attempts: 
# 最大重试次数 ,默认为6
spring.cloud.config.retry.max-interval: 
# 最大 重试间隔 ,默认为 2000 毫秒。
spring.cloud.config.retry.multiplier:
# 重试间隔的递增系数,默认为 1.1

4. 安全配置

# 为服务器 application.yml,配置访问的用户名和密码:
security: 
  user : 
    name : root 
    password : root

# 为客户端的 bootstrap .yml 加入以下配置
spring: 
  cloud: 
   config: 
	 username: root 
	 password: root

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值