CreateLoadBalancer - 创建负载均衡器

用于创建一个新的负载均衡器实例,支持自定义路由策略、会话保持、监控配置等高级功能。

接口说明

通过此 API,用户可以根据业务需求配置负载均衡服务,包括但不限于自适应路由、加权轮询、规则匹配、健康检查等设置,以实现流量的有效管理和优化。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。
  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:
    • 对于必选的资源类型,用前面加 * 表示。
    • 对于不支持资源级授权的操作,用全部资源表示。
  • 条件关键字:是指云产品自身定义的条件关键字。
  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
操作访问级别资源类型条件关键字关联操作
esa:CreateLoadBalancercreate
*Site
acs:esa:{#regionId}:{#accountId}:site/{#SiteId}

请求参数

名称类型必填描述示例值
Namestring

负载均衡器名称,需要满足域名格式校验,并且是站点下的子域名。

lb.example.com
Enabledboolean

负载均衡器是否启用。

  • true:启用。
  • false:不启用。
true
SiteIdlong

站点 ID,可通过调用 ListSites 接口获取。

123456789****
AdaptiveRoutingobject

跨地址池回源配置。

FailoverAcrossPoolsboolean

是否跨地址池回源。

  • true:是。
  • false: 否。
true
DefaultPoolsarray

默认地址池列表。

long

默认地址池 ID,整型。

95223818027****
FallbackPoollong

兜底地址池 ID,当所有其他池不可用时,流量将被导向此处。

123
RandomSteeringobject

加权轮询配置,用于控制不同地址池的流量分配权重。

DefaultWeightinteger

默认的轮询权重,用于所有没有单独指定权重的地址池。取值范围:0-100 之间的整数。

50
PoolWeightsobject

各后端服务器池的权重配置,键为池 ID,值为权重系数。权重系数表示相对流量分配的比例。

integer

单个源地址池的权重,0-100 的数字,0 表示不往该源地址池调度流量。

50
Rulesarray<object>

规则信息。

{ "ENAM": [ 12345678**** ], "WNAM": [ 23456789****, 23456789**** ] }
object

规则结构体。

RuleNamestring

规则名称。添加全局配置的时候不需要设置该参数。

rule_1
Rulestring

规则内容,使用条件表达式来匹配用户请求。添加全局配置的时候不需要设置该参数。存在两种使用场景:

  • 匹配所有传入请求:值设置为 true
  • 匹配指定请求:值设置为自定义表达式,例如:(http.host eq "video.example.com")
(http.request.method eq "GET" and http.request.version eq "HTTP/1.0") or (ip.geoip.country eq "CN") or (http.host eq "www.example.com")
RuleEnablestring

规则开关。添加全局配置的时候不需要设置该参数。取值范围:

  • on:开启。
  • off:关闭。
on
FixedResponseobject

匹配规则后执行响应指定内容。

ContentTypestring

HTTP Header 中的 Content-Type 字段。

application/octet-stream
Locationstring

HTTP 返回中的 location 字段。

http://www.example.com/index.html
MessageBodystring

响应 body 值。

Hello World!
StatusCodeinteger

响应状态码。

200
Overridesany

匹配规则后修改对应请求改写的负载均衡配置,配置的字段,会覆盖负载均衡器配置里相应的字段。

{ "adaptive_routing": { "failover_across_pools": true }, "sub_region_pools": { "AL,AT": [ 92298024898****, 92304347804**** ], "BG,BY": [ 92298024898**** ] }, "default_pools": [ 92298024898****, 92304347804**** ], "fallback_pool": 92298024898****, "location_strategy": { "mode": "resolver_ip", "prefer_ecs": "always" }, "random_steering": { "default_weight": 0.3, "pool_weights": { "92298024898****": 0.7, "92304347804****": 0.8 } }, "region_pools": { "CN,SEAS": [ 92298024898****, 92304347804**** ], "SAF,SAS": [ 92304347804**** ] }, "session_affinity": "ip", "steering_policy": "geo", "ttl": 30 }
Sequenceinteger

规则执行顺序,可以不填,不填时以列表顺序执行,如果填的话,是大于 0 的整数。数值越大越优先执行。

1
Terminatesboolean

是否终止执行后续规则。

  • true:是。
  • false:否,默认值。
true
SessionAffinitystring

会话保持,取值:

  • off:不开启。
  • ip:按 ip 方式会话保持。
  • cookie: 按 cookie 方式会话保持。
ip
SteeringPolicystring

负载均衡策略。

  • geo: 地址策略。
  • random: 加权轮询。
  • order: 主备方式。
order
Descriptionstring

负载均衡器的详细描述信息,便于管理和识别。

测试负载均衡器描述
Ttlinteger

TTL 值,DNS 记录的生存时间,默认为 30 秒。取值范围:10-600。

300
Monitorobject

监视器配置,用于健康检查。

Typestring

监视器协议类型,如 HTTP,用于健康检查,值为 off 时,表示不进行检查。

  • TCP
  • UDP
  • SMTP
  • HTTPS
  • HTTP
  • ICMP Ping
  • off
HTTP
Methodstring

监视器请求方法,如GET,HTTP 协议中的方法。

GET
Portinteger

源站端口。

1921
Pathstring

监视器检查路径,如/healthcheck,HTTP 请求路径。

/health
Intervalinteger

监视间隔,如60秒,检查频率。

60
Timeoutinteger

应用健康检查超时时间,单位为秒,取值范围:1-10。

5
ExpectedCodesstring

预期状态码,如200,202,成功的 HTTP 响应。

200
FollowRedirectsboolean

是否跟随重定向。

  • true:是。
  • false:否。
true
ConsecutiveUpinteger

连续探测多少次成功算成功,如3

3
ConsecutiveDowninteger

连续探测多少次失败算失败,如5

5
Headerany

探测时所带头部信息,HTTP 头。

{ "host": [ "example1.com", "example2.com" ] }
SubRegionPoolsany

二级 region 对应的地址池,多个二级 region 共用一批地址池时,可以多个二级 region,使用逗号拼接作为 key。

{"AL,MO": [92298024898****],"CN-SH,CN-SX,CN-SC":[92304347804****,92843536908****]}
RegionPoolsany

一级 region 对应的地址池。

{ "ENAM": [ 12345678**** ], "WNAM": [ 23456789****, 23456789**** ] }

返回参数

名称类型描述示例值
object

Schema of Response

RequestIdstring

请求 ID。

EEEBE525-F576-1196-8DAF-2D70CA3F4D2F
Idlong

负载均衡器 ID。

99867648760****

示例

正常返回示例

JSON格式

{
  "RequestId": "EEEBE525-F576-1196-8DAF-2D70CA3F4D2F\n",
  "Id": 0
}

错误码

HTTP status code错误码错误信息描述
400InvalidParameterThe specified parameter is invalid.输入参数规范校验失败。
400LoadBalancerQuotaCheckFailedLoad balancer enable quota check failed.您当前的套餐无法使用负载均衡器相关功能,如需使用,请进行套餐升级。
400LoadBalancerNumberExceedQuotaLimitThe number of load balancers you have added has reached the limit of the plan quota. Please delete the unused load balancers or upgrade the plan and try again.您添加的负载均衡器数量已经达到套餐配额限制,请删除不使用的负载均衡器或者升级套餐后进行重试。
400LoadBalancerRuleQuotaCheckFailedYour current plan does not support configuring load balancer custom rules, or the load balancer rules you have added exceed the plan quota limit. Please upgrade the plan or delete the rules that are no longer in use and try again.您当前的套餐不支持配置负载均衡器自定义规则,或者您已经添加的负载均衡器规则超过套餐配额限制,请升级套餐或者删除不再使用的规则后重试。
400LoadBalancerPolicyCheckFailedYour current plan does not support the load balancer scheduling policy. Upgrade the plan and try again.您当前的套餐不支持使用该负载均衡器调度策略,请升级套餐后重试。
400LoadBalancerHealthDetectionQuotaCheckFailedYour current plan does not allow you to configure the load balancer's health detection. Upgrade the plan and try again.您当前的套餐不允许配置负载均衡器的健康探测,请升级套餐后重试。
400LoadBalancerHealthDetectionIntervalCheckFailedThe configured load balancer health detection interval exceeds the quota range allowed by the plan. Please revise the interval within the range or upgrade the plan and try again.您配置的负载均衡器健康探测时间间隔超出了套餐允许的配额范围,请订正为范围内的间隔或者升级套餐后,进行重试。
400InternalExceptionFailed to call the service. Try again later or contact technical support.调用服务失败,请稍后重试或联系客服咨询详情。
400Instance.NotOnlineYour plan is unavailable due to an overdue payment. Complete the payment first.您的套餐实例因欠费当前处于非上线状态,请先完成续费操作以继续使用。
400MonitorExpectedBodyInvalidInvalid response body. Specify a response body that does not exceed 102,400 characters in length in your custom rule.传入的监视器预期返回值不正确,长度不能大于102400字符,请您确认返回值后重试。
400MonitorExpectedCodesInvalidInvalid expected status code for the probe.Make sure that you specify no more than 10 status codes in the probe settings, and each status code must be 3 to 4 characters in length.Examples: 200, 301, 3xx, 8000, and 88xx.传入的监视器预期返回码不合法。请注意:返回码的数量不能超过10个,且每个返回码的长度应不少于3个字符且不超过4个字符。例如:200、301、3xx、8000、88xx。
400MonitorHeaderInvalidInvalid request header for the probe. You can add up to 10 request headers, each with 1 to 9 values. The combined length of all headers and values cannot exceed 6,000 characters. You cannot configure the User-Agent header.传入的监视器携带的请求头非法。请确保请求头数量不超过10个,每个请求头的值长度在110之间,并且不得使用User-Agent请求头(该请求头保留用于内部特定场景)。此外,所有请求头及其值的总长度不得超过6000个字符。请您检查并修正请求头配置后重试。
400MonitorMethodNotSupportInvalid HTTP method for the probe request. Valid values are GET and HEAD.传入的监视器请求方法不支持,只支持以下方法:GET/HEAD。
400MonitorPathNotSupportInvalid probe URL path.If you set the probe protocol to HTTP or HTTPS, make sure you specify a probe URL path that does not exceed 1,024 characters in length.传入的监听路径不支持。当监听类型为HTTPHTTPS时,监听路径不能为空,且路径长度不得超过1024个字符,请您检查路径后重试。
400MonitorPortNotSupportInvalid probe port. Specify a valid port from 1 to 65535 for the probe request. Then, try again.传入的监视器监听端口不支持,端口取值范围:[1-65535],请您确保端口在取值范围内重试。
400MonitorRetriesInvalidInvalid number of probe retries. Specify an integer from 0 to 5. Then, try again.传入的监视器重试次数参数不支持,支持的重试次数取值范围为:[0-5],请确保设置的重试次数在此范围内。
400MonitorTimeoutInvalidInvalid timeout for the probe. Valid values are 1 to 10.传入的监视器超时时间超出取值范围,支持以下范围:[1-10]。
400MonitorTypeNotSupportInvalid protocol. Valid values are off, HTTP, HTTPS, TCP, UDP, ICMP Ping, and SMTP.传入的监视器类型不支持,监视器只支持以下类型:off/HTTP/HTTPS/TCP/UDP/ICMP Ping/SMTP。
400OriginPoolNotExistThe specified origin pool does not exist or does not belong to your account or website. Check and try again.传入的源地址池不存在,或该地址池不属于当前用户和站点,请您确认后重试。
400LoadBalancerNameConflictThe load balancer name or the hostname for the origin pool already exists. Try again with a unique name.负载均衡器名称或源地址池记录名已存在,请更换一个唯一的名字重试。
400LockFailedThe system is handling requests you previously submitted. Try again later.您有其他请求正在处理中,请稍后再进行重试。
400SourceCircleExistThe host record of the resource to be operated on is already the source station of another resource, or the source station of the current resource has been added as a host record. To avoid loopback, modify the host record or source station and retry.当前要操作资源的主机记录已经是其他资源的源站,或者当前资源的源站已经被添加为主机记录,为避免回环产生,请修改主机记录或者源站后进行重试。
403QuotaExceededThe quota is exceeded.额度不足
404SiteNotFoundThe website does not exist or does not belong to you.站点不存在,或者不属于你。

访问错误中心查看更多错误码。

变更历史

变更时间变更内容概要操作
2025-02-13OpenAPI 错误码发生变更、OpenAPI 入参发生变更查看变更详情
2025-02-10OpenAPI 错误码发生变更查看变更详情