开发者社区> 问答> 正文

资源编排如何创建一台ECS实例?

资源编排如何创建一台ECS实例?

展开
收起
小天使爱美 2020-03-24 18:17:28 676 0
1 条回答
写回答
取消 提交回答
  • 本文为您介绍如何通过资源编排服务(ROS)模板创建一台ECS实例。

    前提条件 创建ECS实例前,首先需要创建虚拟专有网络(VPC)和交换机(VSwitch)并加入安全组(SecurityGroup)。本文为您介绍如何通过创建ROS模板生成上述资源,再通过ROS控制台创建资源栈,详情请参见创建资源栈。

    创建VPC的注意事项,请参见ALIYUN::ECS::VPC。 创建交换机的注意事项,请参见ALIYUN::ECS::VSwitch。 创建安全组的注意事项,请参见ALIYUN::ECS::SecurityGroup。 创建一台ECS实例的注意事项,请参见ALIYUN::ECS::Instance。 创建一台ECS实例 下述两种格式的模板中几个重要参数的描述如下:

    {"Fn::Select": ["1", {"Fn::GetAZs": {"Ref": "ALIYUN::Region"}}]} :获取当前地域的第二个可用区。 Parameters:提高模板的灵活性,即可以在创建资源栈时自定义资源类型所需参数,而不是在模板中进行硬编码。 Ref:关联参数或其他资源类型,获取参数的值或其他资源的ID。 Fn::GetAtt:获取资源类型的返回值。 Outputs:进入控制台对应资源栈详情页面在输出一栏查看输出值。 JSON格式

    { "ROSTemplateFormatVersion": "2015-09-01", "Description": "创建一台ECS实例", "Parameters": { "PublicIP": { "Type": "Boolean", "Description": "是否分配公网IP", "Label": "分配公网IP", "Default": false }, "ImageId": { "Type": "String", "Description": "镜像ID,表示要启动一个ECS实例的镜像资源", "AllowedValues": [ "centos_7", "ubuntu", "win" ], "Label": "ECS镜像ID", "Default": "centos_7" }, "InstanceType": { "Type": "String", "Description": "ECS实例类型", "AllowedValues": [ "ecs.c5.large", "ecs.g5.large", "ecs.c5.xlarge", "ecs.g5.xlarge" ], "Label": "ECS实例类型", "Default": "ecs.c5.large" }, "LoginPassword": { "NoEcho": true, "Type": "String", "Description": "ECS登录密码", "AllowedPattern": "[a-zA-Z0-9-\(\)\`\~\!@\#\$%\^&\-+=\|\{\}\[\]\:\;\‘\,\.\?\/]", "Label": "ECS登录密码", "MinLength": 8, "MaxLength": 30 } }, "Resources": { "VSwitch": { "Type": "ALIYUN::ECS::VSwitch", "Properties": { "VpcId": { "Ref": "VPC" }, "ZoneId": { "Fn::Select": [ "1", { "Fn::GetAZs": { "Ref": "ALIYUN::Region" } } ] }, "CidrBlock": "192.168.0.0/24" } }, "SG": { "Type": "ALIYUN::ECS::SecurityGroup", "Properties": { "VpcId": { "Ref": "VPC" }, "SecurityGroupName": "SG", "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": "intranet" } ] } }, "ECS": { "Type": "ALIYUN::ECS::Instance", "Properties": { "IoOptimized": "optimized", "VpcId": { "Ref": "VPC" }, "SecurityGroupId": { "Ref": "SG" }, "VSwitchId": { "Ref": "VSwitch" }, "ImageId": { "Ref": "ImageId" }, "AllocatePublicIP": { "Ref": "PublicIP" }, "InstanceType": { "Ref": "InstanceType" }, "SystemDiskCategory": "cloud_ssd", "Password": { "Ref": "LoginPassword" } } }, "VPC": { "Type": "ALIYUN::ECS::VPC", "Properties": { "CidrBlock": "192.168.0.0/16", "VpcName": "MyVPC" } } }, "Outputs": { "ECS实例ID": { "Value": { "Fn::GetAtt": [ "ECS", "InstanceId" ] } }, "公网IP": { "Value": { "Fn::GetAtt": [ "ECS", "PublicIp" ] } } } } YAML格式

    ROSTemplateFormatVersion: '2015-09-01' Description: 创建一台ECS实例 Parameters: PublicIP: Type: Boolean Description: 是否分配公网IP Label: 分配公网IP Default: false ImageId: Type: String Description: 镜像ID,表示要启动一个ECS实例的镜像资源 AllowedValues: - centos_7 - ubuntu - win Label: ECS镜像ID Default: centos_7 InstanceType: Type: String Description: ECS实例类型 AllowedValues: - ecs.c5.large - ecs.g5.large - ecs.c5.xlarge - ecs.g5.xlarge Label: ECS实例类型 Default: ecs.c5.large LoginPassword: NoEcho: true Type: String Description: ECS登录密码 AllowedPattern: "[a-zA-Z0-9-\(\)\`\~\!@\#\$%\^&\-+=\|\{\}\[\]\:\;\‘\,\.\?\/]" Label: ECS登录密码 MinLength: 8 MaxLength: 30 Resources: VSwitch: Type: ALIYUN::ECS::VSwitch Properties: VpcId: Ref: VPC ZoneId: Fn::Select: - '1' - Fn::GetAZs: Ref: ALIYUN::Region CidrBlock: 192.168.0.0/24 SG: Type: ALIYUN::ECS::SecurityGroup Properties: VpcId: Ref: VPC SecurityGroupName: SG 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: intranet ECS: Type: ALIYUN::ECS::Instance Properties: IoOptimized: optimized VpcId: Ref: VPC SecurityGroupId: Ref: SG VSwitchId: Ref: VSwitch ImageId: Ref: ImageId AllocatePublicIP: Ref: PublicIP InstanceType: Ref: InstanceType SystemDiskCategory: cloud_ssd Password: Ref: LoginPassword VPC: Type: ALIYUN::ECS::VPC Properties: CidrBlock: 192.168.0.0/16 VpcName: MyVPC Outputs: ECS实例ID: Value: Fn::GetAtt: - ECS - InstanceId 公网IP: Value: Fn::GetAtt: - ECS - PublicIp 查看ECS实例镜像资源,请参见公共镜像概述。 查看ECS实例类型,请参见实例规格族。

    2020-03-24 18:27:31
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS块储存产品全面解析 立即下载

相关镜像