使用ROS创建一组ECS

使用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": {
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章