Help Center/ Auto Scaling/ Best Practices/ Setting Up an Automatically Scalable Discuz! Forum
Updated on 2022-03-31 GMT+08:00

Setting Up an Automatically Scalable Discuz! Forum

Application Scenarios

Discuz! is one of the most mature and widely used forum software programs. Website traffic reaches its top in peak hours. If a forum website is deployed on multiple servers to cope with peak hours, some servers must be sitting idle at other times. This increases the costs and leads to a waste of resources.

AS helps you address the preceding problems. After you use AS on the servers for deploying a forum website, AS maintains the proper running of the website and reduces costs by automatically adjusting the number of servers based on the predefined scaling policy. This section describes how to use AS to automatically increase or reduce the number of ECSs for a web service, for example, Discuz!.

Solution Introduction

Table 1 lists the steps required to set up an automatically scalable Discuz! forum website. This section focuses on how to implement AS. The increase or decrease of website traffic causes the rise or drop of the ECS CPU usage. You can configure two CPU usage alarm policies, one for increasing one ECS when the CPU usage exceeds 70% and the other for reducing one ECS when the CPU usage is less than 30%. In this way, there will remain a proper number of ECSs for the forum website.

Table 1 Setting up a Discuz! forum

Step

Category

Substep

Description

Setting up a website

Applying for services

Applying for a VPC

Apply for 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 the ECS to access the Internet.

Creating a security group and adding a security group rule

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 an enhanced 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.

Implementing AS

N/A

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

Follow the instructions provided in Table 1 to set up the website. For details, see Setting Up a Discuz! Forum.

Creating an AS Configuration

An AS configuration specifies the specifications of ECS instances to be added. To enable the instances to automatically carry web services, use the image discuz_centos6.5 (40 GB) and ensure the parameter settings in the AS configuration the same as those of discuz02.

  1. Log in to the management console. Under Compute, click Auto Scaling.
  2. On the Instance Scaling page, click Create AS Configuration.
    Configure parameters listed in Table 2. Retain default settings for other parameters.
    Table 2 Key AS configuration parameters

    Parameter

    Description

    Example Value

    Configuration Template

    Select Create new template and configure the parameters, such as ECS type, vCPUs, memory, image, and disk, 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.

    sg-DISCUZ

    EIP

    Not required if you have enabled a load balancer in 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

  3. After setting the parameters, click Create Now.

Creating an AS Group

  1. Click Create AS Group.
    Configure parameters listed in Table 3. Retain default settings for other parameters.
    Table 3 Key AS group parameters

    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. 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.

    Enhanced load balancer

    Health Check Method

    ELB health check is recommended, in which heartbeat messages are sent to backend ECSs for check.

    ELB health check

  2. After setting the parameters, click Create Now.
  3. Back to the AS group list. The AS group is successfully created if its status changes to Enabled.

Creating an AS Policy

To automatically scale ECSs, configure two alarm policies to monitor CPU usage. One (as-policy-discuz01) is used to increase the number of ECSs when the website traffic rises, and the other (as-policy-discuz02) is used to reduce the number of ECSs when the website traffic drops.

  1. Locate the row containing the created AS group as-group-discuz and click View AS Policy in the Operation column.
  2. 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.

    The following scaling action options are available:
    • Add

      Adds instances to an AS group when the scaling action is performed.

    • Reduce

      Removes instances from an AS group when the scaling action is performed.

    • Set to

      Sets the expected number of instances in an AS group to a specified value.

    Add 1 instance

    Cooldown Period

    To prevent an alarm-based policy from being triggered repeatedly by the same event, configure a cooldown period.

    900

  3. Click OK.
  4. 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.
  5. Click OK.
  6. Back to the AS policy list. The AS policies are successfully created if their statuses change to Enabled.

Manually Adding an ECS to an AS Group

Perform the following operations to manually add ECS discuz02 to the AS group:

  1. Click the name of the AS group as-group-discuz to switch to the page providing details about the AS group.
  2. Click the Instances tab and manually add discuz02 to the AS group.

Changing the Minimum Number of Instances

To ensure that discuz02 is not removed from the AS group, perform the following operations to change the minimum number of instances:

  1. Click the name of the AS group as-group-discuz to switch to the page providing details about the AS group.
  2. Click Modify in the upper right corner of the page. Set Min. Instances to 1.
  3. Click OK.

Verifying Configurations

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.

Practice Extensions