Deploy a high-availability application cluster

更新时间:
复制 MD 格式

You can use Simple Application Load Balancer to deploy a high-availability application cluster. Unlike an application that runs on a single Simple Application Server instance, a high-availability application cluster can distribute traffic and elastically scale to ensure your application remains stable and available. This topic shows how to deploy this high-availability architecture by using Simple Application Server.

Prerequisites

A domain name is required. If you do not have a domain name, you can purchase one from Alibaba Cloud Domain Name Service. For more information, see What is Alibaba Cloud Domain Name Service?. You can also register a domain name with another provider.

Background information

A high-availability application cluster has the following features:

  • Simple Application Load Balancer distributes incoming traffic across multiple backend Simple Application Server instances. This increases application throughput, eliminates single points of failure, and improves application availability.

  • The custom image feature lets you quickly create Simple Application Server instances with identical applications. You can then add these instances to a Simple Application Load Balancer as backend servers to achieve elastic scaling.

In this example, you will use Simple Application Load Balancer, Simple Application Server, a domain name, and Alibaba Cloud DNS to deploy a high-availability application cluster. The following diagram shows the architecture.高可用架构示意图 The resources in this architecture are described as follows:

  • Region: A Simple Application Load Balancer instance supports only backend servers in the same region.

    In this example, the Simple Application Load Balancer and Simple Application Server instances are created in the China (Hangzhou) region.

  • Simple Application Server: The application servers and the database server are separate. This improves application throughput while ensuring data storage efficiency and data security.

    In this example, you will create two Simple Application Server instances as application servers (referred to as Server A and Server B) and one Simple Application Server instance as a database server (referred to as Server C).

  • Simple Application Load Balancer: By default, it uses the HTTP protocol (HTTPS is not currently supported), listens on port 80, and applies the round-robin algorithm for forwarding rules.

    In this example, you will create one Simple Application Load Balancer instance and add the two application servers as backend servers.

  • Domain name and Alibaba Cloud DNS: You must associate a domain name with the Simple Application Load Balancer instance to allow access to the backend servers.

    Therefore, you must use Alibaba Cloud DNS to create a CNAME record that maps your domain name (for example, example.com) to the public service address of the Simple Application Load Balancer instance.

Notes:

  • This example uses Nginx and PHP to build the application server environment and uses a WordPress blog as the sample application. The database server runs a MySQL database for data storage. To efficiently install the software on each server, this example uses BT-Panel to install and configure all software components. If you are familiar with server operations, you can install and configure the software manually.

  • If your domain name requires an ICP filing, you must subscribe to the Simple Application Server instance for at least three months.

  • In a high-availability cluster, you must ensure data is synchronized across all application servers. Because data synchronization is complex, this topic does not cover this requirement. When you deploy your own services, use a file synchronization tool like Syncthing or a combination of Rsync and Inotify to synchronize data between servers.

Step 1: Create and configure database server C

In this step, you will create a Simple Application Server instance using a BT-Panel application image, and then use BT-Panel to quickly install and configure MySQL 5.7.

  1. Create a Simple Application Server instance. For more information, see Create a Simple Application Server instance.

    This server is the database server (Server C).

    Note

    When using this server as a database server in a production environment, we recommend you select a plan with a higher memory specification to improve data processing performance.

    • Instance Type: Select Server Instance.

    • Region and Zone: Click the China tab, and then select China (Hangzhou).

    • Image: Click the Application Images tab, and then select the BT-Panel 7.5.1 image.

    • Plan: Select the CNY 60/month ultra cloud disk plan.

    • Data Disk: In this example, no data disk is attached.

      If you need to store a large amount of data for your services, attach a data disk of an appropriate capacity.

    • Duration: Select 3 Months.

      If your domain name does not have an ICP filing, you can apply for one only if your subscription duration for the Simple Application Server instance is three months or longer.

    • Quantity: 1.

  2. In the firewall for Server C, add a rule to allow traffic on port 3306 (the default MySQL port) and port 8888 (the BT-Panel port).

    For more information about how to add a firewall rule, see Manage firewalls.

    After you add the firewall rule, the allowed port appears in the firewall rule list.

  3. Log in to BT-Panel.

    1. Click the server card of the instance.

    2. Click the Application Details tab. In the BT-Panel Information section, copy the relevant commands, and then click Connect.

    3. In the remote connection dialog box, click Log on Now and paste the copied command to get the external panel URL, username, and password.

      Note

      Keep your username and password secure to prevent data leaks.

      [root@xxx ~]# sudo /etc/init.d/bt default | grep 外网面板地址
      External panel URL: http://xxx:8888/xxx
      [root@xxx ~]# sudo /etc/init.d/bt default | grep password
      password: xxx
      [root@xxx ~]# sudo /etc/init.d/bt default | grep username
      username: xxx
    4. On your local machine, open a browser and go to the external panel URL. Enter the username and password, and then click Logon.

    5. The first time you log in to BT-Panel, you must read and agree to the user agreement in the Welcome to BT-Panel dialog box. Then, click Enter Panel.

      After you enter the panel, a dialog box appears recommending a software suite. Because Server C is a database server that requires only MySQL, you can close this dialog box.

    6. Bind your BT-Panel account.

      You must bind your BT-Panel account to use the panel. Register an account on the official BT-Panel website and log in.

  4. Install the MySQL database.

    1. In the left-side navigation pane of BT-Panel, click App Store.

    2. In the App Search box, enter MySQL and search.

    3. In the search results, find MySQL and click Install in the Actions column.

    4. In the Install mysql dialog box, configure the settings and click Commit.

      The settings are described as follows:

      • Installation Version: Select mysql 5.7.

      • Installation Method: Select Fast installation.

    5. In the Software Installation dialog box, click Confirm.

      The installation may take some time. You can check the progress in the Message Box that automatically appears.

      When the message box shows No tasks currently!, the MySQL installation is complete.

  5. Configure the MySQL database.

    1. In the left-side navigation pane, click Databases.

    2. In the upper-left corner of the page, click Add Database.

    3. In the Add Database dialog box, configure the settings and click Commit.

      The settings are described as follows:

      • Database: Enter a custom name, such as wptest.

      • Username: Enter a username to access the wptest database, such as wpuser.

      • Password: Enter a password for the database. Although a random password is provided, we recommend setting a custom one, such as WPtest123.

        Important

        Keep your username and password secure to prevent data leaks.

      • Access Privileges: Everyone.

        Important

        Granting fully open access privileges does not protect your data. After you create the application servers, you must return to the BT-Panel of the database server, set the MySQL Access Privileges to Specified IP, and then specify the internal IP address of each application server.

      • Keep the default values for all other settings.

      After the database is added, you can view the wptest database information on the current page.

    4. In the left-side navigation pane, click Security.

    5. In the Firewall section, allow traffic on the default MySQL port 3306.

      In the Firewall section on the Security page of BT-Panel, the upper area is for configuring ports to allow, where you can select the Allow Port type and enter a port number and description. The lower area lists the allowed ports, showing the status and the time each was added.

      1. In the port configuration area, enter 3306 for the port and add a remark, and then click Allow.

      2. After the port is allowed, it appears in the port list below.

Step 2: Create and configure application server A

In this step, you will create a Simple Application Server instance using a BT-Panel application image, and then use BT-Panel to quickly install and configure Nginx 1.21, PHP 7.2, and WordPress 5.6.

  1. Create a Simple Application Server instance. For more information, see Create a Simple Application Server instance.

    This server is an application server (Server A).

      • Instance Type: Select Server Instance.

      • Region and Zone: Click the China tab, and then select China (Hangzhou).

      • Image: Click the Application Images tab, and then select the BT-Panel 7.5.1 image.

      • Plan: Select the CNY 60/month ultra cloud disk plan.

      • Data Disk: In this example, no data disk is attached.

        If you need to store a large amount of data for your services, attach a data disk of an appropriate capacity.

      • Duration: Select 3 Months.

        If your domain name does not have an ICP filing, you can apply for one only if your subscription duration for the Simple Application Server instance is three months or longer.

      • Quantity: 1.

  2. In the firewall for Server A, add a rule to allow traffic on port 8888 for BT-Panel.

    For more information about how to add a firewall rule, see Manage firewalls.

  3. On the Application Details tab for Server A, obtain the BT-Panel logon information and log in to BT-Panel. For more information, see Log in to BT-Panel.

  4. Use BT-Panel to install Nginx 1.21 and PHP 7.2.

    1. In the left-side navigation pane of BT-Panel, click App Store.

    2. In the App Search box, enter Nginx and search.

    3. In the search results, find Nginx and click Install in the Actions column.

    4. In the Install nginx dialog box, configure the settings and click Commit.

      The settings are described as follows:

      • Installation Version: Select nginx 1.21.

      • Installation Method: Select Fast installation.

    5. In the Software Installation dialog box, click Confirm.

      The installation may take some time. You can check the progress in the Message Box that automatically appears.

      When the message box shows No tasks currently!, the Nginx installation is complete.

    6. Follow the same steps to search for PHP and install PHP 7.2.

      In the search results, select version PHP-7.2, select Fast installation as the installation method, and click Submit.

      After you install Nginx and PHP, go to the App Store. In the App Classification section, click Installed to view the installed Nginx 1.21 and PHP 7.2.

  5. Use BT-Panel to deploy a WordPress site with one click.

    1. In the left-side navigation pane of BT-Panel, click App Store.

    2. In the App Classification section, click One-Click Deployment.

    3. In the App Search box, enter WordPress and search.

    4. In the search results, find WordPress and click One-Click Deployment in the Actions column.

    5. In the BT-Panel One-Click WordPress Deployment dialog box, complete the configuration and click Submit.

      The settings are described as follows:

      • Domain: Enter your domain name and the public IP address of Server A on separate lines, in the following format:

        example.com
        47.96.XX.XX

        After you enter these values, the default settings for Remarks, Root directory, and Database are automatically updated.

        Note

        At this stage, you do not need to perform DNS resolution or domain association for example.com.

      • Remarks: We recommend that you do not use the domain name for remarks. Manually change the remarks, for example, to wordpresstest.

      • Root directory: We recommend that you do not use the domain name as the root directory name. Manually change the root directory, for example, to /www/wwwroot/wordpress.

      • Database: Leave this field empty. If there are default values, delete them.

      • Keep the default values for all other settings.

      After you deploy WordPress, click Websites in the left-side navigation pane to view information about your running WordPress site.

  6. Install WordPress.

    1. On your local machine, open a browser and access the public IP address of Server A.

      Because DNS resolution and domain association are not yet complete for example.com, you must use the server's public IP address to access the WordPress installation page.

    2. Select a language for WordPress and click Continue.

      This example uses Simplified Chinese.

    3. Click Let's go!.

    4. Configure the database connection information and click Commit.

      These settings come from database server C. In this example, use the following values. In your environment, enter the actual values from your database server.

      • Database Name: wptest

      • Username: wpuser

      • Password: WPtest123

      • Database Host: Internal IP address of Server C:3306

      • Table Prefix: Keep the default value.

    5. Click Run the installation.

    6. Configure your WordPress site information and click Install WordPress.

      The settings are described as follows:

      • Site Title: Enter a custom title for your WordPress site. For example, wp-HA-test.

      • Username: Enter a username to log in to WordPress. For example, wpadmin.

      • Password: Enter a password to log in to WordPress. We recommend that you set a strong, custom password. For example, WP123!password456.

        Important

        Keep your username and password secure to prevent data leaks.

      • Your Email: Enter your email address to receive notifications from the WordPress site. For example, username@example.com.

    7. On the Success! page, click Log In and use your configured username and password to log in to WordPress.

      After you log in, the WordPress dashboard appears.

Step 3: Create server B from a custom image

You can use the custom image feature of Simple Application Server to quickly create application server B with the same configuration as application server A.

  1. Create a snapshot for Server A. For more information, see Create a snapshot.

  2. Create a custom image from the snapshot of Server A. For more information, see Create a custom image.

  3. Create application server B from the custom image. For more information, see Create a server from a custom image.

    When you create application server B, set Image to the custom image. Keep all other settings exactly the same as for application server A.

  4. In the firewall for Server B, add a rule to allow traffic on port 8888 for BT-Panel.

    For more information about how to add a firewall rule, see Manage firewalls.

  5. Configure the website settings for application server B.

    After creating Server B, attempting to access its public IP address returns a Site not found error. This is because the BT-Panel site settings still use the public IP address of Server A. To fix this, you must log in to the BT-Panel for Server B and add its public IP address to the domain settings.

    1. Log in to the BT-Panel for Server B.

      The username and password for the BT-Panel of Server B are the same as for Server A. However, the login URLs are different. For example:

      • The login URL for the BT-Panel of Server A is http://<public IP address of Server A>:8888/db08****.

      • The corresponding login URL for the BT-Panel of Server B is http://<public IP address of Server B>:8888/db08****.

    2. After you log in to BT-Panel, click Panel Settings in the left-side navigation pane.

    3. Find the Server IP setting, enter the public IP address of Server B in the text box, and then click Save at the bottom of the page.

    4. In the left-side navigation pane, click Websites.

    5. Find the site whose name is the public IP address of Server A or the associated domain name. In the Actions column, click Settings.

    6. On the Modify Site page, click Domain Manager in the left-side navigation pane.

    7. In the text box, enter the public IP address of Server B and click Add.

      After the address is added, the new public IP address of Server B appears in the domain list.

  6. On your local machine, open a browser and test access to the public IP address of Server B.

    You should be able to access the WordPress site successfully.

Step 4: Modify database permissions

You have now created two application servers (Server A and Server B). To secure data transmission between the application servers and the database server, we recommend changing the MySQL access permission on database server C from Everyone to Specified IP and specifying the internal IP addresses of the two application servers.

  1. Log in to the BT-Panel for database server C. For more information, see Log in to BT-Panel.

  2. After you log in to BT-Panel, click Databases in the left-side navigation pane.

  3. Find the wptest database and click Permission in the Actions column.

  4. In the Set Database Permissions dialog box, select Specified IP from the Access Privileges list. In the new text box that appears, enter the internal IP addresses of Server A and Server B.

    Simple Application Server instances in the same region can communicate over the internal network, which is more efficient and stable than public network access. Separate multiple internal IP addresses with commas (,), for example, 172.27.XX.XX,172.27.XX.XX.

  5. Click Commit.

Step 5: Create a load balancer and add backends

  1. Create a Simple Application Load Balancer instance. For more information, see Create a Simple Application Load Balancer instance.

    The settings in this example are described as follows:

    • Instance Type: Select Load Balancer Instance.

    • Region and Zone: Select China (Hangzhou).

    • Plan: CNY 60/month.

    • Duration: Select 3 Months.

  2. Add backend servers. For more information, see Add backend servers.

    In this example, add application server A and application server B as backend servers. Ensure their health check status is Healthy.

Step 6: Resolve and associate the domain name

To distribute public traffic with a Simple Application Load Balancer, you must first associate a domain name with the instance.

  1. Use Alibaba Cloud DNS to create a CNAME record that resolves the domain name example.com to the public service address of the Simple Application Load Balancer instance.

    The public service address of the Simple Application Load Balancer instance is the DNS information displayed on the load balancer's overview page in the Simple Application Server console.

    For more information about how to resolve a domain name, see Add a CNAME record.

  2. Associate the domain name.

    After resolving example.com to the Simple Application Load Balancer instance via a CNAME record, you must also associate the domain name with the load balancer instance. For more information, see Associate a domain name.

Step 7: Test access to the WordPress site

  • Test access to the WordPress blog site

    On your local machine, open a browser and go to the domain name example.com. If you can access the WordPress homepage, the high-availability application cluster is deployed successfully.

  • Simulate a Server A failure and test access to the WordPress blog site

    1. In the Simple Application Server console, manually stop Server A.

      Manually stopping the server simulates a server failure. The status of Server A changes to Stopped.

    2. Check the status of the backend servers for the Simple Application Load Balancer instance.

      The health check status of the stopped Server A is Unhealthy, while the status of the running Server B is Healthy.

    3. On your local machine, open a browser and go to the domain name example.com.

      You can still access the WordPress homepage. This indicates that the high-availability architecture is working correctly. Your traffic is now being routed to the healthy Server B.