Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add technical solution 46 #239

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ Parameters:
AllowedPattern: '^[a-z0-9]+[a-z0-9\-]*[a-z0-9]+$'
MaxLength: 63
Type: String
AssociationProperty: AutoCompleteInput
AssociationPropertyMetadata:
Length: 5
Prefix: application-cdn-oss-
CharacterClasses:
- Class: lowercase
min: 1
DomainName:
Placeholder: example.com
Type: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,371 @@
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Improve application availability through ALB+ESS.
zh-cn: 通过ALB+ESS提升应用的可用性。
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: ecs.c7.large
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: ecs.c6.large
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
ScalingTime:
Type: String
Label:
en: Automatic expansion execution time
zh-cn: 自动扩容执行时间
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'YYYY-MM-DDThh:mmZ'
Description:
zh-cn: 本方案创建完成预计需要 3-5 分钟,建议选择 5 分钟之后的时间观察扩容效果。
en: >-
It is estimated that it will take 3-5 minutes to complete the creation of this solution.
It is recommended to choose a time after 5 minutes to observe the expansion effect.
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: 22/22
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- 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
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 "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
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 "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
AlbListener:
Type: 'ALIYUN::ALB::Listener'
Properties:
ListenerPort: 80
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: Alb
ListenerProtocol: HTTP
EssScalingGroup:
Type: 'ALIYUN::ESS::ScalingGroup'
Properties:
VSwitchIds:
- Ref: VSwitch1
- Ref: VSwitch2
ScalingGroupName:
Fn::Sub: ${CommonName}-${ALIYUN::StackId}
RemovalPolicys:
- NewestInstance
MinSize: 0
MaxSize: 4
DefaultCooldown: 300
MultiAZPolicy: COMPOSABLE
AzBalance: true
DependsOn: SecurityGroup
EssServerGroupAttachment:
Type: 'ALIYUN::ESS::ServerGroupAttachment'
DependsOn: EssScalingGroupEnable
Properties:
ScalingGroupId:
Ref: EssScalingGroup
ForceAttach: true
ServerGroups:
- Type: ALB
Port: 80
ServerGroupId:
Ref: AlbServerGroup
Weight: 100
EssScalingConfiguration:
Type: 'ALIYUN::ESS::ScalingConfiguration'
Properties:
SecurityGroupId:
Ref: SecurityGroup
ImageId: aliyun_3_9_x64_20G_alibase_20231219.vhd
SpotStrategy: SpotAsPriceGo
ScalingConfigurationName:
Fn::Sub: ${CommonName}-asc
ScalingGroupId:
Ref: EssScalingGroup
InstanceTypes:
- Ref: InstanceType1
- Ref: InstanceType2
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
Password:
Ref: InstancePassword
InstanceName:
Fn::Sub: ${CommonName}-ess
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 instance from ess, the instance id is $instanceId" > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl enable nginx
EssScalingGroupEnable:
Type: 'ALIYUN::ESS::ScalingGroupEnable'
Properties:
ScalingGroupId:
Ref: EssScalingGroup
ScalingConfigurationId:
Ref: EssScalingConfiguration
EssScalingRule:
Type: 'ALIYUN::ESS::ScalingRule'
Properties:
ScalingRuleName:
Fn::Sub: ${CommonName}-asr-scaleout
ScalingGroupId:
Ref: EssScalingGroup
ScalingRuleType: SimpleScalingRule
AdjustmentType: QuantityChangeInCapacity
AdjustmentValue: 1
Cooldown: 60
EssScheduledTask:
Type: 'ALIYUN::ESS::ScheduledTask'
Properties:
ScheduledTaskName:
Fn::Sub: ${CommonName}-scaleout
LaunchTime:
Ref: ScalingTime
ScheduledAction:
Fn::Sub: '${EssScalingRule.ScalingRuleAri}'
LaunchExpirationTime: 10
Outputs:
WebUrl:
Description:
zh-cn: Web 访问地址。
en: The Addresses of Web.
Value:
'Fn::Sub': 'http://${Alb.DNSName}'
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- InstanceType1
- ZoneId1
- InstanceType2
- ZoneId2
- InstancePassword
- ScalingTime
TemplateTags:
- acs:technical-solution:high-availability-architecture:通过ALB+ESS提升应用的可用性-tech_solu_117
Hidden:
- CommonName
Loading