ALIYUN::ALB::ServerGroup類型用於建立伺服器組。
文法
{
"Type": "ALIYUN::ALB::ServerGroup",
"Properties": {
"VpcId": String,
"ResourceGroupId": String,
"Scheduler": String,
"StickySessionConfig": Map,
"HealthCheckConfig": Map,
"Protocol": String,
"ServerGroupType": String,
"ServerGroupName": String,
"Tags": List,
"ServiceName": String,
"UpstreamKeepaliveEnabled": Boolean,
"SlowStartConfig": Map,
"ConnectionDrainConfig": Map,
"UchConfig": Map,
"CrossZoneEnabled": Boolean,
"Ipv6Enabled": Boolean
}
}屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
HealthCheckConfig | Map | 是 | 是 | 健全狀態檢查相關配置結構。 | 更多資訊,請參見HealthCheckConfig屬性。 |
ServerGroupName | String | 是 | 是 | 伺服器組名稱。 | 長度為2~128個字元,必須以英文字母或漢字開頭,可包含數字、半形句點(.)、底線(_)和短劃線(-)。 |
VpcId | String | 否 | 否 | 專用網路ID。 | 只有該VPC下的伺服器可以加入伺服器組。 |
Protocol | String | 否 | 否 | 後端協議。 | 取值:
說明 ServerGroupType取值為Fc時,僅支援HTTP協議。 |
ResourceGroupId | String | 否 | 是 | 資源群組ID。 | 無 |
Scheduler | String | 否 | 是 | 調度演算法。 | 取值:
|
ServerGroupType | String | 否 | 否 | 伺服器群組類型。 | 取值:
|
ServiceName | String | 否 | 是 | 伺服器組對應的Kubernetes服務名稱。 | 說明 本參數僅適用於應用路由情境。 |
StickySessionConfig | Map | 否 | 是 | 會話保持配置結構體。 | 更多資訊,請參見StickySessionConfig屬性。 |
Tags | List | 否 | 是 | 標籤。 | 最多添加20個標籤。 更多資訊,請參見Tags屬性。 |
UpstreamKeepaliveEnabled | Boolean | 否 | 是 | 是否開啟後端長連結。 |
|
SlowStartConfig | Map | 否 | 是 | 慢啟動相關配置。 | 開啟慢啟動後,將會在設定的時間段內對新添加到後端伺服器組的後端伺服器進行預熱,轉寄到該伺服器的請求數量線性增加。 更多資訊,請參見SlowStartConfig屬性。 說明
|
ConnectionDrainConfig | Map | 否 | 是 | 串連優雅中斷相關配置。 | 開啟串連優雅中斷,在移除後端伺服器或者健全狀態檢查失敗後,負載平衡使現有串連在一定時間內正常傳輸。 說明 基礎版執行個體不支援開啟串連優雅中斷,僅標準版、WAF 增強版執行個體支援。 伺服器類型、IP 類型伺服器組支援串連優雅中斷,Function Compute類型不支援。 |
UchConfig | Map | 否 | 是 | URL一致性 hash 參數配置。 | 更多資訊,請參見UchConfig屬性。 |
CrossZoneEnabled | Boolean | 否 | 是 | 伺服器組是否開啟跨 AZ 負載平衡。 | 取值:
說明
|
Ipv6Enabled | Boolean | 否 | 否 | 是否開啟 Ipv6 | 無 |
UchConfig文法
"UchConfig": {
"Type": String,
"Value": String
}UchConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
Type | String | 是 | 否 | 參數類型。 | 只能填 QueryString。 |
Value | String | 是 | 否 | 一致性 hash 參數值。 | 無 |
ConnectionDrainConfig文法
"ConnectionDrainConfig": {
"ConnectionDrainTimeout": Integer,
"ConnectionDrainEnabled": Boolean
}ConnectionDrainConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
ConnectionDrainTimeout | Integer | 是 | 是 | 串連優雅中斷逾時時間。 | 取值範圍:0~900。 預設值:300。 |
ConnectionDrainEnabled | Boolean | 是 | 是 | 是否開啟串連優雅中斷。 | 取值:
|
SlowStartConfig文法
"SlowStartConfig": {
"SlowStartDuration": Integer,
"SlowStartEnabled": Boolean
}SlowStartConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
SlowStartDuration | Integer | 是 | 是 | 慢啟動期間。 | 取值範圍:30~900。 預設值:30。 |
SlowStartEnabled | Boolean | 是 | 是 | 是否開啟慢啟動。 | 取值:
|
StickySessionConfig文法
"StickySessionConfig": {
"Cookie": String,
"CookieTimeout": Integer,
"StickySessionType": String,
"StickySessionEnabled": Boolean
}StickySessionConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
Cookie | String | 否 | 是 | 伺服器上配置的Cookie。 | 長度為1~200個字元,不能以貨幣符號($)開頭,可包含英文字母和數字,不能包含半形逗號(,)、半形分號(;)或空格。 說明 當StickySessionEnabled取值為true且StickySessionType取值為Server時,必須指定該參數。 |
CookieTimeout | Integer | 否 | 是 | Cookie逾時時間。 | 取值範圍:1~86,400。 預設值:1000。 單位:秒。 說明 當StickySessionEnabled取值為true且StickySessionType取值為Insert時,必須指定該參數。 |
StickySessionEnabled | Boolean | 否 | 是 | 是否啟用會話保持。 | 取值:
說明 當ServerGroupType取值為 |
StickySessionType | String | 否 | 是 | Cookie的處理方式。 | 取值:
說明 當StickySessionEnabled取值為true時,必須指定該參數。 |
HealthCheckConfig文法
"HealthCheckConfig": {
"HealthCheckInterval": Integer,
"HealthCheckConnectPort": Integer,
"HealthCheckCodes": List,
"UnhealthyThreshold": Integer,
"HealthCheckMethod": String,
"HealthCheckPath": String,
"HealthCheckHost": String,
"HealthyThreshold": Integer,
"HealthCheckProtocol": String,
"HealthCheckHttpVersion": String,
"HealthCheckEnabled": Boolean,
"HealthCheckTimeout": Integer
}HealthCheckConfig屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
HealthCheckEnabled | Boolean | 是 | 是 | 是否啟用健全狀態檢查。 | 取值:
|
HealthCheckCodes | List | 否 | 是 | 健全狀態檢查的狀態代碼列表。 | 取值:
說明 HealthCheckProtocol為HTTP或HTTPS或gRPC,該參數生效。 |
HealthCheckConnectPort | Integer | 否 | 是 | 健全狀態檢查的後端伺服器的連接埠。 | 取值範圍: 0~65,535。 預設值:0,表示使用後端伺服器的連接埠進行健全狀態檢查。 |
HealthCheckHost | String | 否 | 是 | 健全狀態檢查網域名稱。 | 長度為1~80個字元。可包含小寫英文字母、數字、短劃線(-)和半形句號(.)。 取值樣本: 說明 當HealthCheckProtocol取值為HTTP時,該參數有效。 |
HealthCheckHttpVersion | String | 否 | 是 | 健全狀態檢查HTTP協議版本。 | 取值:
說明 當HealthCheckProtocol取值為HTTP時,該參數有效。 |
HealthCheckInterval | Integer | 否 | 是 | 健全狀態檢查的時間間隔。 | 取值範圍:1~50。 預設值:2。 單位:秒。 |
HealthCheckMethod | String | 否 | 是 | 健全狀態檢查方式。 | 取值:
說明 只有HealthCheckProtocol設定為HTTP或HTTPS或gRPC時,該參數生效。 |
HealthCheckPath | String | 否 | 是 | 健全狀態檢查的路徑。 | 長度為1~80,必須以正斜線(/)開頭。可包含英文字母、數字和特殊字元 說明 當HealthCheckProtocol取值為HTTP時,該參數有效。 |
HealthCheckProtocol | String | 否 | 是 | 健全狀態檢查協議。 | 取值:
|
HealthCheckTimeout | Integer | 否 | 是 | 接收來自健全狀態檢查的響應需要等待的時間。 | 如果後端ECS在指定的時間內沒有正確響應,則判定為健全狀態檢查失敗。 取值範圍:1~300。 預設值:5。 單位:秒。 說明 如果HealthCheckTimeout的值小於HealthCheckInterval的值,則HealthCheckTimeout無效,逾時時間為HealthCheckInterval的值。 |
HealthyThreshold | Integer | 否 | 是 | 健全狀態檢查連續成功多少次後,將後端伺服器的健全狀態檢查狀態由失敗判定為成功。 | 取值範圍:2~10。 預設值:3。 |
UnhealthyThreshold | Integer | 否 | 是 | 健全狀態檢查連續失敗多少次後,將後端伺服器的健全狀態檢查狀態由成功判定為失敗。 | 取值範圍:2~10。 預設值:3。 |
Tags文法
"Tags": [
{
"Key": String,
"Value": String
}
] Tags屬性
屬性名稱 | 類型 | 必須 | 允許更新 | 描述 | 約束 |
Key | String | 是 | 否 | 標籤鍵。 | 長度為1~128個字元,不能以 |
Value | String | 否 | 否 | 標籤值。 | 長度為0~128個字元,不能以 |
傳回值
Fn::GetAtt
ServerGroupId:伺服器組ID。
Arn:阿里雲資源名稱。
樣本
請您根據實際情況更改脫敏的參數取值。
情境 1 :向伺服器組中添加後端伺服器。
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
VpcId:
AssociationProperty: ALIYUN::ECS::VPC::VPCId
Type: String
Label:
zh-cn: 現有VPC的執行個體ID
en: Existing VPC Instance ID
Resources:
ServerGroup:
Type: ALIYUN::ALB::ServerGroup
Properties:
VpcId:
Ref: VpcId
StickySessionConfig:
Cookie: B490B5EBF6F3CD402E515D22****
CookieTimeout: 1000
StickySessionEnabled: true
StickySessionType: Insert
HealthCheckConfig:
HealthCheckConnectPort: 80
HealthCheckEnabled: true
HealthCheckHost: www.example.com
HealthCheckCodes:
- http_2xx
HealthCheckHttpVersion: HTTP1.0
HealthCheckInterval: 5
HealthCheckMethod: HEAD
HealthCheckPath: /test/index.html
HealthCheckProtocol: HTTP
HealthCheckTimeout: 3
HealthyThreshold: 4
UnhealthyThreshold: 4
ServerGroupName: TestServerGroup
Outputs:
ServerGroupId:
Description: The ID of the server group.
Value:
Fn::GetAtt:
- ServerGroup
- ServerGroupId {
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"VpcId": {
"AssociationProperty": "ALIYUN::ECS::VPC::VPCId",
"Type": "String",
"Label": {
"zh-cn": "現有VPC的執行個體ID",
"en": "Existing VPC Instance ID"
}
}
},
"Resources": {
"ServerGroup": {
"Type": "ALIYUN::ALB::ServerGroup",
"Properties": {
"VpcId": {
"Ref": "VpcId"
},
"StickySessionConfig": {
"Cookie": "B490B5EBF6F3CD402E515D22****",
"CookieTimeout": 1000,
"StickySessionEnabled": true,
"StickySessionType": "Insert"
},
"HealthCheckConfig": {
"HealthCheckConnectPort": 80,
"HealthCheckEnabled": true,
"HealthCheckHost": "www.example.com",
"HealthCheckCodes": [
"http_2xx"
],
"HealthCheckHttpVersion": "HTTP1.0",
"HealthCheckInterval": 5,
"HealthCheckMethod": "HEAD",
"HealthCheckPath": "/test/index.html",
"HealthCheckProtocol": "HTTP",
"HealthCheckTimeout": 3,
"HealthyThreshold": 4,
"UnhealthyThreshold": 4
},
"ServerGroupName": "TestServerGroup"
}
}
},
"Outputs": {
"ServerGroupId": {
"Description": "The ID of the server group.",
"Value": {
"Fn::GetAtt": [
"ServerGroup",
"ServerGroupId"
]
}
}
}
}情境 2 :建立一個應用型負載平衡ALB執行個體,並向伺服器組中添加後端伺服器。
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 建立雙可用性區域ALB負載平衡。
en: Create a dual-Availability-Zone ALB.
Parameters:
CommonName:
Type: String
Default: elastic-app
ZoneId1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId2
Label:
en: Availability Zone
zh-cn: 可用性區域1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: 可用性區域2
InstanceType1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 執行個體規格1
InstanceType2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 執行個體規格2
InstancePassword:
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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符號)
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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符號)'
AssociationProperty: 'ALIYUN::ECS::Instance::Password'
Default: null
Resources:
Vpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Fn::Sub: ${CommonName}-vpc
VSwitch1:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.1.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-vsw
VSwitch2:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.2.0/24
ZoneId:
Ref: ZoneId2
VSwitchName:
Fn::Sub: ${CommonName}-vsw
SecurityGroup:
Type: 'ALIYUN::ECS::SecurityGroup'
Properties:
VpcId:
Ref: Vpc
SecurityGroupName:
Fn::Sub: ${CommonName}-sg
SecurityGroupIngress:
- PortRange: 443/443
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 80/80
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
EcsInstance1:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
InstanceName:
Fn::Sub: ${CommonName}-ecs-1
InstanceType:
Ref: InstanceType1
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 0
Password:
Ref: InstancePassword
UserData:
Fn::Sub: |-
#!/bin/bash
yum -y install nginx-1.20.1
instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
echo "This is instance1, the instance id is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
EcsInstance2:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
InstanceName:
Fn::Sub: ${CommonName}-ecs-2
InstanceType:
Ref: InstanceType2
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 0
Password:
Ref: InstancePassword
UserData:
Fn::Sub: |-
#!/bin/bash
yum -y install nginx-1.20.1
instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
echo "This is instance2, the instance id is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
Alb:
Type: 'ALIYUN::ALB::LoadBalancer'
Properties:
LoadBalancerName:
Fn::Sub: ${CommonName}-alb
LoadBalancerEdition: Basic
VpcId:
Ref: Vpc
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
ZoneMappings:
- ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
- ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
AlbServerGroup:
Type: 'ALIYUN::ALB::ServerGroup'
Properties:
VpcId:
Ref: Vpc
ServerGroupType: Instance
ServerGroupName:
Fn::Sub: ${CommonName}-server-group
HealthCheckConfig:
HealthCheckConnectPort: 80
HealthCheckCodes:
- http_2xx
- http_3xx
HealthCheckProtocol: HTTP
HealthCheckEnabled: true
HealthCheckPath: /
StickySessionConfig:
StickySessionEnabled: false
AlbBackendServerAttachment:
Type: 'ALIYUN::ALB::BackendServerAttachment'
Properties:
ServerGroupId:
Ref: AlbServerGroup
Servers:
- ServerType: Ecs
ServerId:
Ref: EcsInstance1
Port: 80
- ServerType: Ecs
ServerId:
Ref: EcsInstance2
Port: 80
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId1
- ZoneId2
- InstanceType1
- InstanceType2
- InstancePassword
Hidden:
- CommonName{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"zh-cn": "建立雙可用性區域ALB負載平衡。",
"en": "Create a dual-Availability-Zone ALB."
},
"Parameters": {
"CommonName": {
"Type": "String",
"Default": "elastic-app"
},
"ZoneId1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"ExclusiveTo": [
"ZoneId2"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域1"
}
},
"ZoneId2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"ExclusiveTo": [
"ZoneId1"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域2"
}
},
"InstanceType1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "執行個體規格1"
}
},
"InstanceType2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "執行個體規格2"
}
},
"InstancePassword": {
"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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
},
"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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
},
"AssociationProperty": "ALIYUN::ECS::Instance::Password",
"Default": null
}
},
"Resources": {
"Vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "192.168.0.0/16",
"VpcName": {
"Fn::Sub": "${CommonName}-vpc"
}
}
},
"VSwitch1": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "192.168.1.0/24",
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchName": {
"Fn::Sub": "${CommonName}-vsw"
}
}
},
"VSwitch2": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "192.168.2.0/24",
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchName": {
"Fn::Sub": "${CommonName}-vsw"
}
}
},
"SecurityGroup": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"SecurityGroupName": {
"Fn::Sub": "${CommonName}-sg"
},
"SecurityGroupIngress": [
{
"PortRange": "443/443",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
},
{
"PortRange": "80/80",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
}
]
}
},
"EcsInstance1": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchId": {
"Ref": "VSwitch1"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd",
"InstanceName": {
"Fn::Sub": "${CommonName}-ecs-1"
},
"InstanceType": {
"Ref": "InstanceType1"
},
"SystemDiskCategory": "cloud_essd",
"MaxAmount": 1,
"InternetMaxBandwidthOut": 0,
"Password": {
"Ref": "InstancePassword"
},
"UserData": {
"Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"This is instance1, the instance id is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
}
}
},
"EcsInstance2": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchId": {
"Ref": "VSwitch2"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "aliyun_3_9_x64_20G_alibase_20231219.vhd",
"InstanceName": {
"Fn::Sub": "${CommonName}-ecs-2"
},
"InstanceType": {
"Ref": "InstanceType2"
},
"SystemDiskCategory": "cloud_essd",
"MaxAmount": 1,
"InternetMaxBandwidthOut": 0,
"Password": {
"Ref": "InstancePassword"
},
"UserData": {
"Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"This is instance2, the instance id is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
}
}
},
"Alb": {
"Type": "ALIYUN::ALB::LoadBalancer",
"Properties": {
"LoadBalancerName": {
"Fn::Sub": "${CommonName}-alb"
},
"LoadBalancerEdition": "Basic",
"VpcId": {
"Ref": "Vpc"
},
"LoadBalancerBillingConfig": {
"PayType": "PostPay"
},
"AddressType": "Internet",
"ZoneMappings": [
{
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchId": {
"Ref": "VSwitch1"
}
},
{
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchId": {
"Ref": "VSwitch2"
}
}
]
}
},
"AlbServerGroup": {
"Type": "ALIYUN::ALB::ServerGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ServerGroupType": "Instance",
"ServerGroupName": {
"Fn::Sub": "${CommonName}-server-group"
},
"HealthCheckConfig": {
"HealthCheckConnectPort": 80,
"HealthCheckCodes": [
"http_2xx",
"http_3xx"
],
"HealthCheckProtocol": "HTTP",
"HealthCheckEnabled": true,
"HealthCheckPath": "/"
},
"StickySessionConfig": {
"StickySessionEnabled": false
}
}
},
"AlbBackendServerAttachment": {
"Type": "ALIYUN::ALB::BackendServerAttachment",
"Properties": {
"ServerGroupId": {
"Ref": "AlbServerGroup"
},
"Servers": [
{
"ServerType": "Ecs",
"ServerId": {
"Ref": "EcsInstance1"
},
"Port": 80
},
{
"ServerType": "Ecs",
"ServerId": {
"Ref": "EcsInstance2"
},
"Port": 80
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"ZoneId1",
"ZoneId2",
"InstanceType1",
"InstanceType2",
"InstancePassword"
]
}
],
"Hidden": [
"CommonName"
]
}
}
}情境 3 :搭建高可用的 nginx 網站。
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 建立雙可用性區域高可用NGINX網站,含VPC、ECS執行個體、ALB負載平衡、安全性群組及自動部署配置。
en: Establish a dual-Availability Zone high-availability NGINX website, encompassing
a Virtual Private Cloud (VPC), Elastic Cloud Server (ECS) instances, an Application
Load Balancer (ALB), Security Groups, and automated deployment configurations.
Parameters:
CommonName:
Type: String
Default: elastic-app
ZoneId1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- ZoneId2
Label:
en: Availability Zone
zh-cn: 可用性區域1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: 可用性區域2
InstanceType1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
SpotStrategy: SpotAsPriceGo
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 執行個體規格1
Description:
zh-cn: 本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。
en: >-
This solution will create a spot instance and automatically deploy a
nginx service.
Default: null
InstanceType2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
SpotStrategy: SpotAsPriceGo
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 執行個體規格2
Description:
zh-cn: 本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。
en: >-
This solution will create a spot instance and automatically deploy a
nginx service.
Default: null
InstancePassword:
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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符號)
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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符號)'
AssociationProperty: 'ALIYUN::ECS::Instance::Password'
Default: null
Resources:
Vpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Fn::Sub: ${CommonName}-vpc
VSwitch1:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.1.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-vsw
VSwitch2:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.2.0/24
ZoneId:
Ref: ZoneId2
VSwitchName:
Fn::Sub: ${CommonName}-vsw
SecurityGroup:
Type: 'ALIYUN::ECS::SecurityGroup'
Properties:
VpcId:
Ref: Vpc
SecurityGroupName:
Fn::Sub: ${CommonName}-sg
SecurityGroupIngress:
- PortRange: 443/443
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- PortRange: 80/80
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
EcsInstance1:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_
InstanceName:
Fn::Sub: ${CommonName}-ecs-1
InstanceType:
Ref: InstanceType1
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 0
SpotStrategy: SpotAsPriceGo
Password:
Ref: InstancePassword
UserData:
Fn::Sub: |-
#!/bin/bash
yum -y install nginx-1.20.1
instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
echo "Welcome to Nginx. Current instance is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
EcsInstance2:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_
InstanceName:
Fn::Sub: ${CommonName}-ecs-2
InstanceType:
Ref: InstanceType2
SystemDiskCategory: cloud_essd
MaxAmount: 1
InternetMaxBandwidthOut: 0
SpotStrategy: SpotAsPriceGo
Password:
Ref: InstancePassword
UserData:
Fn::Sub: |-
#!/bin/bash
yum -y install nginx-1.20.1
instanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`
echo "Welcome to Nginx. Current instance is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
Alb:
Type: 'ALIYUN::ALB::LoadBalancer'
Properties:
LoadBalancerName:
Fn::Sub: ${CommonName}-alb
LoadBalancerEdition: Basic
VpcId:
Ref: Vpc
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
ZoneMappings:
- ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch1
- ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch2
AlbServerGroup:
Type: 'ALIYUN::ALB::ServerGroup'
Properties:
VpcId:
Ref: Vpc
ServerGroupType: Instance
ServerGroupName:
Fn::Sub: ${CommonName}-server-group
HealthCheckConfig:
HealthCheckConnectPort: 80
HealthCheckCodes:
- http_2xx
- http_3xx
HealthCheckProtocol: HTTP
HealthCheckEnabled: true
HealthCheckPath: /
StickySessionConfig:
StickySessionEnabled: false
AlbBackendServerAttachment:
Type: 'ALIYUN::ALB::BackendServerAttachment'
Properties:
ServerGroupId:
Ref: AlbServerGroup
Servers:
- ServerType: Ecs
ServerId:
Ref: EcsInstance1
Port: 80
- ServerType: Ecs
ServerId:
Ref: EcsInstance2
Port: 80
AlbListener:
Type: 'ALIYUN::ALB::Listener'
Properties:
ListenerPort: 80
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: Alb
ListenerProtocol: HTTP
Outputs:
WebUrl:
Description:
zh-cn: Web 存取地址。
en: The Addresses of Web.
Value:
'Fn::Sub': 'http://${Alb.DNSName}'
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId1
- InstanceType1
- ZoneId2
- InstanceType2
- InstancePassword
TemplateTags:
- acs:example:彈性計算:搭建高可用的 nginx 網站
Hidden:
- CommonName
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"zh-cn": "建立雙可用性區域高可用NGINX網站,含VPC、ECS執行個體、ALB負載平衡、安全性群組及自動部署配置。",
"en": "Establish a dual-Availability Zone high-availability NGINX website, encompassing a Virtual Private Cloud (VPC), Elastic Cloud Server (ECS) instances, an Application Load Balancer (ALB), Security Groups, and automated deployment configurations."
},
"Parameters": {
"CommonName": {
"Type": "String",
"Default": "elastic-app"
},
"ZoneId1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"AutoSelectFirst": true,
"ExclusiveTo": [
"ZoneId2"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域1"
}
},
"ZoneId2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"AutoSelectFirst": true,
"ExclusiveTo": [
"ZoneId1"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "可用性區域2"
}
},
"InstanceType1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"SpotStrategy": "SpotAsPriceGo",
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "執行個體規格1"
},
"Description": {
"zh-cn": "本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。",
"en": "This solution will create a spot instance and automatically deploy a nginx service."
},
"Default": null
},
"InstanceType2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"SpotStrategy": "SpotAsPriceGo",
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "執行個體規格2"
},
"Description": {
"zh-cn": "本方案會建立一個搶佔式執行個體,並且自動部署nginx服務。",
"en": "This solution will create a spot instance and automatically deploy a nginx service."
},
"Default": null
},
"InstancePassword": {
"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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
},
"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,必須包含三項(大寫字母、小寫字母、數字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符號)"
},
"AssociationProperty": "ALIYUN::ECS::Instance::Password",
"Default": null
}
},
"Resources": {
"Vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "192.168.0.0/16",
"VpcName": {
"Fn::Sub": "${CommonName}-vpc"
}
}
},
"VSwitch1": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "192.168.1.0/24",
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchName": {
"Fn::Sub": "${CommonName}-vsw"
}
}
},
"VSwitch2": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"CidrBlock": "192.168.2.0/24",
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchName": {
"Fn::Sub": "${CommonName}-vsw"
}
}
},
"SecurityGroup": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"SecurityGroupName": {
"Fn::Sub": "${CommonName}-sg"
},
"SecurityGroupIngress": [
{
"PortRange": "443/443",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
},
{
"PortRange": "80/80",
"SourceCidrIp": "0.0.0.0/0",
"IpProtocol": "tcp"
}
]
}
},
"EcsInstance1": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchId": {
"Ref": "VSwitch1"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "aliyun_3_9_x64_20G_alibase_",
"InstanceName": {
"Fn::Sub": "${CommonName}-ecs-1"
},
"InstanceType": {
"Ref": "InstanceType1"
},
"SystemDiskCategory": "cloud_essd",
"MaxAmount": 1,
"InternetMaxBandwidthOut": 0,
"SpotStrategy": "SpotAsPriceGo",
"Password": {
"Ref": "InstancePassword"
},
"UserData": {
"Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"Welcome to Nginx. Current instance is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
}
}
},
"EcsInstance2": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchId": {
"Ref": "VSwitch2"
},
"SecurityGroupId": {
"Ref": "SecurityGroup"
},
"ImageId": "aliyun_3_9_x64_20G_alibase_",
"InstanceName": {
"Fn::Sub": "${CommonName}-ecs-2"
},
"InstanceType": {
"Ref": "InstanceType2"
},
"SystemDiskCategory": "cloud_essd",
"MaxAmount": 1,
"InternetMaxBandwidthOut": 0,
"SpotStrategy": "SpotAsPriceGo",
"Password": {
"Ref": "InstancePassword"
},
"UserData": {
"Fn::Sub": "#!/bin/bash\nyum -y install nginx-1.20.1\ninstanceId=`curl http://100.100.100.200/latest/meta-data/instance-id`\necho \"Welcome to Nginx. Current instance is $instanceId\" > /usr/share/nginx/html/index.html \nsystemctl start nginx \nsystemctl enable nginx"
}
}
},
"Alb": {
"Type": "ALIYUN::ALB::LoadBalancer",
"Properties": {
"LoadBalancerName": {
"Fn::Sub": "${CommonName}-alb"
},
"LoadBalancerEdition": "Basic",
"VpcId": {
"Ref": "Vpc"
},
"LoadBalancerBillingConfig": {
"PayType": "PostPay"
},
"AddressType": "Internet",
"ZoneMappings": [
{
"ZoneId": {
"Ref": "ZoneId1"
},
"VSwitchId": {
"Ref": "VSwitch1"
}
},
{
"ZoneId": {
"Ref": "ZoneId2"
},
"VSwitchId": {
"Ref": "VSwitch2"
}
}
]
}
},
"AlbServerGroup": {
"Type": "ALIYUN::ALB::ServerGroup",
"Properties": {
"VpcId": {
"Ref": "Vpc"
},
"ServerGroupType": "Instance",
"ServerGroupName": {
"Fn::Sub": "${CommonName}-server-group"
},
"HealthCheckConfig": {
"HealthCheckConnectPort": 80,
"HealthCheckCodes": [
"http_2xx",
"http_3xx"
],
"HealthCheckProtocol": "HTTP",
"HealthCheckEnabled": true,
"HealthCheckPath": "/"
},
"StickySessionConfig": {
"StickySessionEnabled": false
}
}
},
"AlbBackendServerAttachment": {
"Type": "ALIYUN::ALB::BackendServerAttachment",
"Properties": {
"ServerGroupId": {
"Ref": "AlbServerGroup"
},
"Servers": [
{
"ServerType": "Ecs",
"ServerId": {
"Ref": "EcsInstance1"
},
"Port": 80
},
{
"ServerType": "Ecs",
"ServerId": {
"Ref": "EcsInstance2"
},
"Port": 80
}
]
}
},
"AlbListener": {
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"ListenerPort": 80,
"DefaultActions": [
{
"Type": "ForwardGroup",
"ForwardGroupConfig": {
"ServerGroupTuples": [
{
"ServerGroupId": {
"Ref": "AlbServerGroup"
}
}
]
}
}
],
"LoadBalancerId": {
"Ref": "Alb"
},
"ListenerProtocol": "HTTP"
}
}
},
"Outputs": {
"WebUrl": {
"Description": {
"zh-cn": "Web 存取地址。",
"en": "The Addresses of Web."
},
"Value": {
"Fn::Sub": "http://${Alb.DNSName}"
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"ZoneId1",
"InstanceType1",
"ZoneId2",
"InstanceType2",
"InstancePassword"
]
}
],
"TemplateTags": [
"acs:example:彈性計算:搭建高可用的 nginx 網站"
],
"Hidden": [
"CommonName"
]
}
}
}更多樣本,請參考包含此資源的公用模板。