Distribute Layer 4 or Layer 7 traffic to ECS through CLB

Updated on: April 10, 2024 11:02:31

slb

One click configuration

sixteen

Tutorial Introduction

In this tutorial, you will learn how to deploy Layer 4 and Layer 7 load balancing services on Alibaba Cloud's traditional load balancing CLB, distribute requests from clients to multiple back-end ECSs, and simulate ECS single point of failure scenarios to verify the high availability of services.

Traditional load balancer : It has the basic load balancing capability of Layer 4 and Layer 7, which can expand the external service capability of the application system, eliminate single points of failure, and improve the availability of the application system. For more information, see What is traditional load balancing CLB  image.. png

Description of probationary benefits

Only users who use the load balancing product for the first time can receive it once 3 natural months Free trial of traditional load balancing CLB. (Natural month refers to the period from the 1st day of each month to the last day of the month, which is calculated according to the solar calendar.)

  • The monthly CLB includes 750 hours of free trial quota (shared by multiple CLB instances)

  • The monthly CLB includes 15 LCUs for free trial (shared by multiple CLB instances)

The trial benefits received from the above traditional load balancing CLB cards are all pay as you go CLB instances.

What can I learn

  • Learn how to create CLB instances.

  • Learn how to configure Layer 4 monitoring with one click to complete the request forwarding of Layer 4 load balancing.

  • Learn how to configure Layer 7 monitoring with one click to complete the request forwarding of Layer 7 load balancing.

Operation difficulty

in

Time required

16 minutes

AliCloud products used

Required expenses

After receiving the free trial benefits of CLB and ECS and opening the CDT service, you can complete this tutorial for free and experience the free load balancing service within the validity period of the benefits. Please see the next step for the access Prepare resources and environment

Please refer to CLB charging rules ECS Billing Rules Public network fee CDT public network traffic billing rules

Prepare resources and environment

three

Resource requirements

Deploying the CLB load balancing service requires one CLB instance and two ECS instances, and the CLB instance and ECS instance belong to the same region.

Get free benefits

Enter the following resource collection portal and click Login/Registration Button, and complete account login (existing AliCloud account), account registration (no AliCloud account), or real name authentication (personal real name authentication or enterprise real name authentication according to the requirements of the trial product) according to the page prompts.

If you Existing corresponding resources , you may not receive free benefits, please go directly to the next step Check Resources

Resource collection entrance

This tutorial configures

Get traditional load balancing CLB

750 hours per month 15 LCUs (Free: 750 hours of instance usage per month, 15 LCUs per month, 3 months)

  • Region and zone : Selection of this article East China 1 (Hangzhou) Region, zone configuration on demand

  • Instance billing method : Billing by usage

  • Instance Type : Public network

  • IP version :IPv4

  • Trial quantity :1

  • Other parameters: keep the default value or select as required

Get ECS

2 cores, 4GB, 3 months

  • region : Select The same region as the CLB instance

  • Operating system: CentOS 7.9 64 bit

  • Trial quantity: 2 (ECS01, ECS02)

  • Other parameters: keep the default value or select as required

Enable cloud data transmission CDT

CDT gives 200GB of free public network traffic every month (20GB of which is available in all regions, and 180GB is only available in overseas regions), which can be used to offset the public network traffic of ECS, elastic public network IP, and traditional load balancing CLB. The excess part will be charged by steps. For details, refer to CDT public network traffic billing rules

Check Resources

Sign in Traditional load balancing CLB console and ECS Console Check whether the CLB instance and ECS instance are in the same region. If they are not in the same region, see Create and manage CLB instances Customized purchase of ECS instances Create related resources.

Deploy application

three

  1. Sign in ECS Console

  2. In the upper left corner of the top menu bar, select the same region as ECS 01 and ECS 02 instances.

  3. Set ECS 01 and ECS 02 instance login passwords. Click in the Action column image.. png >Instance Properties>Reset Instance Password , set the login password of the ECS instance according to the interface prompts. After saving the password, on the pop-up page, click Restart Now Make the password effective.

    Resetting the instance password is supported about 3-5 minutes after the instance creation is completed. If it cannot be reset, please wait patiently and try again.

  4. Connect ECS 01 and ECS 02 instances remotely.

    1. return example Page, click Remote connection

    2. In the pop-up connection and command dialog box, click Connect remotely through Workbench Corresponding Sign in now

    3. In the pop-up login instance dialog box, enter the login information.

  5. Execute the following commands to deploy the Nginx static page for the ECS 01 instance. The following command takes CentOS 7.9 64 bit operating system as an example.

    yum install -y nginx

    systemctl start nginx.service

    cd /usr/share/nginx/html/

    echo "Hello World ! This is ECS01." > index.html

  6. Execute the following commands to deploy the Nginx static page for the ECS 02 instance. The following command takes CentOS 7.9 64 bit operating system as an example.

    yum install -y nginx

    systemctl start nginx.service

    cd /usr/share/nginx/html/

    echo "Hello World ! This is ECS02." > index.html

One click configuration

three

After preparing resources and deploying applications, you can quickly complete the configuration of CLB listening through one click configuration. One click configuration is based on AliCloud Resource Orchestration Service (ROS), which is designed to help developers experience the automated configuration of resources through IaC (Infrastructure as Code). To view specific information about CLB instances, backend server groups, and listening configurations, see the Manual configuration The completed contents of the template include:

  • Configure listening

  • Configure Virtual Server Group

Operation steps

  1. Select the following link to go to the ROS console. The system opens automatically Use new resources (standard) Create a page of the resource stack, and Template content The area shows the details of the YAML file.

    The ROS console is in the region you last accessed the console by default. Please modify the region according to the region of the resource you created before proceeding to the next step.

  2. After confirming the region, keep all the options on the page unchanged and click next step get into Configure template parameters Page.

  3. stay Configure template parameters Page, complete the configuration of the following parameters, and then click establish Start one click configuration.

    to configure

    explain

    Example

    Resource stack name

    Modify the resource stack name.

    test

    CLB instance ID

    Select the created private network CLB instance from the drop-down box.

    lb-bp1g9vutth8xvnznn****

    ECS instance ID list

    single click Select Instance In the pop-up dialog box, select the two ECS instances that have been created, and then click determine

    The selected ECS instances have deployed application services, and the ECS instances and CLB instances belong to the same region.

    single click Select Instance And select two ECS in the pop-up dialog box

  4. When Resource stack information Of the page state Show as Created successfully Indicates that one click configuration is complete.

    It usually takes about 1~2 minutes to create a monitor through one click configuration, but there may be some delay due to network and other reasons. Please wait patiently for a few minutes.

     image

complete

five

After one click configuration, you can select the following methods to test whether the CLB instance distributes the request to the back-end ECS, and simulate the ECS single point of failure scenario to verify the high availability of the business according to the configured Layer 4 and Layer 7 monitoring.

Verifying Layer 7 Load Balancing

  1. Sign in Traditional load balancing CLB console , at CLB Instance management Page, on Service address Column to view and copy the public network service address of the CLB instance.

  2. Enter the public service address of the CLB instance in the browser http://120.XX.XX.50:81 To verify the CLB's 7-layer load balancing forwarding capability.

    Refresh the browser, and you can observe that the request is converted between two ECSs.

    The above verification process shows that CLB can distribute client traffic to different back-end servers.

     image

     image

Verifying Layer 4 Load Balancing

  1. Sign in Traditional load balancing CLB console , at CLB Instance management Page, on Service address Column to view and copy the public network service address of the CLB instance.

  2. Enter the public service address of the CLB instance in the browser http://120.XX.XX.50 You can observe that the request has been forwarded to a backend ECS server. The following operations take ECS01 as an example.

    1. Deactivate ECS01, refresh the public service address of the browser accessing the CLB instance, and you can observe that the request has been forwarded to ECS02.

    2. start-up ECS01 and wait for a few minutes.

    3. Deactivate ECS02, refresh the public service address of the browser accessing the CLB instance, and observe that the request has been forwarded to ECS01.

    The above verification process shows that when a single back-end server fails, CLB can still ensure service availability.

     image

     image

Cleaning and follow-up

two

clear

  1. The free trial rights of CLB are limited in duration, and CLB instances that are not released after the expiration of the rights may incur costs. After completing the tutorial, refer to the following scenarios to process CLB instances:

    • If you do not need to use the CLB instance, you can log in Traditional load balancing CLB console In the left navigation bar, select Traditional load balancing CLB (original SLB) > Instance management , on Instance management Page, find the target CLB instance in the operation Column Click one thousand one hundred and eleven > Release Settings , manually release the instance according to the interface prompts.

    • If you need to continue using the CLB instance, please recharge your AliCloud account at least one hour before the trial expires to ensure that the account amount is not less than 100.00 yuan. The CLB instance that has not been renewed upon expiration will be automatically stopped due to arrears. The CLB instance will be retained within 7 days of downtime, and the CLB instance and data will be automatically released after 7 days.

  2. This tutorial uses a personal ECS instance, which defaults to pay as you go instances. After completing the tutorial, please refer to the following scenarios to process ECS instances:

    • If you do not need to continue using the instance, you can Log in to the ECS console , find the target instance, and click in the operation column image.. png , search and click Release Settings , release the instance according to the interface prompt.

    • If you need to continue using the instance, please recharge your AliCloud account at least one hour before the trial expires to ensure that the account amount is not less than 100.00 yuan. Instances that have not been renewed upon expiration will be automatically shut down due to arrears. The instance will be retained within 15 days of downtime, and the instance and data will be automatically released after 15 days.

follow-up

During the probation period, you can continue to use traditional load balancing CLB products according to other business scenarios you want to test. For CLB related tutorials, see CLB Tutorial

summary

Common knowledge points

Question 1: What protocol monitoring does the CLB instance support? (Single topic)

  • Only Layer 4 (TCP or UDP protocol) listening

  • Layer 4 (TCP or UDP protocol) and Layer 7 (HTTP or HTTPS protocol) listening

The correct answer is Layer 4 (TCP or UDP protocol) and Layer 7 (HTTP or HTTPS protocol) listening.

Q2: What are the common reasons for health check failures? (Single topic)

  • The backend ECS may not deploy the service

  • Health check is not enabled

The correct answer is that the backend ECS does not deploy services.

Extended Reading

Manual configuration

twenty

Tutorial Introduction

Through this tutorial, you will learn how to deploy Layer 4 and Layer 7 load balancing services on Alibaba Cloud traditional load balancing, forward requests from clients to back-end ECS, and simulate ECS single point of failure scenarios to verify the high availability of services.

Traditional load balancer : It has the basic load balancing capability of Layer 4 and Layer 7, which can expand the external service capability of the application system, eliminate single points of failure, and improve the availability of the application system. For more information, see What is traditional load balancing CLB  image.. png

Description of probationary benefits

Only users who use the load balancing product for the first time can receive it once 3 natural months Free trial of traditional load balancing CLB. (Natural month refers to the period from the 1st day of each month to the last day of the month, which is calculated according to the solar calendar.)

  • The monthly CLB includes 750 hours of free trial quota (shared by multiple CLB instances)

  • The monthly CLB includes 15 LCUs for free trial (shared by multiple CLB instances)

The trial benefits received from the above traditional load balancing CLB cards are all pay as you go CLB instances.

What can I learn

  • Learn how to create CLB instances.

  • Learn how to configure Layer 4 monitoring and complete the request forwarding of Layer 4 load balancing.

  • Learn how to configure Layer 7 monitoring and complete the request forwarding of Layer 7 load balancing.

Operation difficulty

in

Time required

20 minutes

AliCloud products used

Required expenses

After receiving the free trial benefits of CLB and ECS and opening the CDT service, you can complete this tutorial for free and experience the free load balancing service within the validity period of the benefits. Please see the next step for the access Prepare resources and environment

Please refer to CLB charging rules ECS Billing Rules Public network fee CDT public network traffic billing rules

Prepare resources and environment

three

Resource requirements

Deploying the CLB load balancing service requires one CLB instance and two ECS instances, and the CLB instance and ECS instance belong to the same region.

Get free benefits

Enter the following resource collection portal and click Login/Registration Button, and complete account login (existing AliCloud account), account registration (no AliCloud account), or real name authentication (personal real name authentication or enterprise real name authentication according to the requirements of the trial product) according to the page prompts.

If you Existing corresponding resources , you may not receive free benefits, please go directly to the next step Check Resources

Resource collection entrance

This tutorial configures

Get traditional load balancing CLB

750 hours per month 15 LCUs (Free: 750 hours of instance usage per month, 15 LCUs per month, 3 months)

  • Region and zone : Selection of this article East China 1 (Hangzhou) Region, zone configuration on demand

  • Instance billing method : Billing by usage

  • Instance Type : Public network

  • IP version :IPv4

  • Trial quantity :1

  • Other parameters: keep the default value or select as required

Get ECS

2 cores, 4GB, 3 months

  • region : Select The same region as the CLB instance

  • Operating system: CentOS 7.9 64 bit

  • Trial quantity: 2 (ECS01, ECS02)

  • Other parameters: keep the default value or select as required

Enable cloud data transmission CDT

CDT gives 200GB of free public network traffic every month (20GB of which is available in all regions, and 180GB is only available in overseas regions), which can be used to offset the public network traffic of ECS, elastic public network IP, and traditional load balancing CLB. The excess part will be charged by steps. For details, refer to CDT public network traffic billing rules

Check Resources

Sign in Traditional load balancing CLB console and ECS Console Check whether the CLB instance and ECS instance are in the same region. If they are not in the same region, see Create and manage CLB instances Customized purchase of ECS instances Create related resources.

Deploy application

three

  1. Sign in ECS Console

  2. In the upper left corner of the top menu bar, select the same region as ECS 01 and ECS 02 instances.

  3. Set ECS 01 and ECS 02 instance login passwords. Click in the Action column image.. png >Instance Properties>Reset Instance Password , set the login password of the ECS instance according to the interface prompts. After saving the password, on the pop-up page, click Restart Now Make the password effective.

    Resetting the instance password is supported about 3-5 minutes after the instance creation is completed. If it cannot be reset, please wait patiently and try again.

  4. Connect ECS 01 and ECS 02 instances remotely.

    1. return example Page, click Remote connection

    2. In the pop-up connection and command dialog box, click Connect remotely through Workbench Corresponding Sign in now

    3. In the pop-up login instance dialog box, enter the login information.

  5. Execute the following commands to deploy the Nginx static page for the ECS 01 instance. The following command takes CentOS 7.9 64 bit operating system as an example.

    yum install -y nginx

    systemctl start nginx.service

    cd /usr/share/nginx/html/

    echo "Hello World ! This is ECS01." > index.html

  6. Execute the following commands to deploy the Nginx static page for the ECS 02 instance. The following command takes CentOS 7.9 64 bit operating system as an example.

    yum install -y nginx

    systemctl start nginx.service

    cd /usr/share/nginx/html/

    echo "Hello World ! This is ECS02." > index.html

Configure CLB listening

seven

Configure Layer 4 Monitoring

  1. Sign in Traditional load balancing CLB console

  2. In the top menu bar, select the region where the CLB instance belongs. Selection of this article East China 1 (Hangzhou)

  3. stay Instance management Page, click the created CLB instance ID.

    After receiving the free trial benefits of CLB, the system will automatically create a CLB instance for you. It usually takes 1~3 minutes to create a CLB instance. Please wait patiently. When the instance status changes to In operation The CLB instance creation is completed.

  4. single click monitor Tab, in monitor Tab Click Add listening

  5. stay Protocol&Listening The configuration wizard completes the configuration of the following main parameters. The remaining parameters remain in the default configuration, and then click next step

    Listening configuration

    explain

    Sample value

    Select a load balancing protocol

    Select the protocol type to listen to.

    TCP

    Listening port

    Set the front-end protocol port, that is, the listening port used to receive requests and forward requests to the back-end server.

    Listening port range: 1~65535.

    eighty

    Listening name

    The name of the custom listener.

    TCP_80

  6. stay Back-end server Configuration wizard, selecting Default Server Group , and then click Continue adding

    1. stay Select Server In the configuration wizard, select the created ECS01 and ECS02 instances, and then click next step

    2. stay Configure Ports and Weights Configuration wizard, keep the default configuration, click add to

    3. Enter the ports of ECS01 and ECS02. In this tutorial, set them to 80, and then click next step

  7. stay Health Check Configuration Wizard, keep the default configuration, click next step , and then click Submit After the configuration is successful, click got it

Configure Layer 7 monitoring

  1. stay monitor Tab Click Add listening

  2. stay Protocol&Listening The configuration wizard completes the configuration of the following main parameters. The remaining parameters remain in the default configuration, and then click next step

    Listening configuration

    explain

    Sample value

    Select a load balancing protocol

    Select the protocol type to listen to.

    HTTP

    Listening port

    Set the front-end protocol port, that is, the listening port used to receive requests and forward requests to the back-end server.

    Listening port range: 1~65535.

    eighty-one

    Listening name

    The name of the custom listener.

    HTTP_81

  3. stay Back-end server Configuration wizard, selecting Default Server Group , you can see the added ECS01 and ECS02.

  4. Enter the ports of ECS01 and ECS02. In this tutorial, set them to 80, and then click next step

  5. stay Health Check Configuration Wizard, keep the default configuration, click next step , and then click Submit After the configuration is successful, click got it

complete

five

Verifying Layer 7 Load Balancing

After creating a CLB instance and configuring Layer 7 monitoring, you can test whether the CLB instance distributes requests to the back-end ECS through the following methods, and simulate the ECS single point of failure scenario to verify the high availability of the business.

  1. Sign in Traditional load balancing CLB console , at CLB Instance management Page, on Service address Column to view and copy the public network service address of the CLB instance.

  2. Enter the public service address of the CLB instance in the browser http://120.XX.XX.50:81 To verify the CLB's 7-layer load balancing forwarding capability.

    Refresh the browser, and you can observe that the request is converted between two ECSs.

    The above verification process shows that CLB can distribute client traffic to different back-end servers.

     image

     image

Verifying Layer 4 Load Balancing

After creating a CLB instance and configuring Layer 4 monitoring, you can test whether the CLB instance distributes the request to the back-end ECS through the following methods, and simulate the ECS single point of failure scenario to verify the high availability of the business.

  1. Sign in Traditional load balancing CLB console , at CLB Instance management Page, on Service address Column to view and copy the public network service address of the CLB instance.

  2. Enter the public service address of the CLB instance in the browser http://120.XX.XX.50 You can observe that the request has been forwarded to a backend ECS server. The following operations take ECS01 as an example.

    1. Deactivate ECS01, refresh the public service address of the browser accessing the CLB instance, and you can observe that the request has been forwarded to ECS02.

    2. start-up ECS01 and wait for a few minutes.

    3. Deactivate ECS02, refresh the public service address of the browser accessing the CLB instance, and observe that the request has been forwarded to ECS01.

    The above verification process shows that when a single back-end server fails, CLB can still ensure service availability.

     image

     image

Cleaning and follow-up

two

clear

  1. The free trial rights of CLB are limited in duration, and CLB instances that are not released after the expiration of the rights may incur costs. After completing the tutorial, refer to the following scenarios to process CLB instances:

    • If you do not need to use the CLB instance, you can log in Traditional load balancing CLB console In the left navigation bar, select Traditional load balancing CLB (original SLB) > Instance management , on Instance management Page, find the target CLB instance in the operation Column Click one thousand one hundred and eleven > Release Settings , manually release the instance according to the interface prompts.

    • If you need to continue using the CLB instance, please recharge your AliCloud account at least one hour before the trial expires to ensure that the account amount is not less than 100.00 yuan. The CLB instance that has not been renewed upon expiration will be automatically stopped due to arrears. The CLB instance will be retained within 7 days of downtime, and the CLB instance and data will be automatically released after 7 days.

  2. This tutorial uses a personal ECS instance, which defaults to pay as you go instances. After completing the tutorial, please refer to the following scenarios to process ECS instances:

    • If you do not need to continue using the instance, you can Log in to the ECS console , find the target instance, and click in the operation column image.. png , search and click Release Settings , release the instance according to the interface prompt.

    • If you need to continue using the instance, please recharge your AliCloud account at least one hour before the trial expires to ensure that the account amount is not less than 100.00 yuan. Instances that have not been renewed upon expiration will be automatically shut down due to arrears. The instance will be retained within 15 days of downtime, and the instance and data will be automatically released after 15 days.

follow-up

During the probation period, you can continue to use traditional load balancing CLB products according to other business scenarios you want to test. For CLB related tutorials, see CLB Tutorial

summary

Common knowledge points

Question 1: What protocol monitoring does the CLB instance support? (Single topic)

  • Only Layer 4 (TCP or UDP protocol) listens

  • Layer 4 (TCP or UDP protocol) and Layer 7 (HTTP or HTTPS protocol) listening

The correct answer is Layer 4 (TCP or UDP protocol) and Layer 7 (HTTP or HTTPS protocol) listening.

Q2: What are the common reasons for health check failures? (Single topic)

  • The backend ECS may not deploy the service

  • Health check is not enabled

The correct answer is that the backend ECS does not deploy services.

Extended Reading