Gunakan ALIYUN::ALB::ServerGroup untuk membuat grup server.
Sintaks
{
"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
}
}Properti
Property name | Type | Required | Update allowed | Description | Constraints |
HealthCheckConfig | Map | Yes | Yes | Konfigurasi pemeriksaan kesehatan. | Untuk informasi selengkapnya, lihat properti HealthCheckConfig. |
ServerGroupName | String | Yes | Yes | Nama grup server. | Nama harus terdiri dari 2 hingga 128 karakter. Nama harus diawali dengan huruf dan dapat berisi angka, titik (.), garis bawah (_), serta tanda hubung (-). |
VpcId | String | No | No | ID virtual private cloud (VPC). | Hanya server dalam VPC ini yang dapat ditambahkan ke grup server. |
Protocol | String | No | No | Protokol backend. | Nilai yang valid:
Catatan Jika ServerGroupType diatur ke Fc, hanya HTTP yang didukung. |
ResourceGroupId | String | No | Yes | ID kelompok sumber daya. | None |
Scheduler | String | No | Yes | Algoritma penjadwalan. | Nilai yang valid:
|
ServerGroupType | String | No | No | Tipe grup server. | Nilai yang valid:
|
ServiceName | String | No | Yes | Nama layanan Kubernetes yang sesuai dengan grup server. | Catatan Parameter ini hanya berlaku untuk skenario Ingress. |
StickySessionConfig | Map | No | Yes | Konfigurasi persistensi sesi. | Untuk informasi selengkapnya, lihat properti StickySessionConfig. |
Tags | List | No | Yes | Tag. | Anda dapat menambahkan hingga 20 tag. Untuk informasi selengkapnya, lihat properti Tags. |
UpstreamKeepaliveEnabled | Boolean | No | Yes | Menentukan apakah koneksi keep-alive dengan server backend diaktifkan. |
|
SlowStartConfig | Map | No | Yes | Konfigurasi mulai lambat. | Jika Anda mengaktifkan mulai lambat, jumlah permintaan yang diteruskan ke server backend yang baru ditambahkan akan meningkat secara linear selama periode tertentu. Untuk informasi selengkapnya, lihat properti SlowStartConfig. Catatan
|
ConnectionDrainConfig | Map | No | Yes | Konfigurasi pengurasan koneksi. | Jika Anda mengaktifkan pengurasan koneksi, Server Load Balancer memungkinkan koneksi yang ada diproses selama periode tertentu setelah server backend dihapus atau gagal dalam pemeriksaan kesehatan. Catatan Instans Edisi Dasar tidak mendukung pengurasan koneksi. Hanya instans Edisi Standar dan instans yang diaktifkan WAF yang mendukung fitur ini. Grup server berbasis instans dan berbasis IP mendukung pengurasan koneksi. Grup server Function Compute tidak mendukung. |
UchConfig | Map | No | Yes | Parameter untuk penghashan konsisten berbasis URL. | Untuk informasi selengkapnya, lihat properti UchConfig. |
CrossZoneEnabled | Boolean | No | Yes | Menentukan apakah load balancing lintas zona diaktifkan untuk grup server. | Nilai yang valid:
Catatan
|
Ipv6Enabled | Boolean | No | No | Menentukan apakah IPv6 diaktifkan. | None |
Sintaks UchConfig
"UchConfig": {
"Type": String,
"Value": String
}Properti UchConfig
Property name | Type | Required | Update allowed | Description | Constraints |
Type | String | Yes | No | Tipe parameter. | Nilainya hanya dapat berupa QueryString. |
Value | String | Yes | No | Nilai parameter penghashan konsisten. | None |
Sintaks ConnectionDrainConfig
"ConnectionDrainConfig": {
"ConnectionDrainTimeout": Integer,
"ConnectionDrainEnabled": Boolean
}Properti ConnectionDrainConfig
Property Name | Type | Required | Update allowed | Description | Constraints |
ConnectionDrainTimeout | Integer | Yes | Yes | Periode timeout untuk pengurasan koneksi. | Nilai yang valid: 0 hingga 900. Nilai default: 300. |
ConnectionDrainEnabled | Boolean | Yes | Yes | Menentukan apakah pengurasan koneksi diaktifkan. | Nilai yang valid:
|
Sintaks SlowStartConfig
"SlowStartConfig": {
"SlowStartDuration": Integer,
"SlowStartEnabled": Boolean
}Properti SlowStartConfig
Property Name | Type | Required | Update allowed | Description | Constraints |
SlowStartDuration | Integer | Yes | Yes | Durasi mulai lambat. | Nilai yang valid: 30 hingga 900. Nilai default: 30. |
SlowStartEnabled | Boolean | Yes | Yes | Menentukan apakah mulai lambat diaktifkan. | Nilai yang valid:
|
Sintaks StickySessionConfig
"StickySessionConfig": {
"Cookie": String,
"CookieTimeout": Integer,
"StickySessionType": String,
"StickySessionEnabled": Boolean
}Properti StickySessionConfig
Property Name | Type | Required | Update allowed | Description | Constraints |
Cookie | String | No | Yes | Cookie yang dikonfigurasi pada server. | Cookie harus terdiri dari 1 hingga 200 karakter. Tidak boleh diawali dengan tanda dolar ($). Dapat berisi huruf dan angka. Tidak boleh berisi koma (,), titik koma (;), atau spasi. Catatan Parameter ini wajib jika StickySessionEnabled diatur ke true dan StickySessionType diatur ke Server. |
CookieTimeout | Integer | No | Yes | Periode timeout cookie. | Nilai yang valid: 1 hingga 86.400. Nilai default: 1000. Unit: detik. Catatan Parameter ini wajib jika StickySessionEnabled diatur ke true dan StickySessionType diatur ke Insert. |
StickySessionEnabled | Boolean | No | Yes | Menentukan apakah persistensi sesi diaktifkan. | Nilai yang valid:
Catatan Parameter ini wajib jika ServerGroupType diatur ke |
StickySessionType | String | No | Yes | Metode yang digunakan untuk memproses cookie. | Nilai yang valid:
Catatan Parameter ini wajib jika StickySessionEnabled diatur ke true. |
Sintaks 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
}Properti HealthCheckConfig
Property Name | Type | Required | Update allowed | Description | Constraints |
HealthCheckEnabled | Boolean | Yes | Yes | Menentukan apakah pemeriksaan kesehatan diaktifkan. | Nilai yang valid:
|
HealthCheckCodes | List | No | Yes | Daftar kode status HTTP untuk pemeriksaan kesehatan yang berhasil. | Nilai yang valid:
Catatan Parameter ini berlaku ketika HealthCheckProtocol diatur ke HTTP, HTTPS, atau gRPC. |
HealthCheckConnectPort | Integer | No | Yes | Port pada server backend yang digunakan untuk pemeriksaan kesehatan. | Nilai yang valid: 0 hingga 65.535. Nilai default: 0. Nilai ini menunjukkan bahwa port server backend digunakan untuk pemeriksaan kesehatan. |
HealthCheckHost | String | No | Yes | Nama domain untuk pemeriksaan kesehatan. | Nama domain harus terdiri dari 1 hingga 80 karakter. Dapat berisi huruf kecil, angka, tanda hubung (-), dan titik (.). Contoh: Catatan Parameter ini berlaku ketika HealthCheckProtocol diatur ke HTTP. |
HealthCheckHttpVersion | String | No | Yes | Versi HTTP untuk pemeriksaan kesehatan. | Nilai yang valid:
Catatan Parameter ini berlaku ketika HealthCheckProtocol diatur ke HTTP. |
HealthCheckInterval | Integer | No | Yes | Interval antara dua pemeriksaan kesehatan berturut-turut. | Nilai yang valid: 1 hingga 50. Nilai default: 2. Unit: detik. |
HealthCheckMethod | String | No | Yes | Metode pemeriksaan kesehatan. | Nilai yang valid:
Catatan Parameter ini hanya berlaku ketika HealthCheckProtocol diatur ke HTTP, HTTPS, atau gRPC. |
HealthCheckPath | String | No | Yes | Jalur untuk pemeriksaan kesehatan. | Jalur harus terdiri dari 1 hingga 80 karakter dan diawali dengan garis miring (/). Dapat berisi huruf, angka, dan karakter khusus Catatan Parameter ini berlaku ketika HealthCheckProtocol diatur ke HTTP. |
HealthCheckProtocol | String | No | Yes | Protokol pemeriksaan kesehatan. | Nilai yang valid:
|
HealthCheckTimeout | Integer | No | Yes | Waktu tunggu untuk respons dari pemeriksaan kesehatan. | Jika instans ECS backend tidak merespons dalam periode timeout yang ditentukan, pemeriksaan kesehatan gagal. Nilai yang valid: 1 hingga 300. Nilai default: 5. Unit: detik. Catatan Jika nilai HealthCheckTimeout lebih kecil daripada nilai HealthCheckInterval, HealthCheckTimeout diabaikan dan nilai HealthCheckInterval digunakan sebagai periode timeout. |
HealthyThreshold | Integer | No | Yes | Jumlah pemeriksaan kesehatan berturut-turut yang berhasil sebelum server backend dinyatakan sehat. | Nilai yang valid: 2 hingga 10. Nilai default: 3. |
UnhealthyThreshold | Integer | No | Yes | Jumlah pemeriksaan kesehatan berturut-turut yang gagal sebelum server backend dinyatakan tidak sehat. | Nilai yang valid: 2 hingga 10. Nilai default: 3. |
Sintaks Tags
"Tags": [
{
"Key": String,
"Value": String
}
] Properti Tags
Property Name | Type | Required | Update allowed | Description | Constraints |
Key | String | Yes | No | Kunci tag. | Kunci tag harus terdiri dari 1 hingga 128 karakter. Tidak boleh diawali dengan |
Value | String | No | No | Nilai tag. | Nilai tag dapat terdiri dari 0 hingga 128 karakter. Tidak boleh diawali dengan |
Nilai kembalian
Fn::GetAtt
ServerGroupId: ID grup server.
Arn: Nama Sumber Daya Alibaba Cloud (ARN).
Contoh
Ubah nilai parameter sesuai kebutuhan Anda.
Skenario 1: Tambahkan server backend ke grup server.
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
VpcId:
AssociationProperty: ALIYUN::ECS::VPC::VPCId
Type: String
Label:
zh-cn: Instance ID of the existing VPC
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": "Instance ID of the existing VPC",
"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"
]
}
}
}
}Skenario 2: Buat instans Application Load Balancer (ALB) dan tambahkan server backend ke grup server.
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: Create a dual-zone 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: Zone 1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: Zone 2
InstanceType1:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: Instance Type 1
InstanceType2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: Instance Type 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: >-
The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
Label:
en: Instance Password
zh-cn: Instance Password
ConstraintDescription:
en: >-
Length 8-30, must contain three(Capital letters, lowercase letters,
numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 'The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
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": "Create a dual-zone 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": "Zone 1"
}
},
"ZoneId2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"ExclusiveTo": [
"ZoneId1"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "Zone 2"
}
},
"InstanceType1": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "Instance Type 1"
}
},
"InstanceType2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
"AssociationPropertyMetadata": {
"InstanceChargeType": "PostPaid",
"SystemDiskCategory": "cloud_essd",
"ZoneId": "${ZoneId}"
},
"Label": {
"en": "Instance Type",
"zh-cn": "Instance Type 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": "The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
},
"Label": {
"en": "Instance Password",
"zh-cn": "Instance Password"
},
"ConstraintDescription": {
"en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
"zh-cn": "The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
},
"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"
]
}
}
}Skenario 3: Bangun website NGINX berkeandalan tinggi.
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: Create a dual-zone, high-availability NGINX website that includes a VPC, ECS instances, an ALB instance, security groups, and automatic deployment configurations.
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: Zone 1
ZoneId2:
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- ZoneId1
Label:
en: Availability Zone
zh-cn: Zone 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: Instance Type 1
Description:
zh-cn: This solution creates a spot instance and automatically deploys the NGINX service.
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: Instance Type 2
Description:
zh-cn: This solution creates a spot instance and automatically deploys the NGINX service.
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: >-
The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
Label:
en: Instance Password
zh-cn: Instance Password
ConstraintDescription:
en: >-
Length 8-30, must contain three(Capital letters, lowercase letters,
numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 'The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
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: The web access endpoint.
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:elastic computing:build a high-availability nginx website
Hidden:
- CommonName
{
"ROSTemplateFormatVersion": "2015-09-01",
"Description": {
"zh-cn": "Create a dual-zone, high-availability NGINX website that includes a VPC, ECS instances, an ALB instance, security groups, and automatic deployment configurations.",
"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": "Zone 1"
}
},
"ZoneId2": {
"Type": "String",
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
"AssociationPropertyMetadata": {
"AutoSelectFirst": true,
"ExclusiveTo": [
"ZoneId1"
]
},
"Label": {
"en": "Availability Zone",
"zh-cn": "Zone 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": "Instance Type 1"
},
"Description": {
"zh-cn": "This solution creates a spot instance and automatically deploys the NGINX service.",
"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": "Instance Type 2"
},
"Description": {
"zh-cn": "This solution creates a spot instance and automatically deploys the NGINX service.",
"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": "The logon password of the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
},
"Label": {
"en": "Instance Password",
"zh-cn": "Instance Password"
},
"ConstraintDescription": {
"en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
"zh-cn": "The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
},
"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": "The web access endpoint.",
"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:elastic computing:build a high-availability nginx website"
],
"Hidden": [
"CommonName"
]
}
}
}Untuk contoh lainnya, lihat templat publik yang berisi resource ini.