-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathelastic-application-with-ess.yml
580 lines (580 loc) · 14.2 KB
/
elastic-application-with-ess.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建双可用区ALB负载均衡,搭配ESS自动扩缩容,确保应用高可用性,含安全组与自动安装nginx配置。
en: Create a dual-Availability-Zone ALB (Application Load Balancer) along with ESS
(Elastic Scale Service) for automatic scaling, ensuring high application availability,
inclusive of security groups and automated installation of nginx configurations.
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
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.
ScalingTime2:
Type: String
Label:
en: Automatic scaling execution time
zh-cn: 自动缩容执行时间
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'YYYY-MM-DDThh:mmZ'
Description:
zh-cn: 建议选择扩容时间之后的 5-10 分钟观察缩容效果。
en: It is recommended to observe the shrinkage effect 5-10 minutes after the expansion time.
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
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
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-rule
ScalingGroupId:
Ref: EssScalingGroup
ScalingRuleType: SimpleScalingRule
AdjustmentType: QuantityChangeInCapacity
AdjustmentValue: 1
Cooldown: 60
EssScalingRule2:
Type: 'ALIYUN::ESS::ScalingRule'
Properties:
ScalingRuleName:
Fn::Sub: ${CommonName}-asr-rule2
ScalingGroupId:
Ref: EssScalingGroup
ScalingRuleType: SimpleScalingRule
AdjustmentType: QuantityChangeInCapacity
AdjustmentValue: -1
Cooldown: 60
EssScheduledTask:
Type: 'ALIYUN::ESS::ScheduledTask'
Properties:
ScheduledTaskName:
Fn::Sub: ${CommonName}-task1-${ALIYUN::StackId}
LaunchTime:
Ref: ScalingTime
ScheduledAction:
Fn::Sub: '${EssScalingRule.ScalingRuleAri}'
LaunchExpirationTime: 10
EssScheduledTask2:
Type: 'ALIYUN::ESS::ScheduledTask'
Properties:
ScheduledTaskName:
Fn::Sub: ${CommonName}-task2-${ALIYUN::StackId}
LaunchTime:
Ref: ScalingTime2
ScheduledAction:
Fn::Sub: '${EssScalingRule2.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:
- ZoneId1
- ZoneId2
- InstanceType1
- InstanceType2
- InstancePassword
- ScalingTime
- ScalingTime2
TemplateTags:
- acs:technical-solution:high-availability-architecture:通过ALB+ESS提升应用的可用性-tech_solu_117
Hidden:
- CommonName
ALIYUN::ROS::Composer:
1f68d961:
Rect:
- 1074
- 555
- 40
- 100
- 1
- 0
ResT: Composer::ROSParameter::AlibabaCloud
87dd573c:
Parent: 1f68d961
Rect:
- 1029
- 474
- 60
- 150
- 2
- 0
ResT: Composer::ROSParameter::Region
058060ce:
Res:
- Vpc
Parent: 87dd573c
Rect:
- 860
- 403
- 80
- 200
- 3
- 0
2346e5ab:
Res:
- EssScheduledTask
Parent: 87dd573c
Rect:
- 40
- 40
- 993
- 259
- 3
- 0
bbbd9f80:
Res:
- EssScheduledTask2
Parent: 87dd573c
Rect:
- 40
- 40
- 993
- 435
- 3
- 0
0bbd84a8:
Res:
- ZoneId1
Parent: 058060ce
Rect:
- 329
- 261
- 100
- 259
- 4
- 0
ResT: Composer::ROSParameter::Zone
23522cea:
Res:
- ZoneId2
Parent: 058060ce
Rect:
- 340
- 278
- 560
- 250
- 4
- 0
ResT: Composer::ROSParameter::Zone
7f6b7ed0:
Res:
- Alb
- AlbListener
Parent: 058060ce
Rect:
- 40
- 40
- 807
- 383
- 4
- 0
9caf6e66:
Res:
- VSwitch1
Parent: 0bbd84a8
Rect:
- 264
- 197
- 120
- 303
- 5
- 0
c38d7f55:
Res:
- VSwitch2
Parent: 23522cea
Rect:
- 192
- 198
- 580
- 300
- 5
- 0
'83e77572':
Res:
- SecurityGroup
Parent: 058060ce
Rect:
- 600
- 143
- 157
- 332
- 15
- 0
72cb00a9:
Res:
- AlbServerGroup
- AlbBackendServerAttachment
Parent: 058060ce
Rect:
- 515
- 99
- 200
- 353
- 15
- 0
8708add3:
Res:
- EssScalingGroup
- EssServerGroupAttachment
- EssScalingConfiguration
- EssScalingGroupEnable
- EssScalingRule
- EssScalingRule2
Parent: 058060ce
Rect:
- 75
- 40
- 420
- 543
- 15
- 0
50e7124f:
Res:
- EcsInstance1
Parent: 9caf6e66
Rect:
- 40
- 40
- 261
- 380
- 16
- 0
Layer:
- '83e77572'
- 72cb00a9
0eedf192:
Res:
- EcsInstance2
Parent: c38d7f55
Rect:
- 40
- 40
- 631
- 380
- 16
- 0
Layer:
- '83e77572'
- 72cb00a9
b1729241:
Parent: 058060ce
Edge:
- 7f6b7ed0
- 72cb00a9
Line: 0:0:0:gray:0
16f9f8a7:
Parent: 058060ce
Edge:
- 8708add3
- 72cb00a9
Line: 0:0:0:gray:0
727db6cf:
Parent: 058060ce
Edge:
- 8708add3
- '83e77572'
Line: 0:0:0:gray:0