使用ROS創建一組ECS,加入SLB,創建rds-MySQL並生成賬戶。
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": "創建一組ECS",
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"ImageId",
"InstanceType",
"ZoneId",
"LoginPassword",
"ECSAmount",
"DiskSize",
"DiskCategory",
"SystemDiskSize",
"SystemDiskCategory",
"InstanceNamePrefix",
"HostNamePrefix"
],
"Label": {
"default": "ECS"
}
},
{
"Parameters": [
"PayType",
"AddressType",
"SLB_InternetChargeType",
"MasterZoneId",
"SlaveZoneId",
"LoadBalancerSpec",
"LoadBalancerName",
"Protocol",
"ListenerPort",
"SLBBackendServerPort"
],
"Label": {
"default": "負載均衡"
}
},
{
"Parameters": [
"Engine",
"EngineVersion",
"DBInstanceClass",
"DBInstanceStorage",
"SecurityIPList",
"RDSAccountType",
"RDSAccountName",
"RDSAccountPassword"
],
"Label": {
"default": "雲數據庫RDS"
}
}
],
"TemplateTags": [
"ECS_SLB_RDS"
]
}
},
"Parameters": {
"RDSAccountType": {
"Type": "String",
"Label": "RDS賬號類型",
"Description": "Normal:普通賬號;Super:高權限賬號",
"Default": "Super",
"AllowedValues": [
"Super",
"Normal"
]
},
"RDSAccountName": {
"Type": "String",
"Label": "數據庫賬號",
"Description": "由小寫字母,數字、下劃線組成、字母開頭,字母或數字結尾,最多16個字符,最少2個字符.",
"MaxLength": 16,
"MinLength": 2
},
"RDSAccountPassword": {
"Type": "String",
"Label": "數據庫密碼",
"Description": "大寫、小寫、數字、特殊字符佔三種,長度爲8-32位;特殊字符爲!@#$%^&*()_+-=。",
"MaxLength": 32,
"MinLength": 8,
"NoEcho": true,
"Confirm": true
},
"DBInstanceNetType": {
"Type": "String",
"Description": "Internet(用於公網訪問)、Intranet(用於私網訪問,默認值)。",
"Label": "RDS實例網絡類型",
"Default": "Intranet"
},
"SystemDiskSize": {
"Type": "Number",
"Description": "系統盤大小,40 - 500, 單位:GB",
"Label": "系統盤",
"Default": 100
},
"PublicIP": {
"Type": "Boolean",
"Description": "是否分配公網IP",
"Label": "分配公網IP",
"Default": true
},
"ECSAmount": {
"Type": "String",
"Label": "ECS實例數量",
"Default": "3"
},
"LoadBalancerSpec": {
"Type": "String",
"Description": "負載均衡實例的規格",
"AllowedValues": [
"slb.s1.small",
"slb.s2.small",
"slb.s2.medium",
"slb.s3.small",
"slb.s3.medium",
"slb.s3.large"
],
"Label": "實例規格",
"Default": "slb.s2.medium"
},
"SLBBackendServerPort": {
"Type": "Number",
"Description": "負載均衡實例後端使用的端口,可選值:1-65535。",
"Label": "負載均衡對外服務的端口",
"Default": 80
},
"SecurityIPList": {
"Type": "String",
"Description": "IP白名單以逗號隔開,不可重複,最多1000個。支持格式:0.0.0.0/0。",
"Label": "IP白名單",
"Default": "0.0.0.0/0"
},
"DBInstanceStorage": {
"Type": "Number",
"Description": "取值範圍:MySQL:[5,1000]SQLServer:[10,1000]PostgreSQL或PPAS:[5,2000]單位:GB,每5GB進行遞增。",
"Label": "數據庫存儲空間",
"Default": "250"
},
"ImageId": {
"Type": "String",
"Description": "鏡像ID, 表示要啓動一個ECS實例的映像資源, <a href='#/product/cn-hangzhou/list/imageList' target='_blank'>查看鏡像資源</a>",
"Label": "ECS鏡像ID",
"Default": "centos_7"
},
"DiskSize": {
"Type": "String",
"Description": "數據盤大小, 單位:GB",
"Label": "數據盤",
"Default": "900"
},
"InstanceNamePrefix": {
"Type": "String",
"Description": "2-128個字符,以大小寫英文或中文開頭,可包含數字、下劃線(_)、點(.)或連字符(-)。",
"Label": "實例名稱",
"MinLength": 2,
"MaxLength": 128,
"Default": "Instance"
},
"InstanceType": {
"Type": "String",
"Description": "ECS實例類型, <a href='#/product/cn-hangzhou/list/typeList' target='_blank'>查看實例類型</a>",
"AllowedValues": [
"ecs.g5.xlarge",
"ecs.g6.xlarge",
"ecs.t5-c1m4.xlarge",
"ecs.sn2ne.xlarge"
],
"Label": "ECS實例類型",
"Default": "ecs.g5.xlarge"
},
"Protocol": {
"Type": "String",
"Description": "IP協議",
"AllowedValues": [
"tcp",
"udp",
"http",
"https"
],
"Label": "負載均衡協議",
"Default": "tcp"
},
"SLB_InternetChargeType": {
"Type": "String",
"Description": "公網類型實例付費方式。",
"AllowedValues": [
"paybybandwidth",
"paybytraffic"
],
"Label": "SLB付費方式",
"Default": "paybytraffic"
},
"Engine": {
"Type": "String",
"Description": "取值範圍:MySQL、SQLServer、PostgreSQL、PPAS。",
"Label": "數據庫類型",
"Default": "MySQL"
},
"MasterZoneId": {
"Type": "String",
"Description": "實例的主可用區ID。",
"Label": "主可用區",
"Default": "cn-hangzhou-h"
},
"LoginPassword": {
"NoEcho": true,
"Type": "String",
"Description": "ECS登錄密碼",
"AllowedPattern": "[a-zA-Z0-9-\\(\\)\\`\\~\\!@\\#\\$%\\^&\\*-+=\\|\\{\\}\\[\\]\\:\\;\\‘\\,\\.\\?\\/]*",
"Label": "ECS登錄密碼",
"Confirm": true,
"MinLength": 8,
"MaxLength": 30
},
"ListenerPort": {
"Type": "Number",
"Description": "負載均衡監聽端口,可選值:1-65535",
"Label": "監聽端口",
"Default": 80
},
"EngineVersion": {
"Type": "String",
"Description": "取值範圍:MySQL:5.5、5.6、5.7、8.0,SQLServer:2008r2,PostgreSQL:9.4,PPAS:9.3。",
"Label": "數據庫版本",
"Default": "5.6"
},
"ZoneId": {
"Type": "String",
"Label": "可用區",
"Default": "cn-hangzhou-h"
},
"DBInstanceClass": {
"Type": "String",
"Description": "本例採用三節點企業版,詳情參見<a href='https://help.aliyun.com/document_detail/26312.html?spm=a2c4g.11186623.2.16.379a35c793eumm'>實例規格</a>。",
"AllowedValues": [
"rds.mysql.s2.large",
"mysql.x4.large.3",
"mysql.x4.xlarge.3",
"mysql.x4.2xlarge.3",
"mysql.x4.4xlarge.3",
"mysql.x8.medium.3",
"mysql.x8.large.3",
"mysql.x8.xlarge.3",
"mysql.x8.2xlarge.3",
"mysql.x8.4xlarge.3"
],
"Label": "數據庫實例規格",
"Default": "rds.mysql.s2.large"
},
"DiskCategory": {
"Type": "String",
"Description": "數據盤類型",
"AllowedValues": [
"cloud",
"cloud_efficiency",
"cloud_ssd",
"ephemeral_ssd"
],
"Label": "數據盤類型",
"Default": "cloud_efficiency"
},
"PayType": {
"Type": "String",
"Description": "SLB實例的計費類型。",
"AllowedValues": [
"PayOnDemand",
"PrePay"
],
"Label": "付費方式",
"Default": "PayOnDemand"
},
"SlaveZoneId": {
"Type": "String",
"Description": "該創建實例的備可用區ID。",
"Label": "備可用區",
"Default": "cn-hangzhou-g"
},
"SystemDiskCategory": {
"Type": "String",
"Description": "系統盤類型",
"AllowedValues": [
"cloud",
"cloud_efficiency",
"cloud_ssd",
"ephemeral_ssd"
],
"Label": "系統盤類型",
"Default": "cloud_ssd"
},
"LoadBalancerName": {
"Type": "String",
"Description": "負載均衡實例的名稱。",
"Label": "SLB實例名稱",
"Default": "SLB_HZ_APP01"
},
"HostNamePrefix": {
"Type": "String",
"Description": "2-64個字符,允許使用點(.)分隔成多段,每段允許使用大小寫字母、數字或連字符(-),但不能連續使用點(.)或連字符(-),不能以點(.)或連字符(-)開頭或結尾。",
"Label": "主機名",
"MinLength": 2,
"MaxLength": 64,
"Default": "Host"
},
"AddressType": {
"Type": "String",
"Description": "負載均衡地址類型",
"AllowedValues": [
"internet",
"intranet"
],
"Label": "負載均衡地址類型",
"Default": "internet"
}
},
"Resources": {
"RDS": {
"Type": "ALIYUN::RDS::DBInstance",
"DependsOn": [
"VPC001",
"VSW001"
],
"Properties": {
"EngineVersion": {
"Ref": "EngineVersion"
},
"DBInstanceNetType": {
"Ref": "DBInstanceNetType"
},
"DBInstanceClass": {
"Ref": "DBInstanceClass"
},
"SecurityIPList": {
"Ref": "SecurityIPList"
},
"DBInstanceStorage": {
"Ref": "DBInstanceStorage"
},
"MultiAZ": true,
"Engine": {
"Ref": "Engine"
}
}
},
"SLBListener": {
"Type": "ALIYUN::SLB::Listener",
"Properties": {
"ListenerPort": {
"Ref": "ListenerPort"
},
"Bandwidth": -1,
"LoadBalancerId": {
"Fn::GetAtt": [
"LoadBalancer",
"LoadBalancerId"
]
},
"Protocol": {
"Ref": "Protocol"
},
"BackendServerPort": {
"Ref": "SLBBackendServerPort"
}
}
},
"SLBBackendServerAttachment": {
"Type": "ALIYUN::SLB::BackendServerAttachment",
"DependsOn": "ECS",
"Properties": {
"BackendServerList": {
"Fn::GetAtt": [
"ECS",
"InstanceIds"
]
},
"LoadBalancerId": {
"Fn::GetAtt": [
"LoadBalancer",
"LoadBalancerId"
]
}
}
},
"ECS": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"IoOptimized": "optimized",
"PrivateIpAddress": "192.168.0.1",
"DiskMappings": [
{
"Category": {
"Ref": "DiskCategory"
},
"Size": {
"Ref": "DiskSize"
}
}
],
"ZoneId": {
"Ref": "ZoneId"
},
"UserData": {
"Fn::Join": [
"",
[
"#!/bin/sh\n",
"yum -y install httpd\n",
"systemctl start httpd\n",
"yum install -y mysql\n"
]
]
},
"SystemDiskSize": {
"Ref": "SystemDiskSize"
},
"SecurityGroupId": {
"Ref": "SG"
},
"VSwitchId": {
"Ref": "VSW001"
},
"MaxAmount": {
"Ref": "ECSAmount"
},
"SystemDiskCategory": {
"Ref": "SystemDiskCategory"
},
"InstanceName": {
"Fn::Join": [
"",
[
{
"Ref": "InstanceNamePrefix"
},
"[1,3]"
]
]
},
"VpcId": {
"Ref": "VPC001"
},
"MinAmount": {
"Ref": "ECSAmount"
},
"ImageId": {
"Ref": "ImageId"
},
"AllocatePublicIP": {
"Ref": "PublicIP"
},
"InstanceType": {
"Ref": "InstanceType"
},
"HostName": {
"Fn::Join": [
"",
[
{
"Ref": "HostNamePrefix"
},
"[1,3]"
]
]
},
"Password": {
"Ref": "LoginPassword"
}
}
},
"SG": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPC001"
},
"SecurityGroupName": "mysg",
"SecurityGroupIngress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "all",
"NicType": "internet"
}
],
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "internet"
}
]
}
},
"LoadBalancer": {
"Type": "ALIYUN::SLB::LoadBalancer",
"Properties": {
"LoadBalancerName": {
"Ref": "LoadBalancerName"
},
"PayType": {
"Ref": "PayType"
},
"AddressType": {
"Ref": "AddressType"
},
"SlaveZoneId": {
"Ref": "SlaveZoneId"
},
"MasterZoneId": {
"Ref": "MasterZoneId"
},
"InternetChargeType": {
"Ref": "SLB_InternetChargeType"
},
"LoadBalancerSpec": {
"Ref": "LoadBalancerSpec"
}
}
},
"VSW001": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "VPC001"
},
"ZoneId": {
"Ref": "ZoneId"
},
"CidrBlock": "192.168.0.0/24",
"VSwitchName": "vsw_001"
}
},
"VPC001": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "192.168.0.0/16",
"VpcName": "VPC_HZ"
}
},
"RDSAccount": {
"DependsOn": "RDS",
"Type": "ALIYUN::RDS::Account",
"Properties": {
"DBInstanceId": {
"Ref": "RDS"
},
"AccountType": {
"Ref": "RDSAccountType"
},
"AccountName": {
"Ref": "RDSAccountName"
},
"AccountPassword": {
"Ref": "RDSAccountPassword"
}
}
}
},
"Outputs": {
}
}