arrow

Set Up A Typical Web Application On Alibaba Cloud

1. Experiment

1.1 Knowledge points

Alibaba Cloud services such as Elastic Compute Service (ECS), ApsaraDB for RDS (RDS), Object Storage Service (OSS), Server Load Balancer (SLB), and Alibaba Cloud CDN are used in this experiment. This lab walks you throuth the steps to set up a typical application on Alibaba Cloud. You will install Django on two ECS instances and set up an SLB instance to distribute traffic among the ECS instances. You will create an ApsaraDB RDS for MySQL database and connect to it from the ECS instances.You Will also set up CDN to accelerate website loading.

1.2 Experiment process

  • Experiment scenario
  • Insert data into the ApsaraDB RDS for MySQL database
  • Use Alibaba Cloud CDN to accelerate content delivery
  • Activate the ECS service
  • Configure an SLB instance

1.3 Cloud resources required

  • ECS
  • RDS
  • OSS
  • Alibaba Cloud CDN
  • SLB

1.4 Prerequisites

  • <font color='red'>This experiment requires that you have a domain name</font>

  • If you are using your own Alibaba Cloud account instead of the account provided by this lab to operate the experiment, please note that you’ll need to choose the same Ubuntu 16.04 operating system for your ECS in order to run the experiment smoothly.
  • Before starting the experiment, please confirm that the previous experiment has been closed normally and exited.

2. Start the experiment environment

Click Start Lab in the upper right corner of the page to start the experiment.

image desc.

After the experiment environment is started, the system has deployed resources required by this experiment in the background, including the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Web console of Alibaba Cloud is also provided.

image desc

After the experiment environment is started and related resources are properly deployed, the experiment starts a countdown. You have two hours to perform experimental operations. After the countdown ends, the experiment stops, and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Next, use the username and password provided by the system to log on to the Web console of Alibaba Cloud and view related resources:

openCole

Go to the logon page of the Alibaba Cloud Management Console.

image desc

Enter the RAM user name and click Next.

image desc

Enter the RAM user password and click Log on.

image desc

After you log on to the console, the following page appears.

image desc

3. Experiment scenario

3.1 Business need

When it comes to launching a new business online, enterprises look for agile and cost-effective deployments. The goal is to scale up the business rapidly if it is well-received by the market, and to minimize financial losses in case of failure.

3.2 Our solution

To help you efficiently deploy new applications at lower costs, Alibaba Cloud supports the deployment of applications that feature separate application and database systems, reverse proxy load balancing, and accelerated conten delivery.

Such a solution offers high performance, is highly scalable, and can be stopped at any time, providing great flexiblility for new business ventures.

3.3 Use cases

image desc

This solution applies to the following use cases:

  • Quickly setting up an application based on separate application and database servers.
  • Enabling automatic failover and horizontal scaling to improve application availability.
  • Setting up efficient caching to speed up website loading and reduce latency.
  • Core services are deployed on multiple ECS instances, which are connected to an SLB instance to ensure high application availability.
  • CDN delivers data at high transfer speeds to minimize latency.
  • ApsaraDB RDS for MySQL is a stable and reliable database service and OSS provides secure and cost-effective data storage.
  • Subsystems that provide non-core services are deployed on single ECS instances along with database services.

4. Insert data into the ApsaraDB RDS for MySQL database

4.1 Configure the whitelist

Refer to the figure below and go to the RDS console.

image desc

Select US (Silicon Valley). An ApsaraDB RDS for MySQL instance is being created. Please wait a few minutes.

After the creation is complete, click Manage.

image desc

Then, he details of the RDS instance appears.

image desc

Click Configure Whitelist.

image desc

Click Modify.

image desc

Set parameters as shown in the following figure and click OK.

image desc

The whitelist is added.

image desc

Check Internal Endpoint of the RDS instance again.

image desc

4.2 Create an account and database

Create a database named labex.

image desc

image desc

Create a database standard account named labex and authorize it.

image desc

User name: labex

Password: Aliyun-test

image desc

image desc

Now, you have created the database and the account for managing it. Next, try to connect to the ApsaraDB RDS for MySQL instance.

image desc

4.3 Insert data

Log on to the ECS console, as shown in the following figure.

image desc

Select US (Silicon Valley). Two ECS instances have been created.

image desc

Copy the public IP address of an ECS instance to remotely log on to the ECS instance. For more information about remote logon, see How to Remotely Log in to Alibaba Cloud’s ECS Server.

The default user name and password of the ECS instance:

User name: root

Password: nkYHG890..

After you log on to the ECS instance, run the following command to connect the ECS instance to your ApsaraDB RDS for MySQL database. Note: Replace YOUR-RDS-PRIVATE-ADDR with the internal IP address of your ApsaraDB RDS for MySQL instance.

mysql -hYOUR-RDS-PRIVATE-ADDR -ulabex -pAliyun-test

image desc

Run the following command to create a table named course in the labex database:

use labex;

CREATE TABLE course(
    id  int,
    describes  varchar(200)
);

image desc

Run the following command to insert the data into the course table:

INSERT INTO course VALUES (1, "This experiment involves Alibaba Cloud Container Service for Kubernetes");
INSERT INTO course VALUES (2, "In this experiment, Alibaba Cloud API Gateway is used");
INSERT INTO course VALUES (3, "This experiment mainly uses the Alibaba Cloud OSS product");
INSERT INTO course VALUES (4, "This experiment uses Alibaba Cloud Migration Tool");
INSERT INTO course VALUES (5, "This experiment uses AnalyticDB for PostgreSQL");
INSERT INTO course VALUES (6, "This experiment uses Alibaba Cloud Table Store");
INSERT INTO course VALUES (7, "This experiment describes how to use Alibaba Cloud Operation Orchestration Service");
INSERT INTO course VALUES (8, "This experiment uses Alibaba Cloud Function Compute");
INSERT INTO course VALUES (9, "In this experiment, Alibaba Cloud Elasticsearch is used.");

image desc

Run the following command. The data is inserted.

SELECT * FROM course;

image desc

Run the following command to exit the database:

exit;

image desc

5. Use Alibaba Cloud CDN to accelerate content delivery

5.1 Upload images

Enter the following URLs in the address bar of your browser to download the demo images to your computer:

http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/1.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/2.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/3.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/4.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/5.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/6.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/7.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/8.png
http://labex-ali-data.oss-us-west-1.aliyuncs.com/web/9.png

Log on to the OSS console, as shown in the following figure.

image desc

A bucket has been created. Click the name of the bucket.

image desc

Click Upload to upload the downloaded images.

image desc

image desc

The upload process is complete.

image desc

5.2 View domain names

Refer to the figure below to go to the Alibaba Cloud DNS console.

image desc

You can see the domain name currently assigned by the user, which will be used later.

image desc

5.3 Configure a domain name to accelerate

Click Map Custom Domain Name, as shown in the following figure.

image desc

Enter a custom domain name and click Submit.Referring to the figure below, if the domain name assigned by the user is labexlab057.cyou, then add the prefix down0414.,Please name the prefix yourself as much as possible, such as adding a date and time flag to avoid the same.

image desc

Click Not Configured to configure CDN acceleration.

image desc

Configure parameters and click Next, as shown in the following figure.

image desc

image desc

image desc

After you add a custom domain name for CDN acceleration, you must add a CNAME record to your domain name system.

If your domain name is registered on Alibaba Cloud, you will obtain a document about how to add a CNAME record by clicking Add CNAME to Record. Click Return to Domain Names.

image desc

A message appears, indicating that a CNAME record has not been added. In this case, add a CNAME record that points down.labexlab.cyou to down.labexlab.cyou.w.kunlunsl.com.

image desc

Log on to the Alibaba Cloud Domain Name System (DNS) console.

image desc

Click the domain name which for you want to add a CNAME record.

image desc

Complete the settings, as shown in the following figure, and then click Confirm.

image desc

The CNAME record is added.

image desc

Return to the CND console. A message appears, indicating that the CNAME record has been added. Note: The information being displayed is not real-time. Refresh it after about 10 minutes.

image desc

Return to the OSS console and refresh the page. CDN acceleration has been configured for down.labexlab.cyou.

image desc

Enter the following URL in the address bar of your browser to test whether this domain name can be used to download files from OSS,Please replace it with the user’s own domain name

down0414.labexlab057.cyou/1.png

image desc

If the domain name can be used to download files from OSS, the domain name is accelerated.

6. Activate the ECS Service

An ECS instance has been remotely connected in the Section 3.3.

Return to the command line of the remote connection and run the following command. A Django project named labex_project is available.

ls 

cd labex_project

ls

image desc

Run the vim app1/views.py command to open the views.py file and modify the configurations, as shown in the following figure. Save the modification and exit.

image desc

Run the following command to start the Django project:

nohup python3 manage.py runserver 0.0.0.0:80 &

In the address bar of your browser, enter the public IP address of the current ECS instance. The ECS service is activated. The internal IP address of the current ECS instance is displayed in the center of the page.

image desc

Log on to the other ECS instance to perform the same operations. Enter the public IP address of the ECS instance in the address bar of your browser to test whether the ECS service is activated.

image desc

7. Configure an SLB instance

Log on to the SLB console, as shown in the following figure.

image desc

An SLB instance has been automatically created. Click Configure.

image desc

As shown in the following figure, select the protocol of the listener, set Listening Port to 80, and click Next.

image desc

Select Default Server Group and click Add More.

image desc

Select the two ECS instances and click Next.

image desc

Click Add.

image desc

Enter 80 in the Port column and click Next.

image desc

Click Next.

image desc

Confirm the configurations and click Submit.

image desc

Click OK.

image desc

After the configurations are completed, copy the public IP address of the SLB instance.

image desc

Paste the public IP address of the SLB instance into the address bar of your browser. After you refresh the page multiple times, different ECS instances are accessed.

image desc

image desc

The SLB instance distributes traffic to among the two ECS instances.

To test the effect of the CDN acceleration, use a new browser.

Open the developer page in your browser. When you access the images on OSS for the first time, the latency is high.

image desc

Due to the CDN acceleration, the latency is much lower and the page loading is faster.

image desc

Reminder:
Log off your Alibaba RAM user before you click stop to leave this lab. Otherwise you’ll encounter some issues when opening a new lab session in the same browser:

image descimage desc

8. Experiment summary

This lab walks you throuth the steps to set up a typical application deployment on Alibaba Cloud. To help you deploy new applications in an efficient and economical manner, Alibaba Cloud supports the deployment of applications that feature separate application and database systems, reverse proxy load balancing, and accelerated content delivery.
This solution offers high performance, is highly scalable, and can be stopped at any time, providing great flexibility for new business ventures. It enables you to quickly set up an application based on separate application and database servers; supports automatic failover and horizontal scaling to improve application availability; and allows you to set up efficient caching to speed up website loading and reduce latency.