forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhighly-available-blog-site-on-the-cloud.yml
411 lines (405 loc) · 11.2 KB
/
highly-available-blog-site-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
409
410
411
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Highly available blog site on the cloud.
zh-cn: 云上高可用博客网站。
Parameters:
EcsInstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
Zone1:
Type: String
Label:
en: VSwitch Availability Zone1
zh-cn: 交换机可用区1
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
Zone2:
Type: String
Label:
en: VSwitch Availability Zone2
zh-cn: 交换机可用区2
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
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'
AllowedPattern: '^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$'
MinLength: 8
MaxLength: 30
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.x4.large
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, Length 8-30, must contain three(Capital
letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
Special symbol in)
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'
AllowedPattern: '^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$'
MinLength: 8
MaxLength: 30
NoEcho: true
BucketName:
Type: String
Label:
en: OSS Bucket Name
zh-cn: Oss存储空间名称
Description:
en: >-
The name must be 3 to 63 bytes in length, The name must start and end
with a lowercase letter or digit.The name can contain only lowercase
letters, digits, and hyphens (-).;<br><b>note:<font color='blue'>A
bucket name must be globally unique within OSS. Bucket names cannot be
changed after the bucket is created.</b></font>
zh-cn: >-
长度为3~63个字符,必须以小写字母或数字开头和结尾,可以包含小写字母、数字和连字符(-);<br><b>注:<font
color='blue'>需要全网唯一性,已经存在的不能在创建。</b></font>
Default: image-example-test
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::InstanceGroup'
Properties:
ZoneId:
Ref: Zone1
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch1
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7_6
IoOptimized: optimized
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
InstanceName:
'Fn::Sub': '${CommonName}_ecs1'
EcsInstanceGroup2:
Type: 'ALIYUN::ECS::InstanceGroup'
Properties:
ZoneId:
Ref: Zone2
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch2
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7_6
IoOptimized: optimized
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
InstanceName:
'Fn::Sub': '${CommonName}_ecs2'
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
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
PolarDBCluster:
Type: 'ALIYUN::POLARDB::DBCluster'
Properties:
ZoneId:
Ref: Zone1
VpcId:
Ref: EcsVpc
VSwitchId:
Ref: EcsVSwitch1
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
OssBucket:
Type: 'ALIYUN::OSS::Bucket'
Properties:
BucketName:
Ref: BucketName
AccessControl: public-read
StorageClass: Standard
OpenCdnService:
Type: 'ALIYUN::ROS::AutoEnableService'
Properties:
ServiceName: DCDN
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:
- EcsInstanceType
- InstancePassword
Label:
default:
en: Instance
zh-cn: ECS实例配置
- Parameters:
- PolarDBName
- DBNodeClass
- PolarDBAccountName
- PolarDBPassword
Label:
default:
en: PolarDB Information
zh-cn: PolarDB配置
- Parameters:
- BucketName
Label:
default:
en: OSS
zh-cn: OSS 配置
- Parameters:
- Zone1
- Zone2
Label:
default:
en: Availability Zone
zh-cn: 可用区配置
TemplateTags:
- 'acs:technical-solution:high-availability-architecture:云上高可用博客网站'
Hidden:
- CommonName