更新时间:2025-05-21 GMT+08:00
分享

转发策略配置

本章介绍通过IaC进行转发策略配置的管理,包括监听下的转发策略、健康检查、后端服务器及动态路由管理。对应的资源类型为WiseCloud::LoadBalancer::SLB::RouteRule。

表1 转发策略配置字段说明

参数名

类型

是否必选

说明

listenerGroupName

String

SLB监听名称,一个转发策略实例只能绑定一个监听实例。

targetGroups

List<TargetGroupConfigBean>

后端集群。

routes

List<RouteRule>

转发策略(Locations)。

dynamicRoutes

List<DynamicRouteRuleBean>

动态路由。

表2 TargetGroupConfigBean

参数名

类型

是否必选

说明

name

String

后端集群名,不超过150位,不包含特殊字符。

protocol

String

协议,取值为:HTTP或HTTPS。

loadBalancer

TargetGroupLoadBalancerBean

后端集群负载均衡类型。

healthCheck

TargetGroupHealthCheckBean

健康检查。

表3 TargetGroupLoadBalancerBean

参数名

类型

是否必选

说明

strategy

String

负载均衡算法,支持"roundRobin"、"protocolParam"、"IP_HASH"、"least_conn"。

slowStartDelay

int

预热时延,不超过30。

slowStartPeriod

int

预热周期,不超过30。

slowStartFactor

int

预热因子,默认为10,不小于1,不超过100。

hashParam

String

哈希转发字段名,Strategy类型为protocolParam时必填

长度不超过50,由字母加数字,下划线,横杠,点组成。

customParam

String

自定义参数,不包含by_lua。

默认取第一个后端集群的健康检查配置,如果为空,使用默认值。

表4 TargetGroupHealthCheckBean

参数名

类型

是否必选

说明

switchStatus

String

是否开启健康检查,取值为on或off,不填或者其他字符均为off。

protocol

String

协议,默认HTTP,不可修改。

path

String

检查路径,长度不超过500,由字母、数字、横杠、下划线和点组成。

successCodes

String

成功码列表,100-600之间的数字,以逗号隔开。

healthyThreshold

int

健康阈值,取值范围2-10,默认为2。

interval

int

探测间隔时间,取值范围1-50,默认为5。

timeout

int

探测超时时间,取值范围1-300,默认为10。

unhealthyThreshold

int

不健康阈值,取值范围2-10,默认为3。

表5 RouteRule

参数名

类型

是否必选

说明

location

String

转发策略地址,长度不超过500,非中文。

targetGroup

String

后端集群名,长度不超过150,由字母、数字、下划线、横杠和点组成。

grayServiceName

String

灰度规则

degradeUrl

String

降级url

  • 不降级:unDegrade
  • 默认降级:defaultDegrade

只有值为defaultDegrade时才为默认降级,其他值均认为是不降级。

configs

GeneralAndAdvancedConfigBean

通用与高级配置

表6 DynamicRouteRuleBean

参数名

类型

是否必选

说明

name

String

名称,长度不超过50,由字母、数字、下划线、横杠和点组成,不能包含-in-且不能以-in结尾。

switchStatus

String

开关,取值为on或off。

defaultTargetGroup

String

默认后端集群。

enableGrey

String

默认后端集群是否仍参考灰度进行分流,取值为on/off,默认为off,只有输入on才为打开状态。

rules

List<DynamicSubRuleBean>

动态路由规则。

locations

List<String>

动态路由关联的转发策略列表。

表7 DynamicSubRuleBean

参数名

类型

是否必选

说明

condition

String

名称。

targetGroup

String

后端集群。

enableGray

String

是否仍参考灰度进行分流,取值为on/off,默认为off,只有输入on才为打开状态。

表8 GeneralAndAdvancedConfigBean

参数名

类型

是否必选

说明

proxyReadTimeout

int

响应超时时间,不超过10位的数字。

proxySendTimeout

int

转发超时时间,不超过10位的数字。

keepaliveSwitch

String

启用长连接转发,是否keepalive。

hostSwitch

String

是否透传请求头,取值为on/off,不填或者其他字符均为off。

xForwardedForSwitch

String

是否追加XFF。

accessLogSwitch

String

是否开启access日志,取值为on/off,不填或者其他字符均为off。

proxyNextUpstreamSwitch

String

是否在异常时尝试下一台机器,取值为on/off,不填或者其他字符均为off。

proxyNextUpstreamCondition

String

尝试下一台机器的场景,取值为403、404、429、500、502、503、504、error、timeout、invalid_header。

clientConnectionFreeTime

int

客户端连接空闲时间,不超过10位的正整数。

proxyBuffersSwitch

String

开启响应缓存,取值为on/off,不填或者其他字符均为off。

proxyBuffersSize

String

响应缓存大小,数字+空格+k/m 组成,默认8 k。

expiresSwitch

String

高级配置中Expires开关,取值为on/off,不填或者其他字符均为 off。

expiresSize

String

设定页面缓存时间,不缓存或一直使用缓存。可以由字母、数字、空格、 $@+- 、冒号、逗号组成,长度不超过50位。

indexPage

String

静态页面场景index页面设置,长度不超过255,非中文。

returnVal

String

固定返回响应码,长度不超过255,非中文。

allowMethod

String

允许的http方法,对于转发策略有效,对于监听仅为参考,在界面新增转发策略时会继承监听的此项配置,其余场景个无效,GET、HEAD、POST、DELETE、PUT、OPTIONS、PATCH、MKCOL、COPY、MOVE、PROPFIND、PROPPATCH、LOCK、UNLOCK。

nuwaTraceSwitch

String

消息头中透传nuwatrace相关的网元身份标识和时间戳。

command

String

高级配置,自定义参数设置。

不要直接填写转发到某个集群的名称,例如proxy_pass http://upstreamName,这样配置会使得动态加载配置失效。

nginx配置命令,非中文。

root

String

默认资源根目录,长度不超过500,非中文。

clientMaxBodySize

String

最大请求体大小,数字+空格+k/m组成。

clientBodyBufferSize

String

请求体buffer大小,数字+空格+k/m 组成。

addHeaders

List< GeneralKeyValueConfigBean>

响应头。

setVals

List< GeneralKeyValueConfigBean>

对应页面set。

proxySetHeaders

List< GeneralKeyValueConfigBean>

请求头。

redirects

List< GeneralRedirectConfigBean>

重定向。

rewrites

List< GeneralRedirectConfigBean>

重写。

转发策略模板yaml

- name: hw_test                                  // 必填项,不可修改,不可重复
  type: WiseCloud::LoadBalancer::SLB::RouteRule  // 资源类型为转发策略配置
  properties:
    routes:                                     // 非必填
      - targetGroup: group1
        grayServiceName: grayServce_hw
        location: /abc_hw1
        degradeUrl: unDegrade                  // 必填项,unDegrade不降级,defaultDegrade默认降级
        configs:
          hostSwitch: 'off'
          addHeaders:
            - value: b
              key: aaa
          clientConnectionFreeTime: 60
          rewrites:
            - source: /test
              option: break
              target: /test_hw
          proxyReadTimeout: 60
          setVals:
            - value: bbb
              key: aaa
          keepaliveSwitch: 'off'
          proxyBuffersSize: 2 m
          expiresSwitch: 'on'
          proxyBuffersSwitch: 'on'
          accessLogSwitch: 'on'
          clientMaxBodySize: 3 k
          clientBodyBufferSize: 2 k
          expiresSize: 2 m
          proxyNextUpstreamCondition: 'error,timeout'
          proxySendTimeout: 60
          xForwardedForSwitch: 'off'
          proxyNextUpstreamSwitch: 'on'
          allowMethod: 'POST,PUT,DELETE'
    targetGroups:                                // 非必填
      - protocol: HTTP                           // 必填项
        loadBalancer:                            // 必填项,负载均衡类型
          strategy: roundRobin                   // 必填项,负载均衡策略
        healthCheck:                             // 非必填,健康检查
          path: /abc_test
          protocol: HTTP                         // 固定项
          successCodes: '200,302'
          healthyThreshold: '2'
          unhealthyThreshold: '3'
          switchStatus: 'on'                     // 默认关闭,on为打开,打开时,不传其他参数均使用默认值
        name: group1                             // 必填项,并且不可重复,长度不超过150,不包含特殊字符
      - protocol: HTTP
        loadBalancer:
          hashParam: $xxx
          strategy: protocolParam
          customParam: $xxx
        healthCheck:
          switchStatus: 'off'
        name: group2
    listenerGroupName: zwx_listener1             // 必填项,SLB监听名称,一个转发策略实例只能绑定一个监听实例
    dynamicRoutes:                               // 非必填
      - enableGrey: 'off'
        defaultTargetGroup: group1               // 必填并且存在于targetGroups中
        name: /abc_test1_hw
        locations:
          - location: /abc_hw1
        rules:
          - targetGroup: group1
            enableGray: 'off'
        switchStatus: 'on'

相关文档