Adding a Load Balancer to an AS Group to Automatically Add or Remove Backend Servers
After you add a load balancer to an AS group, Auto Scaling adds servers when there are sudden traffic spikes, and then removes them when traffic returns to normal, according to your configured policies. This saves resources and costs while maintains smooth service operation.
Scenarios
Increased website traffic raises cloud server CPU usage, which falls when traffic declines. In this case, you can configure two CPU usage alarm policies, one for adding a server when the CPU usage goes above 70% and the other for removing a server when the CPU usage drops below 30%. This ensures your website has the right number of servers as traffic changes.
Procedure
This practice provides an example for setting up a scalable Discuz! forum website.
Step |
Category |
Substep |
Description |
---|---|---|---|
Setting up a website |
Applying for resources |
Creating a VPC |
Create a VPC, for example, vpc-DISCUZ, that provides network services for the ECS on which the website is deployed. |
Purchasing an EIP |
Purchase an EIP that allows ECSs to access the Internet. |
||
Creating a security group and adding security group rules |
To ensure network security, create a security group, for example, sg-DISCUZ, to control network access. |
||
Purchasing ECSs |
Buy two ECSs, for example, discuz01 for deploying the forum database and discuz02 for deploying the forum. Bind the purchased EIP to the ECS discuz01 when purchasing discuz01. |
||
Configuring the ECSs |
Installing the database on discuz01 |
Install an RDS for MySQL DB instance on discuz01, start the database, and configure it to automatically start upon ECS startup. |
|
Deploying the website code on discuz02 |
Unbind the EIP from discuz01, bind it to discuz02, and deploy a web environment and website code on discuz02. |
||
Configuring features |
Unbinding the EIP |
To save EIP resources, release the EIP bound to discuz02 before using the load balancing service. |
|
Configuring ELB |
Purchase a dedicated load balance listener, for example, elb-DISCUZ, to balance the website traffic in an AS group. |
||
Creating an image |
To ensure that the ECSs to be added to the AS group automatically deploy the web environment and website code, create an image, for example, discuz_centos6.5 (40 GB) based on discuz02. The image is used as a private one for creating an AS configuration. |
||
Configuring AS |
- |
Creating an AS configuration |
An AS configuration is an ECS template in the AS group, specifying specifications of the ECS to be added. Create an AS configuration, for example, as-config-discuz. |
Creating an AS group |
An AS group is the basis for performing scaling actions. Create an AS group, for example, as-group-discuz. |
||
Creating an AS policy |
An AS policy triggers scaling actions. Configure two CPU usage alarm policies for increasing or reducing the number of ECSs when website traffic rises or drops. |
||
Manually adding an ECS to an AS group |
To ensure that discuz02 and the ECSs to be added to the AS group carry forum services together, manually add discuz02 to the AS group. |
||
Configuring Min. Instances |
Min. Instances defines the minimum number of ECSs in an AS group. When the parameter is set to 1, there is at least one ECS in the AS group. The ECS discuz02 is manually added and has the lowest priority to be removed when Instance Removal Policy is configured. Therefore, configuring Min. Instances prevents discuz02 from being removed. |
||
Visiting the forum website |
Verifying the configuration |
Checking whether the forum website can be accessed |
Obtain the EIP bound to the load balancer and visit http://EIP/forum.php. If the forum website is accessible, the configurations have taken effect. |
Preparations
- Set up a Discuz! forum.
- Create a dedicated load balancer (elb-DISCUZ), bind an EIP to the load balancer, and ensure that the load balancer and the AS group are in the same VPC.
- Create a backend server group and associate it with dedicated load balancer elb-DISCUZ.
Step 1: Create an AS Configuration
An AS configuration specifies the specifications of servers to be added. To enable the servers to automatically run web services, use the image discuz_centos6.5 (40 GB) and ensure the parameter settings in the AS configuration are the same as those of discuz02.
- Log in to the management console. Under Compute, click Auto Scaling.
- On the Instance Scaling page, click Create AS Configuration.
Configure parameters listed in Table 2. Retain default settings for other parameters.
Table 2 Parameters required for creating an AS configuration Parameter
Description
Example Value
Configuration Template
Select Create new template and configure the parameters, such as the ECS type, vCPUs, memory, image, and disks, to create an AS configuration.
Create new template
Specifications
You can select multiple flavors to minimize the probability of capacity expansion failures due to insufficient resources of a flavor. Set Flavor selection policy to Sequenced or Cost-centric as required.
s3.medium.2
s3.large.2
Image
Specifies the software and system configuration template for the instances in an AS group.
discuz_centos6.5 (40 GB)
Disk
Stores data and manages the stored data for the instances in an AS group.
System disk: high I/O, 40 GB
Data disk: high I/O, 100 GB
Security Group
Controls ECS access within or between security groups by defining access rules. Select security group sg-DISCUZ.
sg-DISCUZ
EIP
Not required if you have configured a load balancer for an AS group. The system automatically associates instances in the AS group to the load balancer. These instances will provide services via the EIP bound to the load balancer.
Do not use
- After setting the parameters, click Create Now.
Step 2: Create an AS Group and Associate It with the Load Balancer
- Click Create AS Group.
Configure parameters listed in Table 3. Retain default settings for other parameters.
Table 3 Parameters required for creating an AS group Parameter
Description
Example Value
Max. Instances
Specifies the maximum number of instances in an AS group.
50
Expected Instances
Specifies the expected number of instances in an AS group. The ECSs in this practice are manually added to the AS group. To prevent scaling actions before the manually adding, set Expected Instances to 0.
0
Min. Instances
Specifies the minimum number of instances in an AS group.
0
VPC
Provides the network used by instances in an AS group. Ensure that the parameter value is the same as the VPC in which discuz02 is deployed.
VPC-DISCUZ
Subnet
Manages networks in the VPC. Select the subnet created when you apply for the VPC.
vpc-test
Load Balancing
Evenly distributes traffic to instances in an AS group. Select the dedicated load balancer elb-DISCUZ. A backend port is a service port on which a backend ECS listens for traffic. For example, set Backend Port to 80 and Weight to 1.
Dedicated load balancer
Health Check Method
ELB health check is recommended, in which heartbeat messages are sent to backend ECSs for check.
ELB health check
- After setting the parameters, click Create Now.
- Back to the AS group list. The AS group is successfully created if its status changes to Enabled.
Step 3: Create an AS Policy
To automatically scale cloud servers, configure two alarm policies to monitor CPU usage, one (as-policy-discuz01) for adding servers when the website traffic rises, and the other (as-policy-discuz02) for removing servers when the website traffic drops.
- Locate the row containing the created AS group as-group-discuz and click View AS Policy in the Operation column.
- On the displayed page, click Add AS Policy.
Configure parameters listed in Table 4 for as-policy-discuz01. When the system detects that the CPU usage exceeds 70% for three consecutive times, as-policy-discuz01 is triggered and an ECS is added to the AS group.
Table 4 Key parameters for creating AS policy as-policy-discuz01 Parameter
Description
Example Value
Policy Name
Specifies the name of the AS policy to be created.
as-policy-discuz01
Policy Type
Select Alarm.
Alarm
Alarm Rule
Specifies whether a new alarm rule is to be created (Create) or an existing alarm rule will be used (Use existing).
Create
Rule Name
Specifies the name of the alarm rule.
as-alarm-cpu-01
Monitoring Type
Specifies the type of monitoring metrics, which can be System monitoring or Custom monitoring. Select System monitoring.
System monitoring
Trigger Condition
Select monitoring metrics supported by AS and set alarm conditions for the metrics.
CPU Usage Max. >70%
Monitoring Interval
Specifies the interval at which the alarm status is updated based on the alarm rule.
5 minutes
Consecutive Occurrences
Specifies the number of sampling points when an alarm is triggered.
3
Scaling Action
Specifies an action and the number or percentage of instances.
Add 1 instance
Cooldown Period
To prevent an alarm-based policy from being triggered repeatedly by the same event, configure a cooldown period.
900
- Click OK.
- Click Add AS Policy again and create AS policy as-policy-discuz02. When the system detects that the CPU usage is lower than 30% for three consecutive times, as-policy-discuz02 is triggered and an ECS is removed from the AS group.
- Click OK.
- Back to the AS policy list. The AS policies are successfully created if their statuses change to Enabled.
Step 4: Add the Server to the AS Group
Manually add ECS discuz02 to the AS group.
- Click the name of the AS group as-group-discuz to switch to the page providing details about the AS group.
- Click the Instances tab and manually add discuz02 to the AS group.
Step 5: Modify the Minimum Number of Instances
Modify the minimum number of instances to ensure discuz02 is not removed from the AS group.
- Click the name of the AS group as-group-discuz to switch to the page providing details about the AS group.
- Click Modify AS Group in the upper right corner of the page. Set Min. Instances to 1.
- Click OK.
Step 6: Verify Traffic Routing
Check whether the forum website can be used. If the CPU usage of ECSs in the AS group remains higher than 70%, as shown on the Monitoring tab of the page providing details about the AS group, an ECS will be automatically added to the AS group (shown on the Scaling Actions tab). If the CPU usage remains lower than 30% and the AS group contains at least two ECSs, an ECS will be automatically removed from the AS group. If not, contact technical support to locate the fault.
Helpful Links
- To deploy new applications on cloud servers, use AS lifecycle hooks to add and remove cloud servers to and from an AS group and manage the lifecycle of these cloud servers in the AS group. For details, see Managing Lifecycle Hooks.
- To modify the specifications of servers in an AS group, create a new AS configuration first. For details, see Creating an AS Configuration from a New Specifications Template. Then, replace the AS configuration used by the AS group with the one you created. For details, see Changing the AS Configuration for an AS Group.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot