ALIYUN::ALB::Listener类型用于创建HTTP、HTTPS或QUIC监听。
语法
{
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"RequestTimeout": Integer,
"ListenerPort": Integer,
"Http2Enabled": Boolean,
"DefaultActions": List,
"Certificates": List,
"IdleTimeout": Integer,
"LoadBalancerId": String,
"ListenerProtocol": String,
"QuicConfig": Map,
"GzipEnabled": Boolean,
"SecurityPolicyId": String,
"ListenerDescription": String,
"XForwardedForConfig": Map,
"CaEnabled": Boolean,
"CaCertificates": List,
"ListenerStatus": String,
"LogConfig": Map
}
}属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
DefaultActions | List | 是 | 是 | 规则动作列表。 | 取值示例: 更多信息,请参见DefaultActions属性。 |
ListenerPort | Integer | 是 | 否 | 监听端口。 | 取值范围:1~65,535。 |
ListenerProtocol | String | 是 | 否 | 监听协议。 | 取值:
|
LoadBalancerId | String | 是 | 否 | 负载均衡实例ID。 | 无 |
CaCertificates | List | 否 | 是 | CA证书信息。 | 更多信息,请参见CaCertificates属性。 |
CaEnabled | Boolean | 否 | 是 | 是否开启双向认证。 | 取值:
|
Certificates | List | 否 | 是 | 证书。 | 更多信息,请参见Certificates属性。 |
GzipEnabled | Boolean | 否 | 是 | 是否开启Gzip压缩,压缩特定文件类型。 | 取值:
|
Http2Enabled | Boolean | 否 | 是 | 是否开启HTTP/2特性。 | 取值:
说明 仅HTTPS监听支持指定该参数。 |
IdleTimeout | Integer | 否 | 是 | 连接空闲超时时间。 | 取值范围:1~60。 默认值:15。 单位:秒。 如果在超时时间内一直没有访问请求,负载均衡会暂时中断当前连接,直到下一次请求来临时重新建立新的连接。 |
ListenerDescription | String | 否 | 是 | 监听的描述信息。 | 长度为2~256个字符。 |
ListenerStatus | String | 否 | 是 | 监听的状态。 | 取值:
|
LogConfig | Map | 否 | 是 | 日志配置。 | 更多信息,请参见LogConfig属性。 |
QuicConfig | Map | 否 | 是 | 配置关联的QUIC监听。 | 更多信息,请参见QuicConfig属性。 |
RequestTimeout | Integer | 否 | 是 | 请求超时时间。 | 取值范围:1~180。 默认值:60。 单位:秒。 如果在超时时间内后端服务器一直没有响应,负载均衡将放弃等待,并给客户端返回HTTP 504错误码。 |
SecurityPolicyId | String | 否 | 是 | 安全策略ID。 | 支持系统安全策略和自定义安全策略。 默认值:tls_cipher_policy_1_0,表示系统安全策略。 说明 仅HTTPS监听支持此参数。 |
XForwardedForConfig | Map | 否 | 是 | XForward字段配置信息。 | 更多信息,请参见XForwardedForConfig属性。 |
DefaultActions语法
"DefaultActions": [
{
"Type": String,
"ForwardGroupConfig": Map
}
]DefaultActions属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
ForwardGroupConfig | Map | 是 | 是 | 转发Action对应的配置。 | 更多信息,请参见ForwardGroupConfig属性。 |
Type | String | 是 | 是 | 动作类型。 | 取值:ForwardGroup,表示转发至多个虚拟服务器组。 |
ForwardGroupConfig语法
"ForwardGroupConfig": {
"ServerGroupTuples": List
}ForwardGroupConfig属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
ServerGroupTuples | List | 是 | 是 | 转发目标服务器组。 | 更多信息,请参见ServerGroupTuples属性。 |
ServerGroupTuples语法
"ServerGroupTuples": [
{
"ServerGroupId": String
}
]ServerGroupTuples属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
ServerGroupId | String | 是 | 是 | 转发到的目标服务器组ID。 | 无 |
Certificates语法
"Certificates": [
{
"CertificateId": String
}
]Certificates属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
CertificateId | String | 否 | 是 | 证书ID。 | 当前仅支持服务器证书。 |
QuicConfig语法
"QuicConfig": {
"QuicListenerId": String,
"QuicUpgradeEnabled": Boolean
}QuicConfig属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
QuicListenerId | String | 否 | 是 | 需要关联的QUIC监听ID。 | 当QuicUpgradeEnabled取值为true时必须指定该参数。 说明
|
QuicUpgradeEnabled | Boolean | 否 | 是 | 是否开启QUIC升级。 | 取值:
说明 仅HTTPS监听支持指定该参数。 |
LogConfig语法
"LogConfig": {
"AccessLogTracingConfig": Map,
"AccessLogRecordCustomizedHeadersEnabled": Boolean
}LogConfig属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
AccessLogTracingConfig | Map | 否 | 是 | 访问日志 Xtrace 相关的配置信息。 | 更多信息,请参见AccessLogTracingConfig属性。 |
AccessLogRecordCustomizedHeadersEnabled | Boolean | 否 | 是 | 访问日志是否开启携带自定义头。 | 取值:
|
AccessLogTracingConfig语法
"AccessLogTracingConfig": {
"TracingSample": Integer,
"TracingType": String,
"TracingEnabled": Boolean
}AccessLogTracingConfig属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
TracingEnabled | Boolean | 否 | 是 | 是否开启 Xtrace 功能。 | 取值:
说明 只有实例访问日志开关 AccessLogEnabled 打开时,才能将此参数设置为 true。 |
TracingSample | Integer | 否 | 是 | Xtrace 的采样率。 | 取值:1~10000。 说明 TracingEnabled 为 true 时,此值有效。 |
TracingType | String | 否 | 是 | Xtrace 类型。 | 合法取值为 Zipkin。 说明 TracingEnabled 为 true 时,此值有效。 |
XForwardedForConfig语法
"XForwardedForConfig": {
"XForwardedForClientCertFingerprintAlias": String,
"XForwardedForClientCertFingerprintEnabled": Boolean,
"XForwardedForClientCertIssuerDNAlias": String,
"XForwardedForClientCertClientVerifyAlias": String,
"XForwardedForSLBIdEnabled": Boolean,
"XForwardedForClientCertSubjectDNEnabled": Boolean,
"XForwardedForClientCertSubjectDNAlias": String,
"XForwardedForProtoEnabled": Boolean,
"XForwardedForClientSrcPortEnabled": Boolean,
"XForwardedForSLBPortEnabled": Boolean,
"XForwardedForEnabled": Boolean,
"XForwardedForClientCertIssuerDNEnabled": Boolean,
"XForwardedForClientCertClientVerifyEnabled": Boolean,
"XForwardedForClientSourceIpsEnabled": Boolean,
"XForwardedForClientSourceIpsTrusted": String,
"XForwardedForProcessingMode": String,
"XForwardedForHostEnabled": Boolean
}XForwardedForConfig属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
XForwardedForClientCertClientVerifyAlias | String | 否 | 是 | 自定义头名称,用于获取对访问负载均衡实例客户端证书的校验结果。 | 当XForwardedForClientCertClientVerifyEnabled取值为true时,该参数有效。 长度为1~40个字符,可包含小写英文字母、数字、短划线(-)和下划线(_)。 说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertClientVerifyEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Clientcert-clientverify头字段获取对访问负载均衡实例客户端证书的校验结果。 | 取值:
说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertFingerprintAlias | String | 否 | 是 | 自定义头名称,用于获取访问负载均衡实例客户端证书的指纹取值。 | 当XForwardedForClientCertFingerprintEnabled取值为true时,该参数有效。 长度为1~40个字符,可包含小写英文字母、数字、短划线(-)和下划线(_)。 说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertFingerprintEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Clientcert-fingerprint头字段获取访问负载均衡实例客户端证书的指纹取值。 | 取值:
说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertIssuerDNAlias | String | 否 | 是 | 自定义头名称,用于获取访问负载均衡实例客户端证书的发行者信息。 | 当XForwardedForClientCertIssuerDNEnabled取值为true时,该参数有效。 长度为1~40个字符,可包含小写英文字母、数字、短划线(-)和下划线(_)。 说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertIssuerDNEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Clientcert-issuerdn头字段获取访问负载均衡实例客户端证书的发行者信息。 | 取值:
说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertSubjectDNAlias | String | 否 | 是 | 自定义头名称,用于获取访问负载均衡实例客户端证书的所有者信息。 | 当XForwardedForClientCertSubjectDNEnabled取值为true时,该参数有效。 长度为1~40个字符,可包含小写英文字母、数字、短划线(-)和下划线(_)。 说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientCertSubjectDNEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Clientcert-subjectdn头字段获取访问负载均衡实例客户端证书的所有者信息。 | 取值:
说明 仅HTTPS监听支持指定该参数。 |
XForwardedForClientSourceIpsEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Client-SourceIps头字段获取访问负载均衡实例客户端的源端口。 | 取值:
|
XForwardedForClientSourceIpsTrusted | String | 否 | 是 | 指定可信的代理 IP。 | 应用型负载均衡 ALB 会从后往前遍历 |
XForwardedForClientSrcPortEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Client-Port头字段获取访问负载均衡实例客户端的端口。 | 取值:
说明 仅HTTP和HTTPS监听支持指定该参数。 |
XForwardedForEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-For头字段获取来访者真实IP地址。 | 取值:
说明 仅HTTP和HTTPS监听支持指定该参数。 |
XForwardedForHostEnabled | Boolean | 否 | 是 | 是否开启通过 | 取值:
说明 HTTP、HTTPS 和 QUIC 监听支持此参数。 |
XForwardedForProcessingMode | String | 否 | 是 | 处理 | 只有当 XForwardedForEnabled 为 true 时,此值才会生效。取值:
说明
|
XForwardedForProtoEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Proto头字段获取负载均衡实例的监听协议。 | 取值:
|
XForwardedForSLBIdEnabled | Boolean | 否 | 是 | 是否通过SLB-ID头字段获取负载均衡实例ID。 | 取值:
|
XForwardedForSLBPortEnabled | Boolean | 否 | 是 | 是否通过X-Forwarded-Port头字段获取负载均衡实例的监听端口。 | 取值:
|
CaCertificates语法
"CaCertificates": [
{
"CertificateId": String
}
]CaCertificates属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
CertificateId | String | 否 | 是 | CA证书ID。 | 无 |
返回值
Fn::GetAtt
ListenerId:监听ID。
LoadBalancerId:应用型负载均衡实例 ID。
示例
场景 1 :创建HTTP监听。
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
LoadBalancerId:
Type: String
Description: The ID of the ALB instance.
Default: lb-bp1iilcd9ujny84z8****
Resources:
Listener:
Type: ALIYUN::ALB::Listener
Properties:
ListenerPort: 80
DefaultActions:
- ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId: sgp-46ndzg2wz4v5mp****
Type: ForwardGroup
LoadBalancerId:
Ref: LoadBalancerId
ListenerProtocol: HTTP
Outputs:
ListenerId:
Description: The ID of the listener.
Value:
Fn::GetAtt:
- Listener
- ListenerId {
"ROSTemplateFormatVersion": "2015-09-01",
"Parameters": {
"LoadBalancerId": {
"Type": "String",
"Description": "The ID of the ALB instance.",
"Default": "lb-bp1iilcd9ujny84z8****"
}
},
"Resources": {
"Listener": {
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"ListenerPort": 80,
"DefaultActions": [
{
"ForwardGroupConfig": {
"ServerGroupTuples": [
{
"ServerGroupId": "sgp-46ndzg2wz4v5mp****"
}
]
},
"Type": "ForwardGroup"
}
],
"LoadBalancerId": {
"Ref": "LoadBalancerId"
},
"ListenerProtocol": "HTTP"
}
}
},
"Outputs": {
"ListenerId": {
"Description": "The ID of the listener.",
"Value": {
"Fn::GetAtt": [
"Listener",
"ListenerId"
]
}
}
}
}场景 2 :创建双可用区ALB负载均衡,并创建HTTP监听。
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
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
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
AlbListener:
Type: 'ALIYUN::ALB::Listener'
Properties:
ListenerPort: 80
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: Alb
ListenerProtocol: HTTP
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- ZoneId1
- ZoneId2
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"
}
}
},
"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"
}
}
},
"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
}
}
},
"AlbListener": {
"Type": "ALIYUN::ALB::Listener",
"Properties": {
"ListenerPort": 80,
"DefaultActions": [
{
"Type": "ForwardGroup",
"ForwardGroupConfig": {
"ServerGroupTuples": [
{
"ServerGroupId": {
"Ref": "AlbServerGroup"
}
}
]
}
}
],
"LoadBalancerId": {
"Ref": "Alb"
},
"ListenerProtocol": "HTTP"
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"ZoneId1",
"ZoneId2"
]
}
],
"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"
]
}
}
}更多示例,请参考包含此资源的公共模板。