-
Notifications
You must be signed in to change notification settings - Fork 35
/
classic-architecture-on-the-cloud.yml
408 lines (402 loc) · 11.7 KB
/
classic-architecture-on-the-cloud.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建双可用区云上架构,含VPC、ECS实例、PolarDB数据库、ALB负载均衡,自动部署WordPress。
en: Establish a dual-Availability Zone cloud architecture comprising a Virtual Private
Cloud (VPC), Elastic Compute Service (ECS) instances, PolarDB database, and Application
Load Balancer (ALB), with automated deployment of WordPress.
Parameters:
EcsInstanceType1:
Type: String
Label:
en: Instance Type for Availability Zone1
zh-cn: 可用区1对应实例类型
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SpotStrategy: SpotAsPriceGo
ZoneId: ${Zone1}
SystemDiskCategory: cloud_essd
Description:
en: >-
If no available specifications are displayed, please select Modify
Availability Zone and try again.
zh-cn: 如果没有可用规格显示,请选择修改可用区后重试。
Default: ecs.s6-c1m1.small
EcsInstanceType2:
Type: String
Label:
en: Instance Type for Availability Zone2
zh-cn: 可用区2对应实例类型
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SpotStrategy: SpotAsPriceGo
ZoneId: ${Zone2}
SystemDiskCategory: cloud_essd
Description:
en: >-
If no available specifications are displayed, please select Modify
Availability Zone and try again.
zh-cn: 如果没有可用规格显示,请选择修改可用区后重试。
Default: ecs.s6-c1m1.small
Zone1:
Type: String
Label:
en: VSwitch Availability Zone1
zh-cn: 交换机可用区1
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- Zone2
Zone2:
Type: String
Label:
en: VSwitch Availability Zone2
zh-cn: 交换机可用区2
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
AssociationPropertyMetadata:
AutoSelectFirst: true
ExclusiveTo:
- Zone1
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
Description:
en: >-
Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
symbol in)
zh-cn: >-
服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
中的特殊符号),不能以特殊字符开头。
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'
NoEcho: true
PolarDBName:
Type: String
Label:
en: PolarDB Name
zh-cn: 数据库名称
Default: wordpress
DBNodeClass:
Type: String
Label:
en: DBNodeClass
zh-cn: PolarDB集群规格
Default: polar.mysql.g2.medium
PolarDBAccountName:
Type: String
Label:
en: Account Name of PolarDB
zh-cn: 数据库登录名
Default: wordpress
PolarDBPassword:
Type: String
Label:
en: PolarDB Login Password
zh-cn: 数据库登录密码
Description:
en: >-
Software login password, There are three types of uppercase and lowercase letters,
numbers, and special characters, with a length of 8~32 characters; the special characters are !@#$%^&*()_+-=
zh-cn: 软件登录密码,大小写字母、数字、特殊字符占三种,长度为8~32个字符,不能以特殊字符开头,特殊字符为!@#$%^&*()_+-=
ConstraintDescription:
en: >-
There are three types of uppercase and lowercase letters, numbers, and special characters,
with a length of 8~32 characters; the special characters are !@#$%^&*()_+-=
zh-cn: '大小写字母、数字、特殊字符占三种,长度为8~32个字符,不能以特殊字符开头,特殊字符为!@#$%^&*()_+-='
AllowedPattern: '^[a-zA-Z](?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*()_+\-=])[A-Za-z\d!@#$%^&*()_+\-=]{7,31}$'
NoEcho: true
CommonName:
Type: String
Default: high-availability
Resources:
EcsVpc:
Type: 'ALIYUN::ECS::VPC'
Properties:
VpcName:
'Fn::Sub': '${CommonName}_vpc'
CidrBlock: 192.168.0.0/16
EcsVSwitch1:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
ZoneId:
Ref: Zone1
VpcId:
Ref: EcsVpc
VSwitchName:
'Fn::Sub': '${CommonName}_vsw_001'
CidrBlock: 192.168.1.0/24
EcsVSwitch2:
Type: 'ALIYUN::ECS::VSwitch'
Properties:
ZoneId:
Ref: Zone2
VpcId:
Ref: EcsVpc
VSwitchName:
'Fn::Sub': '${CommonName}_vsw_002'
CidrBlock: 192.168.2.0/24
EcsSecurityGroup:
Type: 'ALIYUN::ECS::SecurityGroup'
Properties:
VpcId:
Ref: EcsVpc
SecurityGroupName:
'Fn::Sub': '${CommonName}_sg'
SecurityGroupIngress:
- PortRange: 3306/3306
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
- PortRange: 22/22
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
- PortRange: 443/443
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
EcsInstanceGroup1:
Type: 'ALIYUN::ECS::Instance'
Properties:
ZoneId:
Ref: Zone1
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch1
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7_9
IoOptimized: optimized
SystemDiskSize: 20
InstanceType:
Ref: EcsInstanceType1
Password:
Ref: InstancePassword
InstanceName:
'Fn::Sub': '${CommonName}_ecs1'
SpotStrategy: SpotAsPriceGo
SystemDiskCategory: cloud_essd
EcsInstanceGroup2:
Type: 'ALIYUN::ECS::Instance'
Properties:
ZoneId:
Ref: Zone2
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch2
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7_9
IoOptimized: optimized
SystemDiskSize: 20
InstanceType:
Ref: EcsInstanceType2
Password:
Ref: InstancePassword
InstanceName:
'Fn::Sub': '${CommonName}_ecs2'
SpotStrategy: SpotAsPriceGo
SystemDiskCategory: cloud_essd
InstanceRunCommand:
Type: 'ALIYUN::ECS::RunCommand'
Properties:
InstanceIds:
- Ref: EcsInstanceGroup1
- Ref: EcsInstanceGroup2
Sync: true
Type: RunShellScript
Timeout: '300'
CommandContent:
'Fn::Sub': >-
#!/bin/bash
yum install docker -y
systemctl start docker
systemctl enable docker.service
docker pull docker.io/library/wordpress:5.6
mkdir /wordpress
docker run --name my-blog --restart=always -v /wordpress:/var/www/html
-p 80:80 -d --env
WORDPRESS_DB_HOST=${PolarDBCluster.ClusterConnectionString} --env
WORDPRESS_DB_USER=${PolarDBAccountName} --env
WORDPRESS_DB_PASSWORD=${PolarDBPassword} --env
WORDPRESS_DB_NAME=${PolarDBName} wordpress:5.6
PolarDBCluster:
Type: 'ALIYUN::POLARDB::DBCluster'
Properties:
ZoneId:
Ref: Zone2
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch2
SecurityGroupIds:
- Ref: EcsSecurityGroup
DBType: MySQL
ClusterNetworkType: VPC
DBVersion: '8.0'
CreationOption: Normal
DBNodeClass:
Ref: DBNodeClass
SecurityIPList: 192.168.0.0/16
PayType: Postpaid
PolarDBInstance:
Type: 'ALIYUN::POLARDB::DBInstance'
Properties:
DBClusterId:
Ref: PolarDBCluster
CharacterSetName: utf8mb4
DBName:
Ref: PolarDBName
PolarDBAccount:
Type: 'ALIYUN::POLARDB::Account'
Properties:
DBClusterId:
Ref: PolarDBCluster
AccountName:
Ref: PolarDBAccountName
AccountPrivilege: ReadWrite
AccountType: Normal
AccountPassword:
Ref: PolarDBPassword
DBName:
Ref: PolarDBInstance
AlbLoadBalancer:
Type: 'ALIYUN::ALB::LoadBalancer'
Properties:
VpcId:
Ref: EcsVpc
LoadBalancerName:
'Fn::Sub': '${CommonName}_alb'
LoadBalancerEdition: Basic
LoadBalancerBillingConfig:
PayType: PostPay
AddressType: Internet
AddressAllocatedMode: Dynamic
ZoneMappings:
- ZoneId:
Ref: Zone1
VSwitchId:
Ref: EcsVSwitch1
- ZoneId:
Ref: Zone2
VSwitchId:
Ref: EcsVSwitch2
AlbServerGroup:
Type: 'ALIYUN::ALB::ServerGroup'
Properties:
VpcId:
Ref: EcsVpc
HealthCheckConfig:
HealthCheckEnabled: true
HealthCheckPath: /
HealthCheckCodes:
- http_2xx
- http_3xx
HealthCheckProtocol: HTTP
ServerGroupName:
'Fn::Sub': '${CommonName}_server_group'
StickySessionConfig:
StickySessionEnabled: false
ServerAttachment:
Type: 'ALIYUN::ALB::BackendServerAttachment'
Properties:
ServerGroupId:
Ref: AlbServerGroup
Servers:
- ServerType: Ecs
ServerId:
Ref: EcsInstanceGroup1
Port: 80
Weight: 100
- ServerType: Ecs
ServerId:
Ref: EcsInstanceGroup2
Port: 80
Weight: 100
AlbListener:
Type: 'ALIYUN::ALB::Listener'
Properties:
ListenerPort: 80
DefaultActions:
- Type: ForwardGroup
ForwardGroupConfig:
ServerGroupTuples:
- ServerGroupId:
Ref: AlbServerGroup
LoadBalancerId:
Ref: AlbLoadBalancer
ListenerProtocol: HTTP
Outputs:
WordPressUrl:
Description:
en: The url of WordPress.
zh-cn: WordPress 访问地址。
Value:
'Fn::Sub':
- 'http://${AlbDnsName}'
- AlbDnsName:
'Fn::GetAtt':
- AlbLoadBalancer
- DNSName
Metadata:
'ALIYUN::ROS::Interface':
ParameterGroups:
- Parameters:
- Zone1
- Zone2
Label:
default:
en: Availability Zone
zh-cn: 可用区配置
- Parameters:
- EcsInstanceType1
- EcsInstanceType2
- InstancePassword
Label:
default:
en: Instance
zh-cn: ECS实例配置
- Parameters:
- PolarDBName
- DBNodeClass
- PolarDBAccountName
- PolarDBPassword
Label:
default:
en: PolarDB Information
zh-cn: PolarDB配置
TemplateTags:
- >-
acs:technical-solution:high-availability-architecture:云上经典架构-tech_solu_07
Hidden:
- CommonName