forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic-highly-available-architecture.yml
746 lines (739 loc) · 17.7 KB
/
basic-highly-available-architecture.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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建双可用区VPC环境,配备ECS实例、ALB负载均衡、RDS高可用数据库,自动部署应用与数据初始化,支持CDT服务。
en: Establish a dual-Availability-Zone VPC environment, equipped with ECS instances,
ALB for load balancing, and a high-availability RDS database. Facilitate automatic
application deployment and data initialization, with support for CDT services.
Parameters:
CommonName:
Type: String
Default: high-availability
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
DBUserName:
Type: String
ConstraintDescription:
en: >-
Consist of 2 to 32 characters of lowercase letters, underline.
Must begin with a letter and be end with an alphanumeric character
zh-cn: >-
由 2 到 32 个小写字母组成,支持小写字母、数字和下划线,以小写字母开头。
Label:
zh-cn: RDS数据库账号
en: RDS DB Username
Default: high_availability
AllowedPattern: '^[a-z][a-z0-9_]{0,31}$'
DBPassword:
NoEcho: true
Type: String
Description:
en: >-
RDS user password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
symbol in)
zh-cn: >-
数据库账号密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符号)
Label:
en: RDS Instance Password
zh-cn: RDS数据库密码
ConstraintDescription:
en: >-
Length 8-30, must contain three(Capital letters, lowercase letters,
numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: '长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符号)'
AssociationProperty: ALIYUN::RDS::Instance::AccountPassword
DBInstanceClass:
Type: String
Label:
en: RDS Instance Class
zh-cn: RDS实例规格
AssociationProperty: ALIYUN::RDS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId:
Ref: ZoneId
EngineVersion: '8.0'
DBInstanceStorageType: cloud_essd
Engine: MySQL
Category: HighAvailability
CommodityCode: bards
EnableCDT:
Type: Boolean
Label:
en: EnableCDT
zh-cn: 是否开通 CDT
Default: false
Conditions:
EnableCDT:
Fn::Equals:
- Ref: EnableCDT
- true
Resources:
AutoEnableCDT:
Type: 'ALIYUN::ROS::AutoEnableService'
Condition: EnableCDT
Properties:
ServiceName: CDT
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
VSwitch3:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.3.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-vsw
VSwitch4:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.4.0/24
ZoneId:
Ref: ZoneId2
VSwitchName:
Fn::Sub: ${CommonName}-vsw
VSwitch5:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.5.0/24
ZoneId:
Ref: ZoneId1
VSwitchName:
Fn::Sub: ${CommonName}-vsw
VSwitch6:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
VpcId:
Ref: Vpc
CidrBlock: 192.168.6.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: 5
Password:
Ref: InstancePassword
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: 5
Password:
Ref: InstancePassword
Alb:
Type: 'ALIYUN::ALB::LoadBalancer'
Properties:
LoadBalancerName:
Fn::Sub: ${CommonName}-alb
LoadBalancerEdition: Basic
VpcId:
Ref: Vpc
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
AddressAllocatedMode: Fixed
ZoneMappings:
- ZoneId:
Ref: ZoneId1
VSwitchId:
Ref: VSwitch3
- ZoneId:
Ref: ZoneId2
VSwitchId:
Ref: VSwitch4
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
RdsInstance:
Type: 'ALIYUN::RDS::DBInstance'
Properties:
DBInstanceClass:
Ref: DBInstanceClass
ZoneId:
Ref: ZoneId1
DBInstanceStorage: 40
Category: HighAvailability
DBInstanceStorageType: cloud_essd
VSwitchId:
Ref: VSwitch5
Engine: MySQL
VpcId:
Ref: Vpc
SlaveZoneIds:
- Auto
EngineVersion: '8.0'
SecurityIPList: '192.168.0.0/16'
MasterUsername:
Ref: DBUserName
MasterUserPassword:
Ref: DBPassword
MasterUserType: Super
RdsDatabase:
Type: ALIYUN::RDS::Database
Properties:
CharacterSetName: utf8mb4
DBInstanceId:
Ref: RdsInstance
DBName: high_availability
PrepareData:
Type: 'ALIYUN::ECS::RunCommand'
Properties:
InstanceIds:
- Ref: EcsInstance1
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
yum install -y mysql
mkdir /data
cat << "EOF" > /data/script.sql
-- script.sql
USE high_availability;
CREATE TABLE `todo_list` (
`id` bigint NOT NULL COMMENT 'id',
`title` varchar(128) NOT NULL COMMENT 'title',
`desc` text NOT NULL COMMENT 'description',
`status` varchar(128) NOT NULL COMMENT 'status 未开始、进行中、已完成、已取消',
`priority` varchar(128) NOT NULL COMMENT 'priority 高、中、低',
`expect_time` datetime COMMENT 'expect time',
`actual_completion_time` datetime COMMENT 'actual completion time',
`gmt_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'modified time',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
;
INSERT INTO todo_list
(id, title, `desc`, `status`, priority, expect_time)
value(1, "创建一个应用", "使用阿里云解决方案搭建一个应用", "进行中", "高", "2024-04-01 00:00:00")
EOF
mysql -h${RdsInstance.InnerConnectionString} -u${DBUserName} -p${DBPassword} < /data/script.sql
InstallApp:
Type: 'ALIYUN::ECS::RunCommand'
DependsOn: PrepareData
Properties:
InstanceIds:
- Ref: EcsInstance1
- Ref: EcsInstance2
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
sudo yum -y install java-1.8.0-openjdk-devel.x86_64
cat << EOF >> ~/.bash_profile
export APPLETS_RDS_ENDPOINT=${RdsInstance.InnerConnectionString}
export APPLETS_RDS_USER=${DBUserName}
export APPLETS_RDS_PASSWORD=${DBPassword}
export APPLETS_RDS_DB_NAME=high_availability
export APP_MANUAL_DEPLOY=false
EOF
source ~/.bash_profile
wget https://help-static-aliyun-doc.aliyuncs.com/tech-solution/cloud-demo-0.0.2.jar
nohup java -jar cloud-demo-0.0.2.jar > demo.log 2>&1 &
Outputs:
WebUrl:
Description:
zh-cn: Web 访问地址。
en: The Addresses of Web.
Value:
'Fn::Sub': 'http://${Alb.DNSName}'
Metadata:
ALIYUN::ROS::Composer:
'57315051':
Line: 0:0:0:gray:0
Edge:
- e49874cc
- 5be4ce24
Parent: ba3a88e4
ba3a88e4:
Res:
- Vpc
- Vpc
Parent: 204c26aa
Rect:
- 950
- 750
- 141
- -214
- 2
- 0
Label: Vpc
92c047d9:
Line: 0:0:0:gray:0
Edge:
- 42dc0331
- 51db45c6
Parent: ba3a88e4
51db45c6:
Res:
- EcsInstance1
- EcsInstance1
Layer:
- dde0166f
- 1d49f4a1
Parent: 5ef968f2
Rect:
- 40
- 40
- 455
- 241
- 15
- 0
Label: EcsInstance1
9b4f85db:
Res:
- ZoneId1
- ZoneId1
Parent: ba3a88e4
Rect:
- 323
- 313
- 284
- 124
- 3
- 0
ResT: Composer::ROSParameter::Zone
Label: ZoneId1
459537dd:
Line: 0:0:0:gray:0
Edge:
- 42dc0331
- 5be4ce24
Parent: ba3a88e4
e49874cc:
Res:
- AlbBackendServerAttachment
- AlbBackendServerAttachment
Parent: ba3a88e4
Rect:
- 40
- 40
- 607
- 27
- 3
- 0
Label: AlbBackendServerAttachment
8e3b0a2e:
Res:
- AlbListener
- AlbListener
Parent: f480735a
Rect:
- 40
- 40
- 607
- -104
- 4
- 0
Label: AlbListener
c0190ed5:
Res:
- AutoEnableCDT
- AutoEnableCDT
Parent: ba3a88e4
Rect:
- 40
- 40
- 201
- 358
- 3
- 0
Label: 开通云服务
1d49f4a1:
Res:
- AlbServerGroup
- AlbServerGroup
Parent: ba3a88e4
Rect:
- 474
- 99
- 393
- 221
- 14
- 0
Label: AlbServerGroup
c08b7eea:
Line: 0:0:0:gray:0
Edge:
- e49874cc
- 51db45c6
Parent: ba3a88e4
6f951f87:
Res:
- VSwitch2
- VSwitch2
Parent: 332b3a52
Rect:
- 246
- 257
- 691
- 164
- 4
- 0
Label: VSwitch2
42dc0331:
Res:
- InstallApp
- InstallApp
Parent: ba3a88e4
Rect:
- 40
- 40
- 607
- 470
- 3
- 0
Label: InstallApp
5be4ce24:
Res:
- EcsInstance2
- EcsInstance2
Layer:
- dde0166f
- 1d49f4a1
Parent: 6f951f87
Rect:
- 40
- 40
- 770
- 241
- 15
- 0
Label: EcsInstance2
ecade0ee:
Line: 0:0:0:gray:0
Edge:
- fbfedde2
- 51db45c6
Parent: ba3a88e4
dde0166f:
Res:
- SecurityGroup
- SecurityGroup
Parent: ba3a88e4
Rect:
- 539
- 138
- 366
- 198
- 12
- 0
Label: SecurityGroup
5517fa14:
Res:
- RdsDatabase
- RdsDatabase
Parent: ba3a88e4
Rect:
- 40
- 40
- 393
- 470
- 3
- 0
Label: RdsDatabase
5ef968f2:
Res:
- VSwitch1
- VSwitch1
Parent: 9b4f85db
Rect:
- 254
- 263
- 317
- 164
- 4
- 0
Label: VSwitch1
dc6661c0:
Res:
- RdsInstance
- RdsInstance
Parent: 5ef968f2
Rect:
- 40
- 40
- 393
- 358
- 5
- 0
Label: RdsInstance
fbfedde2:
Res:
- PrepareData
- PrepareData
Parent: ba3a88e4
Rect:
- 40
- 40
- 201
- 241
- 3
- 0
Label: PrepareData
f480735a:
Res:
- Alb
- Alb
Parent: ba3a88e4
Rect:
- 240
- 120
- 507
- -166
- 3
- 0
Label: Alb
332b3a52:
Res:
- ZoneId2
- ZoneId2
Parent: ba3a88e4
Rect:
- 325
- 316
- 655
- 127
- 3
- 0
ResT: Composer::ROSParameter::Zone
Label: ZoneId2
d5db02f6-c400-48a6-b6e4-76282e19268e:
Line: 0:1:0:#969696:0
Edge:
- f480735a
- e49874cc
Parent: ba3a88e4
1dbe85fe:
Line: 0:0:0:gray:0
Edge:
- 5517fa14
- dc6661c0
Parent: ba3a88e4
204c26aa:
Rect:
- 1029
- 811
- 100
- -254
- 1
- 0
ResT: Composer::ROSParameter::Region
Label: cn-hangzhou
ede91afe-625c-476a-98a6-fa7aa62854fb:
Line: 0:1:0:#969696:0
Edge:
- 51db45c6
- dc6661c0
Parent: 5ef968f2
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- ZoneId1
- ZoneId2
- InstanceType1
- InstanceType2
- InstancePassword
Label:
default:
zh-cn: ECS 配置
en: ECS Configuration
- Parameters:
- DBUserName
- DBPassword
- DBInstanceClass
Label:
default:
zh-cn: RDS 数据库配置
en: RDS Configuration
- Parameters:
- EnableCDT
Label:
default:
zh-cn: 其他配置
en: Other Configuration
TemplateTags:
- acs:technical-solution:high-availability-architecture:云上高可用架构-基础版-tech_solu_133
Hidden:
- CommonName