全部產品
Search
文件中心

Server Load Balancer:CreateLoadBalancerTCPListener - 建立TCP監聽

更新時間:Dec 14, 2025

建立TCP監聽。

介面說明

說明

建立的監聽的狀態為 stopped。建立完成後,調用 StartLoadBalancerListener 介面啟動監聽來轉寄流量。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

下表是API對應的授權資訊,可以在RAM權限原則語句的Action元素中使用,用來給RAM使用者或RAM角色授予調用此API的許可權。具體說明如下:

  • 操作:是指具體的許可權點。

  • 存取層級:是指每個操作的存取層級,取值為寫入(Write)、讀取(Read)或列出(List)。

  • 資源類型:是指操作中支援授權的資源類型。具體說明如下:

    • 對於必選的資源類型,用前面加 * 表示。

    • 對於不支援資源級授權的操作,用全部資源表示。

  • 條件關鍵字:是指雲產品自身定義的條件關鍵字。

  • 關聯操作:是指成功執行操作所需要的其他許可權。操作者必須同時具備關聯操作的許可權,操作才能成功。

操作

存取層級

資源類型

條件關鍵字

關聯操作

slb:CreateLoadBalancerTCPListener

create

AccessControlList

acs:slb:{#regionId}:{#accountId}:acl/{#AclId}

*LoadBalancer

acs:slb:{#regionId}:{#accountId}:loadbalancer/{#LoadBalancerId}

  • slb:tag
  • slb:tag
  • slb:tag

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

傳統型Server Load Balancer執行個體的地區 ID。

您可以從地區和可用性區域列表或通過調用 DescribeRegions 介面查詢地區 ID。

cn-hangzhou

LoadBalancerId

string

傳統型Server Load Balancer執行個體的 ID。

lb-bp1b6c719dfa08ex****

ListenerPort

integer

傳統型Server Load Balancer執行個體前端使用的連接埠。

取值範圍:1~65535

80

BackendServerPort

integer

傳統型Server Load Balancer執行個體後端使用的連接埠。

取值範圍:1~65535

如果不使用伺服器組(不指定 vServerGroupId),則該參數必選。

80

Tag

array<object>

標籤列表。

object

標籤列表。

Key

string

監聽的標籤鍵。N 的取值範圍:1~20。一旦傳入該值,則不允許為空白字串。最多支援 64 個字元,不能以aliyunacs:開頭,不能包含http://https://

TestKey

Value

string

監聽的標籤值。N 的取值範圍:1~20。一旦傳入該值,可以為空白字串。最多支援 128 個字元,不能以acs:開頭,不能包含http://或者https://

TestValue

Bandwidth

integer

監聽的頻寬峰值,單位:Mbps。取值:

  • -1:對於按流量計費的公網Server Load Balancer執行個體,可以將頻寬峰值設定為-1,即不限制頻寬峰值。

  • 1~5120: 對於按頻寬計費的公網Server Load Balancer執行個體,可以設定每個監聽的頻寬峰值,但所有監聽的頻寬峰值之和不能超過執行個體的頻寬峰值。

-1

Scheduler

string

調度演算法。取值:

  • wrr(預設值):權重值越高的後端伺服器,被輪詢到的次數(機率)也越高。

  • rr:按照訪問順序依次將外部請求依序分發到後端伺服器。

  • sch:基於源 IP 位址的一致性 hash,相同的源地址會調度到相同的後端伺服器。

  • tch:基於四元組的一致性 hash(源 IP+目的 IP+源連接埠+目的連接埠),相同的流會調度到相同的後端伺服器。

說明

僅效能保障型執行個體支援 schtch 一致性 hash 演算法。

wrr

PersistenceTimeout

integer

會話保持的逾時時間。單位:秒。

取值範圍:0~3600

預設值:0,表示關閉會話保持。

0

EstablishedTimeout

integer

連線逾時時間。單位:秒。

取值範圍:10~900

500

HealthyThreshold

integer

健全狀態檢查連續成功多少次後,將後端伺服器的健全狀態檢查狀態由 fail 判定為 success

取值範圍: 2~10

4

UnhealthyThreshold

integer

健全狀態檢查連續失敗多少次後,將後端伺服器的健全狀態檢查狀態由 success 判定為 fail

取值範圍:2~10

4

HealthCheckConnectTimeout

integer

每次健全狀態檢查響應的最大逾時時間。單位:秒。

取值範圍:1~300

預設值:5

100

HealthCheckConnectPort

integer

健全狀態檢查使用的連接埠。

取值範圍:1~65535

不設定此參數時,表示使用後端服務連接埠(BackendServerPort)。

80

healthCheckInterval

integer

健全狀態檢查的時間間隔。單位:秒。

取值範圍:1~50

3

HealthCheckDomain

string

用於健全狀態檢查的網域名稱。取值:

  • $_ip: 後端伺服器的私網 IP。當指定了 IP 或該參數未指定時,負載平衡會使用各後端伺服器的私網 IP 當做健全狀態檢查使用的網域名稱。

  • domain:網域名稱長度為 1~80,只能包含字母、數字、半形句號(.)和短劃線(-)。

172.XX.XX.6

HealthCheckURI

string

用於健全狀態檢查的 URI。長度限制為 1~80,只能使用字母、數字、短劃線(-)、正斜線(/)、半形句號(.)、百分比符號(%)、井號(#)和 and(&)這些字元。 URI 不能只為正斜線(/),但必須以正斜線(/)開頭。

當 TCP 監聽需要使用 HTTP 健全狀態檢查時可配置此參數,如不配置則按 TCP 健全狀態檢查。

/test/index.html

HealthCheckHttpCode

string

健全狀態檢查正常的 HTTP 狀態代碼,多個狀態代碼用半形逗號(,)分割。取值:

  • http_2xx(預設值)

  • http_3xx

  • http_4xx

  • http_5xx

http_2xx,http_3xx

HealthCheckType

string

健全狀態檢查類型。取值:

  • tcp(預設值)

  • http

tcp

VServerGroupId

string

虛擬伺服器組 ID。

rsp-cige6j****

MasterSlaveServerGroupId

string

主備伺服器組 ID。

說明

虛擬伺服器組 ID 和主備伺服器組 ID 只能選擇一個。

rsp-0bfucw****

AclId

string

監聽綁定的存取原則組 ID。

說明

AclStatus 參數的值為 on 時,該參數必選。

acl-uf60jwfiv6******

AclType

string

存取控制類型:

  • white: 僅轉寄來自所選存取控制策略組中設定的 IP 位址或位址區段的請求,白名單適用於只允許特定 IP 訪問的情境。 設定白名單存在一定業務風險。

一旦設定白名單,就只有白名單中的 IP 可以訪問負載平衡監聽。如果開啟了白名單訪問,但存取原則組中沒有添加任何 IP,則負載平衡監聽會轉寄全部請求。

  • black: 來自所選存取控制策略組中設定的 IP 位址或位址區段的所有請求都不會轉寄,黑名單適用於只限制某些特定 IP 訪問的情境。

如果開啟了黑名單訪問,但存取原則組中沒有添加任何 IP,則負載平衡監聽會轉寄全部請求。

說明

AclStatus 參數的值為 on 時,該參數有效。

black

AclStatus

string

是否開啟存取控制功能。取值:

  • on:開啟。

  • off(預設值):不開啟。

off

Description

string

自訂監聽名稱。

長度限制為 1~256 個字元,支援中文、字母、數字、短劃線(-)、正斜線(/)、半形句號(.)和底線(_)。

tcp_80

ConnectionDrain

string

是否開啟串連優雅中斷。取值:

  • on:開啟。

  • off:不開啟。

off

ConnectionDrainTimeout

integer

設定串連優雅中斷逾時時間。單位:秒。

取值範圍:10~900

說明

ConnectionDrain 取值為 on 時,該選項必選。

300

ProxyProtocolV2Enabled

boolean

是否支援通過 Proxy Protocol 協議攜帶用戶端源地址到後端伺服器。取值:

  • true:是。

  • false(預設值):否。

false

HealthCheckSwitch

string

是否開啟健全狀態檢查。取值:

  • on(預設值):開啟。

  • off:不開啟。

on

返回參數

名稱

類型

描述

樣本值

object

RequestId

string

請求 ID。

CEF72CEB-54B6-4AE8-B225-F876FF7BA984

樣本

正常返回樣本

JSON格式

{
  "RequestId": "CEF72CEB-54B6-4AE8-B225-F876FF7BA984"
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 InvalidParameterValue.SpecNotSupport The loadBalancer of shared spec does not support the parameter value, %s.
400 OperationNotSupport.Acl The cloud box instance does not support acl.
400 InvalidParameterValue.RegionNotSupport The region does not support the parameter value, %s.
400 Abs.VServerGroupIdAndMasterSlaveServerGroupId.MissMatch The parameters VServerGroupId or MasterSlaveServerGroupId miss match.
400 IpVersionConflict The ip version of this LoadBalancer and the Acl is conflict.
400 InvalidParameterValue.ZoneNotSupport The zone does not support the parameter value, %s.
400 ListenerProcessing A previous configuration of the listener is pending, please try again later.
400 AclNotExist Acl does not exist.
400 InvalidParameter.ListenerPortConflict There is conflict listener port exists.
400 InvalidParameter.ZoneNotSupport The zone does not support the parameter %s.
400 InvalidParam.VServerGroupId The specified VServerGroupId is invalid.
400 MissingParam.HealthCheckConnectPort The parameter HealthCheckConnectPort is required.
400 InvalidParam.ListenerPort The specified ListenerPort is invalid.
400 InvalidParam.StartPort The specified StartPort is invalid.
400 InvalidParamSize.PortRange The size of param PortRange is invalid.
400 InvalidParam.EndPort The specified EndPort is invalid.
400 Duplicated.AclEntry %s.
400 OperationUnsupported.SetAccessControl The singleTunnel/anyTunnel loadbalancer does not support config AccessControlList.
400 InvalidParam.PortRange The specified PortRange is invalid.
400 InvalidParameter.RegionNotSupport The region does not support the parameter: %s.
400 LbNotSupportTcpssl You cannot create a TCP SSL type listener for the specified load balancer.
400 LbSupportTcpsslOnly The specified load balancer supports TCP SSL type listener only.
400 ListenerNotSupportRule You cannot create a rule for the specified listener.
400 ListenerPortConflict The specified ListenerPort is conflict with other listener.
400 ResourceNotFound.VServerGroup %s.
400 IllegalParam.FailoverThreshold The parameter FailoverThreshold is illegal.
400 IllegalParam.FailoverStrategy The parameter FailoverStrategy is illegal.
400 MasterSlaveServerConflict The servers are conflict for MasterSlaveGroup.
400 OperationDenied.HealthCheckClosedForMasterSlaveMode The operation is denied because of HealthCheckClosedForMasterSlaveMode.
400 IllegalParam.HealthCheck The param of HelathCheck is illegal.
400 Mismatch.SlbSpecTypeAndListenerProtocol The SlbSpecType and ListenerProtocol are mismatched.
400 OperationDenied.FullNatModeNotAllowed The operation is not allowed because of FullNatModeNotAllowed.
400 OperationDenied.OnlyIpv4SlbSupport The operation is not allowed because of OnlyIpv4SlbSupport.
400 SpecNotSupportParameter The instance with share spec does not support FullNatEnabled parameter.
400 InvalidParam.TagValue %s.
400 InvalidParam.TagKey %s.
400 SizeLimitExceeded.Tag %s.
400 MissingParam.TagKey The param MissingParam.TagKey is missing.
400 MissingParameter The BackendServerPort or VServerGroupId is required at lease one.
400 AclListenerOverLimit This acl has reached the limit of binding to listeners.
400 QuotaLimitExceeds.AclAttachedToListener The number of Acl bound listeners has reached the quota limit
400 QuotaLimitExceeds.TotalAclEntry The number of Acl entries has reached the quota limit.
400 QuotaLimitExceeds.AclListenerOverLimit This acl has reached the limit of binding to listeners.

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情