How to quickly create Nginx using OSS and ROS
Resource Orchestration Service (ROS) lets you define required Alibaba Cloud resources, such as ECS instances and their dependencies, in a template. The ROS orchestration engine then automatically provisions and configures all the resources based on the template, enabling automated deployment and maintenance. This topic shows you how to deploy an Nginx application using Object Storage Service (OSS) and ROS.
Prerequisites
-
A bucket has been created with its access control list (ACL) set to Private. For more information about how to create a bucket, see Create buckets.
You have downloaded the Nginx installation package.
Step 1: Upload the Nginx package to a bucket
-
Log on to the OSS console.
-
In the left-side navigation pane, click Buckets. On the page that appears, click the name of the target bucket.
In the left-side navigation pane, choose
Upload the Nginx installation package that you downloaded.
When you upload the object, set its ACL to Public Read and keep the default settings for other parameters. For more information, see Upload objects.
Obtain the object URL.
After the file upload is complete, click View Details to the right of the Nginx installation package file, and then click Copy Object URL.
Step 2: Create a stack with ROS
Select a template.
Log on to the ROS console.
In the left-side navigation pane, click Stacks.
In the top navigation bar, select China (Hangzhou) from the region drop-down list.
On the Stacks page, click Create Stack. Set Specify Template to Select an Existing Template and Template Import Method to Enter Template Content. On the JSON tab, paste the following template content and then click Next.
{ "ROSTemplateFormatVersion": "2015-09-01", "Description": "", "Parameters": { "NginxDownloadUrl": { "Type": "String", "Description": { "en": "The download URL of the nginx-*.rpm package." }, "Label": { "en": "Nginx Download URL" } }, "ZoneId": { "AssociationProperty": "ALIYUN::ECS::Instance:ZoneId", "Type": "String", "Description": { "en": "The ID of the availability zone.<br><b>Note: <font color='blue'>Before you select an availability zone, make sure that it supports the instance type that you want to create. We recommend that you choose an availability zone different from those of your other VSwitches.</font></b>" }, "Label": { "en": "VSwitch Availability Zone" } }, "ImageId": { "Default": "centos_7", "Type": "String", "Description": { "en": "The ID of the image. Use a CentOS 7 image. For more information, see <b><a href='https://www.alibabacloud.com/help/en/doc-detail/112977.html' target='_blank'><font color='blue'>Find images</font></a></b>." }, "Label": { "en": "Image" } }, "InstanceType": { "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType", "AssociationPropertyMetadata": { "ZoneId": "ZoneId" }, "Label": { "en": "Instance Type" }, "Type": "String", "Description": { "en": "<font color='blue'><b>1. Before you select an instance type, ensure it is available in the selected availability zone.</b></font><br><font color='blue'><b>2. Available instance types:</font><br>[ecs.c5.large <font color='green'>2 vCPU, 4 GiB memory, 1 Gbit/s internal network bandwidth, 300,000 PPS</font>]<br>[ecs.c5.xlarge <font color='green'>4 vCPU, 8 GiB memory, 1.5 Gbit/s internal network bandwidth, 500,000 PPS</font>]<br>[ecs.c5.2xlarge <font color='green'>8 vCPU, 16 GiB memory, 2.5 Gbit/s internal network bandwidth, 800,000 PPS</font>]" } }, "SystemDiskCategory": { "Default": "cloud_efficiency", "Label": { "en": "System Disk Type" }, "Type": "String", "Description": { "en": "<font color='blue'><b>Valid values:</b></font><br>[cloud_efficiency: <font color='green'>efficient cloud disk</font>]<br>[cloud_ssd: <font color='green'>SSD cloud disk</font>]<br>[cloud_essd: <font color='green'>ESSD cloud disk</font>]<br>[cloud: <font color='green'>basic cloud disk</font>]<br>[ephemeral_ssd: <font color='green'>local SSD</font>]" }, "AllowedValues": [ "cloud_efficiency", "cloud_ssd", "cloud", "cloud_essd", "ephemeral_ssd" ] }, "InstancePassword": { "Type": "String", "Description": { "en": "The logon password for the instance. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/" }, "MinLength": 8, "Label": { "en": "Instance Password" }, "AllowedPattern": "[0-9A-Za-z\\_\\-\\&:;'<>,=%`~!@#\\(\\)\\$\\^\\*\\+\\|\\{\\}\\[\\]\\.\\?\\/]+$", "NoEcho": true, "MaxLength": 30, "ConstraintDescription": { "en": "The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters." } }, "SecurityGroup": { "Type": "String", "AssociationProperty": "ALIYUN::ECS::SecurityGroup::SecurityGroupId", "Description": { "en": "The ID of the security group. You can view the ID in the ECS console under Network & Security > Security Groups." }, "Label": { "en": "Security Group ID" } }, "VPC": { "AssociationProperty": "ALIYUN::ECS::VPC::VPCId", "Type": "String", "Description": { "en": "The ID of the Virtual Private Cloud (VPC) instance. You can view the ID in the VPC console." }, "Label": { "en": "Existing VPC Instance ID" } }, "VSwitch": { "AssociationProperty": "ALIYUN::ECS::VSwitch::VSwitchId", "Type": "String", "Description": { "en": "The ID of the VSwitch. You can view the ID in the VPC console under VSwitches." }, "Label": { "en": "VSwitch ID" } } }, "Metadata": { "ALIYUN::ROS::Interface": { "ParameterGroups": [ { "Parameters": [ "VPC", "VSwitch", "SecurityGroup" ], "Label": { "default": { "en": "Infrastructure Configuration" } } }, { "Parameters": [ "ZoneId", "ImageId", "InstanceType", "SystemDiskCategory", "InstancePassword", "NginxDownloadUrl" ], "Label": { "default": { "en": "ECS Configuration" } } } ], "TemplateTags": [ "acs:example:Linux application service: ROS_OOS create Nginx application" ] } }, "Resources": { "WebServer": { "Type": "ALIYUN::ECS::Instance", "Properties": { "InternetMaxBandwidthOut": 80, "IoOptimized": "optimized", "VpcId": { "Ref": "VPC" }, "UserData": { "Fn::Join": [ "", [ "#!/bin/bash \n", "NginxUrl=", { "Ref": "NginxDownloadUrl" }, "\n", "yum -y install aria2 \n", "aria2c $NginxUrl \n", "rpm -ivh nginx-*.rpm \n", "yum -y install nginx \n", "systemctl enable nginx.service \n", "systemctl restart nginx.service \n" ] ] }, "SecurityGroupId": { "Ref": "SecurityGroup" }, "VSwitchId": { "Ref": "VSwitch" }, "ImageId": { "Ref": "ImageId" }, "InstanceType": { "Ref": "InstanceType" }, "SystemDiskCategory": { "Ref": "SystemDiskCategory" }, "Password": { "Ref": "InstancePassword" } } } }, "Outputs": { "NginxUrl": { "Value": { "Fn::Join": [ "", [ "http://", { "Fn::GetAtt": [ "WebServer", "PublicIp" ] }, ":80" ] ] } } } }
Configure parameters.
On the Configure Parameters tab, specify a Stack Name.
In the Configure Template Parameters section, set the parameters as described in the following table.
Section
Parameter
Description
Basic Resource Configuration
Existing VPC Instance ID
Select your VPC ID from the drop-down list.
VSwitch ID
Select your VSwitch ID from the drop-down list.
Security Group ID
Select your security group ID from the drop-down list.
ECS Instance Configuration
VSwitch Availability Zone
Select an availability zone. For example, Zone G.
Image
Enter centos_7.
Instance Type
Select an instance type.
System Disk Type
Select cloud_ssd.
Instance Password
Enter a password for the instance.
Nginx Download URL
Enter the object URL of the Nginx installation package from Step 1.
In the Configure Stack Settings section, keep the default settings.
Click Create.
Verify the deployment.
Click the name of the created stack.
Click the Outputs tab, and then click the URL displayed for NginxUrl.
In the output list on the Outputs tab, the output keyword NginxUrl shows the value
http://<public IP address of the instance>:80.After you click NginxUrl, you are automatically redirected to the CentOS welcome page. This indicates that Nginx is running properly.
If you cannot access the page, add a rule to the security group to allow inbound traffic on HTTP port
80. For more information, see Add a security group rule.