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
2. Start the experiment environment
Click Start Lab in the upper right corner of the page to start the experiment.
.
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.
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:
Go to the logon page of the Alibaba Cloud Management Console.
Enter the RAM user name and click Next.
Enter the RAM user password and click Log on.
After you log on to the console, the following page appears.
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
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
Refer to the figure below and go to the RDS console.
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.
Then, he details of the RDS instance appears.
Click Configure Whitelist.
Click Modify.
Set parameters as shown in the following figure and click OK.
The whitelist is added.
Check Internal Endpoint of the RDS instance again.
4.2 Create an account and database
Create a database named labex
.
Create a database standard account named labex
and authorize it.
User name: labex
Password: Aliyun-test
Now, you have created the database and the account for managing it. Next, try to connect to the ApsaraDB RDS for MySQL instance.
4.3 Insert data
Log on to the ECS console, as shown in the following figure.
Select US (Silicon Valley). Two ECS instances have been created.
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
Run the following command to create a table named course
in the labex
database:
use labex;
CREATE TABLE course(
id int,
describes varchar(200)
);
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.");
Run the following command. The data is inserted.
SELECT * FROM course;
Run the following command to exit the database:
exit;
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.
A bucket has been created. Click the name of the bucket.
Click Upload to upload the downloaded images.
The upload process is complete.
5.2 View domain names
Refer to the figure below to go to the Alibaba Cloud DNS console.
You can see the domain name currently assigned by the user, which will be used later.
5.3 Configure a domain name to accelerate
Click Map Custom Domain Name, as shown in the following figure.
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.
Click Not Configured to configure CDN acceleration.
Configure parameters and click Next, as shown in the following figure.
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.
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
.
Log on to the Alibaba Cloud Domain Name System (DNS) console.
Click the domain name which for you want to add a CNAME record.
Complete the settings, as shown in the following figure, and then click Confirm.
The CNAME record is added.
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.
Return to the OSS console and refresh the page. CDN acceleration has been configured for down.labexlab.cyou
.
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
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
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.
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.
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.
Log on to the SLB console, as shown in the following figure.
An SLB instance has been automatically created. Click Configure.
As shown in the following figure, select the protocol of the listener, set Listening Port to 80, and click Next.
Select Default Server Group and click Add More.
Select the two ECS instances and click Next.
Click Add.
Enter 80 in the Port column and click Next.
Click Next.
Confirm the configurations and click Submit.
Click OK.
After the configurations are completed, copy the public IP address of the SLB instance.
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.
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.
Due to the CDN acceleration, the latency is much lower and the page loading is faster.
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:
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.