tencent cloud

负载均衡

动态与公告
产品动态
产品公告
产品简介
产品概述
产品优势
使用场景
技术原理
产品对比
使用约束
Service Regions and Service Providers
购买指南
计费概述
计费项
CLB 资源包
购买方式
欠费说明
产品属性选择
快速入门
域名化负载均衡快速入门
负载均衡快速入门
IPv6 负载均衡快速入门
CentOS 下部署 Nginx
CentOS 下部署 Java Web
操作指南
负载均衡实例
负载均衡监听器
后端服务器
健康检查
证书管理
日志管理
监控告警
访问管理
传统型负载均衡
实践教程
部署证书到负载均衡(双向认证)
负载均衡开启 Gzip 配置及检测方法说明
HTTPS 转发配置入门指南
如何获取客户端真实 IP
负载均衡配置监控告警最佳实践
产品高可用说明
均衡算法选择与权重配置示例
配置 WAF 对负载均衡的监听域名进行 Web 安全防护
配置 IAP 对负载均衡的域名和路径的web访问进行身份验证
配置 IAP 对负载均衡的域名和路径的程序化访问进行身份验证
运维指南
客户端 timewait 过多解决方案
负载均衡HTTPS服务性能测试
压力测试常见问题
CLB 证书操作权限问题
故障处理
UDP 健康检查出现异常
API 文档
History
Introduction
API Category
Instance APIs
Listener APIs
Backend Service APIs
Target Group APIs
Redirection APIs
Other APIs
Classic CLB APIs
Load Balancing APIs
Making API Requests
Data Types
Error Codes
CLB API 2017
常见问题
计费相关
负载均衡配置相关
健康检查异常排查
HTTPS 相关
WS/WSS 协议支持相关
HTTP/2 协议支持相关
默认域名阻断提示
服务等级协议
联系我们
词汇表

Use Cases

PDF
聚焦模式
字号
最后更新时间: 2024-12-19 10:38:23
An example is given here to help you get started with CLB APIs. Before using the APIs, deploy TCP service on two CVMs and listen on port 80. If the service returns the “hello world” string, the deployment is successful. By creating a CLB instance, you can access CVM services through the CLB VIP.

Purchasing a Public Network CLB Instance

To use CLB services, you need to purchase a public network CLB instance (with static IP). For more information on CLB instance purchase, use the CreateLoadBalancer API.
This example shows you how to create a public network CLB instance (with static IP). The Action field in the common request parameters of this API is CreateLoadBalancer. The list below contains the API request parameters.
Parameter
Description
Value
loadBalancerType
CLB instance type.
2: public network CLB instance, the service of which is accessed via a public network.
By combining common request parameters and API request parameters, you can get the final request as follows:
https://lb.api.qcloud.com/v2/index.php?Action=CreateLoadBalancer
&Region=ap-guangzhou
&Timestamp=1465750149
&Nonce=46364
&SecretId=AKID****ugEY
&Signature=5umi****pTTyk18V2g%2FYi56hqls%3D
&loadBalancerType=2
Response of the request is as follows:
{
"code": 0,
"message": "",
"codeDesc": "Success",
"requestId": 3901941,
"dealIds": [
"3901941"
],
"unLoadBalancerIds": {
"3901941": [
"lb-lb-cjcy****"
]
}
}
Where, lb-cjcymkw5 is the unique ID of the CLB instance you just purchased. Next, use the DescribeLoadBalancers API to query whether the instance has been successfully created.

Creating a CLB Listener

This example shows you how to create a CLB listener with the unique ID of the CLB instance. For more information on the CLB listener creation, use the CreateLoadBalancerListeners API.
In this example, the table below lists the API request parameters.
Parameter
Description
Value
loadBalancerId
Unique ID of the CLB instance
This example uses the unique ID of the instance you’ve just created, i.e. lb-cjcy****
listeners.0.loadBalancerPort
Listening port of the CLB listener.
80
listeners.0.instancePort
Listening port on real server of the CLB instance.
80
listeners.0.protocol
Protocol listened by the CLB listener. 1: HTTP; 2: TCP; 3: UDP; 4: HTTPS
This example uses 2: TCP
listeners.0.healthSwitch
Whether to enable the health check for the CLB listener. 1: enable; 0: disable. The health check is enabled by default.
This example uses 1: enable
listeners.0.listenerName
Name of the CLB listener. This field is optional. Default value will be used if it is left empty.
This example uses listenerTest
By combining common request parameters and API request parameters, you can get the final request as follows:
https://lb.api.qcloud.com/v2/index.php?Action=CreateLoadBalancerListeners
&Region=ap-guangzhou
&Timestamp=1465750149
&Nonce=46364
&SecretId=AKID****ugEY
&Signature=5umi****pTTyk18V2g%2FYi56hqls%3D
&loadBalancerId=lb-cjcy****
&listeners.0.loadBalancerPort=80
&listeners.0.instancePort=80
&listeners.0.protocol=2
&listeners.0.healthSwitch=1
&listeners.0.listenerName=listenerTest

Response of the request is as follows:
{
"code" : 0,
"message" : "",
"codeDesc": "Success",
"requestId" : 12354
}
To query the execution result of the task with the request ID, use the asynchronous DescribeLoadBalancersTaskResult API.

Binding Real Server to the CLB Instance

You need to bind CVM to the CLB instance after creating the listener. For more information on the binding method, use the RegisterInstancesWithLoadBalancer API.
This example shows you how to bind two CVMs (with the unique ID of ins-5678test and ins-1234test respectively) on the CLB instance. The Action field in the common request parameters of this API is RegisterInstancesWithLoadBalancer. The list below contains the API request parameters.
Parameter
Description
Value
loadBalancerId
Unique ID of the CLB instance.
This example uses the unique ID of the instance you’ve just created: lb-abcdefgh
backends.0.instanceId
Unique ID of the CVM bound to the CLB instance.
This example uses the unique ID of the first CVM:ins-5678test
backends.0.weight
Weight of the CVM bound to the CLB instance.
This example uses the default value 10
backends.1.instanceId
Unique ID of the CVM bound to the load balancer instance
This example uses the unique ID of the second CVM: ins-1234test
backends.1.weight
Weight of the CVM bound to the CLB instance.
This example uses the default value 10
By combining common request parameters and API request parameters, you can get the final request as follows:
https://lb.api.qcloud.com/v2/index.php?Action=RegisterInstancesWithLoadBalancer
&Region=ap-guangzhou
&Timestamp=1465750149
&Nonce=46364
&SecretId=AKID****ugEY
&Signature=5umi****pTTyk18V2g%2FYi56hqls%3D
&loadBalancerId=lb-cjcy****
&backends.0.instanceId=ins-5678****
&backends.0.weight=10
&backends.1.instanceId=ins-1234****
&backends.1.weight=10
Response of the request is as follows:
{
"code" : 0,
"message" : "",
"codeDesc": "Success",
"requestId" : 1234
}
To query the execution result of the task with the request ID, use the asynchronous DescribeLoadBalancersTaskResult API.

Querying and Using the CLB Instance

This example shows you how to query the VIP or domain name of the CLB instance. For more information on the query method, use the DescribeLoadBalancers API.
The Action field in the common request parameters of the API is DescribeLoadBalancers. The list below contains the API request parameters.
Parameter
Description
Value
loadBalancerIds.0
Unique ID of the CLB instance.
This example uses the unique ID of the instance you’ve just created: lb-cjcy****
By combining common request parameters and API request parameters, you can get the final request as follows:
https://lb.api.qcloud.com/v2/index.php?Action=DescribeLoadBalancers
&Region=ap-guangzhou
&Timestamp=1465750149
&Nonce=46364
&SecretId=AKID****ugEY
&Signature=5umi****pTTyk18V2g%2FYi56hqls%3D
&loadBalancerIds.0=lb-cjcy****
Response
{
"code": 0,
"message": "",
"codeDesc": "Success",
"loadBalancerSet": [{
"loadBalancerId": "lb-cjcy****",
"unLoadBalancerId": "lb-cjcy****",
"loadBalancerName": "59b25ffb-0",
"loadBalancerType": 2,
"domain": "20de02-0.gz.1251000011.clb.myqcloud.com",
"loadBalancerVips": [
"119.28.168.196"
],
"status": 1,
"createTime": "2017-09-08 17:16:42",
"statusTime": "2017-09-20 13:37:55",
"vpcId": 0,
"uniqVpcId": "",
"subnetId": 0,
"projectId": 1005621,
"forward": 0,
"snat": false,
"openBgp": 0,
"isolation": 0,
"log": ""
}],
"totalCount": 1
}
As the query results suggest, you can use the VIP 119.28.168.XX or domain name 20****-0.gz.1251000011.clb.myqcloud.com of the CLB instance to forward the request to the associated backend CVMs according to the rule of CLB listener, thereby balancing the load.

帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈