日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

使用伸縮組管理多臺云服務器ECS

本文以使用伸縮組管理多臺云服務器ECS為例,由簡入難地向您介紹如何編輯ROS模板。

前提條件

請您提前了解模板語法和結構。更多信息,請參見模板快速入門

場景示例

在阿里云專有網絡中創建一個伸縮組并配置伸縮規則,創建ECS實例并加入到伸縮組中,最后根據已設置的伸縮規則對組內的云服務器ECS實現擴容或縮容。2023-03-29_10-36-10

使用須知

您可以訪問對應的資源類型查看屬性詳情。具體操作,請參見查看資源類型

資源類型為每個屬性定義了類型、是否必須、是否允許更新等信息。如果為必須,則要求必須在模板Resources的Properties中聲明該屬性;反之,則為非必須。如果為允許更新,則可以在新模板中修改該屬性,然后使用修改后的模板更新資源棧以達到更新云資源屬性的目的;反之,則不允許更新。

編輯模板

您可以通過資源類型索引文檔查找所需的資源類型。更多信息,請參見資源類型索引

例如:當前場景中需要創建專有網絡VPC(ALIYUN::ECS::VPC)、云服務器ECS(ALIYUN::ECS::Instance)和伸縮組(ALIYUN::ESS::ScalingGroup)。還需要創建云服務器ECS所使用的交換機(ALIYUN::ECS::VSwitch)和安全組(ALIYUN::ECS::SecurityGroup)。完成資源創建后,您還需要為伸縮組添加伸縮配置(ALIYUN::ESS::ScalingConfiguration)并啟動伸縮組(ALIYUN::ESS::ScalingGroupEnable)。

定義模板資源及其依賴關系

定義基礎網絡資源

您可以通過模板定義基礎網絡資源VpcVSwitchEcsSecurityGroup

  • 使用Ref與偽參數ALIYUN::StackName獲取資源棧名稱作為資源屬性的屬性值,例如Vpc中的VpcNameVSwitch中的VSwitchName。更多信息,請參見RefALIYUN::StackName

  • 使用Fn::Select與Fn::GetAZs函數結合偽參數ALIYUN::Region獲取資源棧所在地域的第一個可用區ID,例如VSwitch中的ZoneId。更多信息,請參見函數(Functions)ALIYUN::Region

Resources:
  Vpc:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock: 192.168.0.0/16
      VpcName:
        Ref: ALIYUN::StackName
  VSwitch:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VSwitchName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: Vpc
      ZoneId:
        Fn::Select:
          - '0'
          - Fn::GetAZs:
              Ref: ALIYUN::Region
      CidrBlock: 192.168.0.0/24
  EcsSecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      SecurityGroupName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: Vpc
      SecurityGroupEgress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          DestCidrIp: 0.0.0.0/0
          NicType: intranet

定義云服務器ECS資源

您可以通過模板定義云服務器ECS資源EcsInstanceGroup

使用Ref引用模板中資源的邏輯名稱,例如Vpc中的VpcIdEcsSecurityGroup中的SecurityGroupIdVSwitch中的VSwitchId。更多信息,請參見Ref

Resources:
	EcsInstanceGroup:
    Type: ALIYUN::ECS::Instance
    Properties:
      VpcId:
        Ref: Vpc
      SecurityGroupId:
        Ref: EcsSecurityGroup
      VSwitchId:
        Ref: VSwitch
      ImageId: centos_7
      AllocatePublicIP: false
      InstanceType: ecs.c5.large
      SystemDiskSize: 40
      SystemDiskCategory: cloud_essd
      Password:
        Ref: EcsInstancePassword

定義伸縮組資源

您可以通過模板定義伸縮組資源EssInstanceScalingGroupEssInstanceScalingGroupEnableEssInstanceScalingConfiguration

  • 使用Fn::GetAtt函數獲取資源輸出屬性值,例如EssInstanceScalingGroupEnable中的InstanceIds。更多信息,請參見Fn::GetAtt

  • 使用Fn::Sub將輸入字符串中的變量替換為指定的值,例如EssInstanceScalingConfiguration中的ScalingConfigurationName。更多信息,請參見Fn::Sub

Resources:
	EssInstanceScalingGroup:
    Type: ALIYUN::ESS::ScalingGroup
    Properties:
      ScalingGroupName:
        Ref: ALIYUN::StackName
      RemovalPolicys:
        - NewestInstance
      MinSize: 3
      MaxSize: 50
      VSwitchId:
        Ref: VSwitch
      DefaultCooldown: 300
  EssInstanceScalingConfiguration:
    Type: ALIYUN::ESS::ScalingConfiguration
    Properties:
      SecurityGroupId:
        Ref: EcsSecurityGroup
      ScalingGroupId:
        Ref: EssInstanceScalingGroup
      ScalingConfigurationName:
        Fn::Sub: sc-${ALIYUN::StackName}
      InstanceType: ecs.c5.large
      SystemDiskCategory: cloud_essd
      SystemDiskSize: 200
      ImageId: centos_7_9_x64_20G_alibase_20220727.vhd
      InstanceName:
        Fn::Join:
          - '-'
          - - Ref: ALIYUN::StackName
            - '[1,4]'
  EssInstanceScalingGroupEnable:
    Type: ALIYUN::ESS::ScalingGroupEnable
    Properties:
      ScalingRuleArisExecuteVersion: '1'
      ScalingConfigurationId:
        Ref: EssInstanceScalingConfiguration
      InstanceIds:
        Fn::GetAtt:
          - EcsInstanceGroup
          - InstanceIds
      ScalingGroupId:
        Ref: EssInstanceScalingGroup

完整模板示例

ROSTemplateFormatVersion: '2015-09-01'
Description: { }
Parameters:
  EcsInstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: Server login password, Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
      zh-cn: 服務器登錄密碼,長度8~30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)。
    AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
    Label:
      en: Instance Password
      zh-cn: 實例密碼
    ConstraintDescription:
      en: Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
      zh-cn: 長度8~30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)。
    MinLength: 8
    MaxLength: 30
Resources:
  Vpc:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock: 192.168.0.0/16
      VpcName:
        Ref: ALIYUN::StackName
  VSwitch:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VSwitchName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: Vpc
      ZoneId:
        Fn::Select:
          - '0'
          - Fn::GetAZs:
              Ref: ALIYUN::Region
      CidrBlock: 192.168.0.0/24
  EcsSecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      SecurityGroupName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: Vpc
      SecurityGroupEgress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          DestCidrIp: 0.0.0.0/0
          NicType: intranet
  EcsInstance:
    Type: ALIYUN::ECS::Instance
    Properties:
      VpcId:
        Ref: Vpc
      SecurityGroupId:
        Ref: EcsSecurityGroup
      VSwitchId:
        Ref: VSwitch
      ImageId: centos_7
      AllocatePublicIP: false
      InstanceType: ecs.c5.large
      SystemDiskSize: 40
      SystemDiskCategory: cloud_essd
      Password:
        Ref: EcsInstancePassword
  EssInstanceScalingGroup:
    Type: ALIYUN::ESS::ScalingGroup
    Properties:
      ScalingGroupName:
        Ref: ALIYUN::StackName
      RemovalPolicys:
        - NewestInstance
      MinSize: 3
      MaxSize: 50
      VSwitchId:
        Ref: VSwitchId
      DefaultCooldown: 300
  EssInstanceScalingConfiguration:
    Type: ALIYUN::ESS::ScalingConfiguration
    Properties:
      SecurityGroupId:
        Ref: EcsSecurityGroup
      ScalingGroupId:
        Ref: EssInstanceScalingGroup
      ScalingConfigurationName:
        Fn::Sub: sc-${ALIYUN::StackName}
      InstanceType: ecs.c5.large
      SystemDiskCategory: cloud_essd
      SystemDiskSize: 200
      ImageId: centos_7_9_x64_20G_alibase_20220727.vhd
      InstanceName:
        Fn::Join:
          - '-'
          - - Ref: ALIYUN::StackName
            - '[1,4]'
  EssInstanceScalingGroupEnable:
    Type: ALIYUN::ESS::ScalingGroupEnable
    Properties:
      ScalingRuleArisExecuteVersion: '1'
      ScalingConfigurationId:
        Ref: EssInstanceScalingConfiguration
      InstanceIds:
        Fn::GetAtt:
          - EcsInstanceGroup
          - InstanceIds

添加模板參數分組和動態獲取參數配置

在以上模板中完成了對多種資源及其依賴關系的定義,其中EcsInstance屬性的InstanceTypeSystemDiskCategory屬性值為固定值。當您在不同地域創建資源棧時,需要多次調整模板內容和變更資源屬性以達到部署資源棧的目的。

您可以對模板添加參數Parameters,從而提高模板的靈活性和可復用性。

添加模板參數分組

您可以在模板中使用元數據(Metadata)對Parameters中定義的參數進行分組,并定義參數分組標簽。

在完成對模板資源和參數的定義后,您可以按照不同資源與資源對應的參數進行參數分組。 以當前模板為例,您可以將資源按照如下結果劃分。

資源參數分類

資源名稱

參數名稱

基礎網絡配置

VpcVSwitchEcsSecurityGroup

VSwitchZoneIdVpcCidrBlockVSwitchCidrBlock

云服務器ECS配置

EcsInstance

ECSInstanceTypeECSInstanceGroupCountECSImageIdECSDiskCategoryEcsInstancePassword

伸縮組資源配置

EssInstanceScalingGroupEssInstanceScalingGroupEnableEssInstanceScalingConfiguration

ESSGroupMaxSize

動態獲取參數配置

EcsInstanceType參數為例,當您需要在控制臺上對參數設置篩選條件并動態選擇參數配置時,可以按照參數對應的資源類型(ALIYUN::ECS::Instance)在AssociationProperty和AssociationPropertyMetadata文檔中查詢到該參數支持的AssociationProperty取值(ALIYUN::ECS::Instance::InstanceType),然后查看對篩選到的AssociationProperty設置過濾條件為ZoneIdAssociationPropertyMetadata取值。更多信息,請參見AssociationProperty和AssociationPropertyMetadata

完整模板示例

ROSTemplateFormatVersion: '2015-09-01'
Description:
  en: scaling-ecs.
  zh-cn: ECS部署,支持彈性功能。
Parameters:
  VSwitchZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
    Description:
      en: Availability ID for existing switches.
      zh-cn: 現有交換機的可用區ID。
    Label:
      en: VSwitch Zone ID
      zh-cn: 交換機可用區
  VpcCidrBlock:
    Default: 192.168.0.0/16
    Label:
      zh-cn: 專有網絡網段
      en: VPC CIDR Block
    Type: String
    Description:
      zh-cn: 新建專有網絡IP地址段范圍,推薦使用以下的IP地址段<br><font color='green'>[10.0.XX.XX/8]</font><br><font color='green'>[172.16.XX.XX/12]</font><br><font color='green'>[192.168.XX.XX/16]</font>。
      en: New proprietary network IP address segment range, recommended use of the following IP address segments<br><font color='green'>[10.0.XX.XX/8]</font><br><font color='green'>[172.16.XX.XX/12]</font><br><font color='green'>[192.168.XX.XX/16]</font>.
  VSwitchCidrBlock:
    Default: 192.168.0.0/24
    Type: String
    Description:
      zh-cn: 必須是所屬專有網絡的子網段,并且沒有被其他交換機占用。
      en: Must be a sub-network segment of the proprietary network and is not occupied by other VSwitches.
    Label:
      zh-cn: 交換機網段
      en: VSwitch CIDR Block
  ECSInstanceType:
    Type: String
    Label:
      en: Instance Type
      zh-cn: 實例類型
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ${VSwitchZoneId}
      InstanceChargeType: ${InstanceChargeType}
  ECSDiskCategory:
    Type: String
    Description:
      en: '<font color=''blue''><b>Optional 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''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD Cloud Disk</font>]'.
      zh-cn: '<font color=''blue''><b>可選值:</b></font><br>[cloud_efficiency: <font color=''green''>高效云盤</font>]<br>[cloud_ssd: <font color=''green''>SSD云盤</font>]<br>[cloud_essd: <font color=''green''>ESSD云盤</font>]<br>[cloud: <font color=''green''>普通云盤</font>]<br>[ephemeral_ssd: <font color=''green''>本地SSD盤</font>]'。
    AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
    AssociationPropertyMetadata:
      ZoneId: ${VSwitchZoneId}
      InstanceType: ${ECSInstanceType}
    Label:
      en: System Disk Type
      zh-cn: 系統盤類型
  ECSImageId:
    AssociationProperty: ALIYUN::ECS::Image::ImageId
    Label:
      zh-cn: ECS鏡像ID
      en: Image ID
    Description:
      zh-cn: 鏡像ID,ECS實例的鏡像資源, <font><a href='http://bestwisewords.com/document_detail/112977.html' target='_blank'><b>查看鏡像資源</b></font color='blue'></a>。
      en: Image ID, represents the image resource to startup one ECS instance, <font><a  target='_blank'><b>View image resources</b></font color='blue'></a>.
    Type: String
  EcsInstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: Server login password, Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
      zh-cn: 服務器登錄密碼,長度8~30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)。
    AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
    Label:
      en: Instance Password
      zh-cn: 實例密碼
    ConstraintDescription:
      en: Length 8~30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
      zh-cn: 長度8~30,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)。
    MinLength: 8
    MaxLength: 30
    AssociationProperty: ALIYUN::ECS::Instance::Password
  ECSInstanceGroupCount:
    Type: Number
    Description:
      en: ECS Instance Count
      zh-cn: ECS實例數量
    Label:
      en: Instance Count
      zh-cn: 實例數量
    Default: 3
  ESSGroupMaxSize:
    Type: Number
    Label:
      en: The maximum number of ECS instances in ESS.
      zh-cn: ESS內ECS實例個數的最大值。
    Default: 50
Resources:
  Vpc:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock:
        Ref: VpcCidrBlock
      VpcName:
        Ref: ALIYUN::StackName
  VSwitch:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VSwitchName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: Vpc
      ZoneId:
        Ref: VSwitchZoneId
      CidrBlock:
        Ref: VSwitchCidrBlock
  EcsSecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      SecurityGroupName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: Vpc
      SecurityGroupIngress:
        - PortRange: 8080/8080
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
          NicType: internet
      SecurityGroupEgress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          DestCidrIp: 0.0.0.0/0
          NicType: internet
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          DestCidrIp: 0.0.0.0/0
          NicType: intranet
  EcsInstanceGroup:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      InstanceName:
        Fn::Join:
          - '-'
          - - Ref: ALIYUN::StackName
            - '[1,4]'
      VpcId:
        Ref: Vpc
      VSwitchId:
        Ref: VSwitch
      SecurityGroupId:
        Ref: EcsSecurityGroup
      SystemDiskCategory:
        Ref: ECSDiskCategory
      SystemDiskSize: 200
      MaxAmount:
        Ref: ECSInstanceGroupCount
      ImageId:
        Ref: ECSImageId
      InstanceType:
        Ref: ECSInstanceType
      Password:
        Ref: EcsInstancePassword
      AllocatePublicIP: false
  EssInstanceScalingGroupEnable:
    Type: ALIYUN::ESS::ScalingGroupEnable
    Properties:
      ScalingRuleArisExecuteVersion: '1'
      ScalingConfigurationId:
        Ref: EssInstanceScalingConfiguration
      InstanceIds:
        Fn::GetAtt:
          - EcsInstanceGroup
          - InstanceIds
      ScalingGroupId:
        Ref: EssInstanceScalingGroup
  EssInstanceScalingConfiguration:
    Type: ALIYUN::ESS::ScalingConfiguration
    Properties:
      SecurityGroupId:
        Ref: EcsSecurityGroup
      ScalingGroupId:
        Ref: EssInstanceScalingGroup
      ScalingConfigurationName:
        Fn::Sub: sc-${ALIYUN::StackName}
      InstanceType:
        Ref: ECSInstanceType
      SystemDiskCategory:
        Ref: ECSDiskCategory
      SystemDiskSize: 200
      ImageId:
        Ref: ECSImageId
      InstanceName:
        Fn::Join:
          - '-'
          - - Ref: ALIYUN::StackName
            - '[1,4]'
  EssInstanceScalingGroup:
    Type: ALIYUN::ESS::ScalingGroup
    Properties:
      ScalingGroupName:
        Ref: ALIYUN::StackName
      RemovalPolicys:
        - NewestInstance
      MinSize:
        Ref: ECSInstanceGroupCount
      MaxSize: 50
      VSwitchId:
        Ref: VSwitch
      DefaultCooldown: 300
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - VSwitchZoneId
          - VpcCidrBlock
          - VSwitchCidrBlock
        Label:
          default:
            zh-cn: 基礎網絡配置
            en: Basic Network Configuration
      - Parameters:
          - ECSInstanceType
          - ECSDiskCategory
          - ECSImageId
          - EcsInstancePassword
          - ECSInstanceGroupCount
        Label:
          default:
            en: Instance
            zh-cn: ECS實例配置
      - Parameters:
          - ESSGroupMaxSize
        Label:
          default:
            zh-cn: 伸縮組配置
            en: ESS Configuration