forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
e-commerce-business-and-db-on-the-cloud.yml
578 lines (578 loc) · 18.8 KB
/
e-commerce-business-and-db-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
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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 电商业务及数据库上云。
en: E-commerce business and database on the cloud.
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- InstanceType
- SystemDiskCategory
- ECS_ZoneId_1
- ECS_ZoneId_2
- Password
Label:
default: ECS
- Parameters:
- DBInstanceClass
- RDS_ZoneId_1
- RDS_ZoneId_2
- DBPassword
Label:
default: RDS
- Parameters:
- LoadBalancerSpec
- SLB_ZoneId_1
Label:
default: SLB
TemplateTags:
- acs:technical-solution:network:ECS:电商行业业务及数据库上云
Parameters:
ECS_ZoneId_1:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: ECS可用区A
en: Availability Zone A of ECS
Description:
en: An availability zone to create for the ECS instance, <font color='red'><b>ensure that the current region has
at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建ECS实例的可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
ECS_ZoneId_2:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: ECS可用区B
en: Availability Zone B of ECS
Description:
en: An availability zone to create for the ECS instance, <font color='red'><b>ensure that the current region has
at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建ECS实例的可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
RDS_ZoneId_1:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: RDS主可用区
en: Master availability zone
Description:
en: The master availability zone to create for the RDS instance, <font color='red'><b>ensure that the current
region has at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建RDS实例的主可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
RDS_ZoneId_2:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: RDS备可用区
en: Slave availability zone
Description:
en: The slave availability zone to create for the RDS instance, <font color='red'><b>ensure that the current
region has at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建RDS实例的备可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
InstanceType:
Type: String
Label:
en: ECS Instance Type
zh-cn: ECS实例规格
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AllowedPattern: 'ecs.u1.*'
SystemDiskCategory:
Type: String
Default: cloud_essd
Label:
en: System disk type
zh-cn: 系统盘类型
Password:
Type: String
Label:
en: ECS instance password
zh-cn: ECS实例密码
Description:
en: 'Length 8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-='
zh-cn: 长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
ConstraintDescription:
en: '8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-='
zh-cn: 8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
MinLength: 8
MaxLength: 32
NoEcho: true
DBInstanceClass:
Type: String
Label:
en: Specifications
zh-cn: 规格
Description:
en: 'Select the instance specification based on the type of database engine
and the available area support;<br>see detail: <a href=''https://www.alibabacloud.com/help/doc-detail/26312.html''
target=''_blank''><b><font color=''blue''>Instance specification sheet</font></b></a>'
zh-cn: 根据数据库引擎的类型和可用的区域支持选择实例规格;<br>请参见详细信息:<a href='https://help.aliyun.com/document_detail/26312.html'
target='_blank'><b><font color='blue'>实例规格表</font></b></a>
Default: rds.mysql.s2.large
DBPassword:
Type: String
Label:
en: Database password
zh-cn: 数据库密码
Description:
en: 'Length 8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-= <br>It applies to both the password of the self-built database on ECS and
the password of RDS.'
zh-cn: 长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)<br>同时适用于ECS上自建数据库的密码与RDS的密码。
ConstraintDescription:
en: '8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-='
zh-cn: 8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
MinLength: 8
MaxLength: 32
NoEcho: true
LoadBalancerSpec:
Type: String
Label:
en: Load balancer instance specification
zh-cn: 负载均衡实例规格
Default: slb.s1.small
AssociationProperty: ALIYUN::SLB::Instance::InstanceType
SLB_ZoneId_1:
Type: String
AssociationProperty: ALIYUN::NLB::Zone::ZoneId
Label:
zh-cn: SLB主可用区
en: Master availability zone
Description:
en: The master availability zone to create for the SLB instance, <font color='red'><b>ensure that the current
region has at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建SLB实例的主可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
VpcName: E_Commerce_Vpc
CidrBlock: 192.168.0.0/16
ECS_Vsw_1:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ECS_ZoneId_1
CidrBlock: 192.168.0.0/24
ECS_Vsw_2:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ECS_ZoneId_2
CidrBlock: 192.168.1.0/24
SLB_Vsw_1:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: SLB_ZoneId_1
CidrBlock: 192.168.2.0/24
RDS_Vsw_1:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: RDS_ZoneId_1
CidrBlock: 192.168.3.0/24
RDS_Vsw_2:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: RDS_ZoneId_2
CidrBlock: 192.168.4.0/24
ECommerceSg:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 22/22
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 443/443
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 3389/3389
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: icmp
NicType: intranet
WordpressSg:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 22/22
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 443/443
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 3306/3306
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: icmp
NicType: intranet
DsDemoEcs_0:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: ECommerceSg
VSwitchId:
Ref: ECS_Vsw_1
InstanceName: ecs-ds-demo-01
ZoneId:
Ref: ECS_ZoneId_1
InstanceChargeType: PostPaid
InstanceType:
Ref: InstanceType
ImageId: centos
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize: 40
AllocatePublicIP: false
Password:
Ref: Password
DsDemoEcs_1:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: ECommerceSg
VSwitchId:
Ref: ECS_Vsw_2
InstanceName: ecs-ds-demo-02
ZoneId:
Ref: ECS_ZoneId_2
InstanceChargeType: PostPaid
InstanceType:
Ref: InstanceType
ImageId: centos
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize: 40
AllocatePublicIP: false
Password:
Ref: Password
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
LoadBalancerSpec:
Ref: LoadBalancerSpec
VpcId:
Ref: Vpc
VSwitchId:
Ref: SLB_Vsw_1
LoadBalancerName: slb-ds-demo
MasterZoneId:
Ref: SLB_ZoneId_1
SlbListener:
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
SlbBackendServerAttachment:
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
- Ref: DsDemoEcs_0
- Ref: DsDemoEcs_1
BackendServerWeightList:
- 100
- 100
LoadBalancerId:
Ref: Slb
WordpressDemoEcs:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: WordpressSg
VSwitchId:
Ref: ECS_Vsw_2
InstanceName: ecs-demo-wordpress
ZoneId:
Ref: ECS_ZoneId_2
InstanceChargeType: PostPaid
InstanceType:
Ref: InstanceType
ImageId: centos
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize: 40
AllocatePublicIP: false
Password:
Ref: Password
Eip_0:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 2
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
Eip_1:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 2
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
VpcEipAssociation_0:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: Slb
AllocationId:
Ref: Eip_0
VpcEipAssociation_1:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: WordpressDemoEcs
AllocationId:
Ref: Eip_1
InstallMysqlRunCommand:
Type: ALIYUN::ECS::RunCommand
DependsOn:
- VpcEipAssociation_1
Properties:
Sync: true
Type: RunShellScript
Timeout: 600
InstanceIds:
- Ref: WordpressDemoEcs
CommandContent:
Fn::Sub:
- |-
#!/bin/bash
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server -y
systemctl start mysqld
# 生成MySQL root用户,设置密码
MYSQL_PASSWD="${RootPwd}"
service mysqld start
yum install expect -y
echo '#!/usr/bin/expect' > dbroot.sh
echo set timeout 60 >> dbroot.sh
echo 'set password [lindex $argv 0]' >> dbroot.sh
echo spawn mysql_secure_installation >> dbroot.sh
echo expect { >> dbroot.sh
echo '"Press y|Y for Yes" { send "Y\r"; exp_continue}' >> dbroot.sh
echo '"password:" { send "${RootPwd}\r"; exp_continue}' >> dbroot.sh
echo '"Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:" { send "0\r"; exp_continue}' >> dbroot.sh
echo '"Cleaning up" { send "\r"}' >> dbroot.sh
echo } >> dbroot.sh
echo interact >> dbroot.sh
chmod +x dbroot.sh
./dbroot.sh
# 生成DTS用户
echo 'create database ${DtsDbName};' > setup.mysql
echo 'create user "${DtsUserName}" identified by "${DtsUserPwd}";' >> setup.mysql
echo 'GRANT ALL ON *.* TO "${DtsUserName}"@"%";' >> setup.mysql
echo 'flush privileges;' >> setup.mysql
chmod +x setup.mysql
mysql -uroot -p${RootPwd} < setup.mysql
# 添加测试数据
echo 'use ${DtsDbName}' > setup_data.mysql
echo 'CREATE TABLE ${DtsTableName} ( ' >> setup_data.mysql
echo 'buyer_id varchar(32) DEFAULT NULL, ' >> setup_data.mysql
echo 'buyer_prov varchar(32) DEFAULT NULL, ' >> setup_data.mysql
echo 'gender varchar(32) DEFAULT NULL, ' >> setup_data.mysql
echo 'age_range varchar(32) DEFAULT NULL, ' >> setup_data.mysql
echo 'zodiac varchar(32) DEFAULT NULL ' >> setup_data.mysql
echo ') ENGINE=InnoDB DEFAULT CHARSET=utf8;' >> setup_data.mysql
echo 'insert into ${DtsTableName} ( buyer_id, buyer_prov, gender, age_range, zodiac ) values' >> setup_data.mysql
echo '("0001","A","Male","20-30" ,"by"),' >> setup_data.mysql
echo '("0002","B","Male","20-30" ,"by"),' >> setup_data.mysql
echo '("0003","C","Female","30-40" ,"by"),' >> setup_data.mysql
echo '("0004","D","Male","20-30" ,"by"),' >> setup_data.mysql
echo '("0005","E","Male","20-30" ,"by"),' >> setup_data.mysql
echo '("0006","F","Female","20-30" ,"by"),' >> setup_data.mysql
echo '("0007","G","Female","10-20" ,"by"),' >> setup_data.mysql
echo '("0008","H","Female","20-30" ,"by"),' >> setup_data.mysql
echo '("0009","I","Male","20-30" ,"by"),' >> setup_data.mysql
echo '("0010","J","Male","20-30" ,"by");' >> setup_data.mysql
chmod +x setup_data.mysql
mysql -uroot -p${RootPwd} < setup_data.mysql
- RootPwd:
Ref: DBPassword
DtsUserName: dts_user
DtsUserPwd:
Ref: DBPassword
DtsDbName: wordpress
DtsTableName: demo_table
RdsDBInstance:
Type: ALIYUN::RDS::DBInstance
Properties:
Category: HighAvailability
DBInstanceStorageType: local_ssd
ZoneId:
Ref: RDS_ZoneId_1
SlaveZoneIds:
- Ref: RDS_ZoneId_2
VpcId:
Ref: Vpc
VSwitchId:
Fn::Join:
- ','
- - Ref: RDS_Vsw_1
- Ref: RDS_Vsw_2
DBInstanceClass:
Ref: DBInstanceClass
DBInstanceStorage: 100
DBMappings:
- CharacterSetName: utf8
DBName: wordpress_new
Engine: MySQL
EngineVersion: '5.6'
MasterUserPassword:
Ref: DBPassword
MasterUserType: Super
MasterUsername: myuser
SecurityIPList: 192.168.0.0/16
SecurityGroupId:
Ref: ECommerceSg
DtsInstance:
Type: ALIYUN::DTS::Instance
Properties:
JobId:
Fn::GetAtt:
- MigrationJob
- DtsJobId
InstanceClass: small
PayType: PostPaid
Type: MIGRATION
SourceRegion:
Ref: ALIYUN::Region
DestinationRegion:
Ref: ALIYUN::Region
SourceEndpointEngineName: MySQL
DestinationEndpointEngineName: MySQL
MigrationJob:
Type: ALIYUN::DTS::MigrationJob2
Properties:
DtsJobName: e-commerce_migration
SourceEndpoint:
InstanceType: ECS
InstanceID:
Ref: WordpressDemoEcs
EngineName: MYSQL
Port: '3306'
Region:
Ref: ALIYUN::Region
UserName: dts_user
Password:
Ref: DBPassword
DestinationEndpoint:
InstanceType: RDS
InstanceID:
Ref: RdsDBInstance
EngineName: MYSQL
Region:
Ref: ALIYUN::Region
UserName: myuser
Password:
Ref: DBPassword
StructureInitialization: true
DataInitialization: true
DataSynchronization: true
DbList:
wordpress:
name: wordpress_new
all: true
DependsOn:
- RdsDBInstance
- InstallMysqlRunCommand
Outputs:
EcsLoginAddress:
Description:
zh-cn: ECS登陆地址。
en: Ecs login address.
Value:
Fn::Sub:
- https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs®ionId=${Region}&instanceId=${InstanceId}
- InstanceId:
Ref: WordpressDemoEcs
Region:
Ref: ALIYUN::Region
DBInstanceId:
Description:
zh-cn: RDS实例ID。
en: RDS instance id.
Value:
Fn::GetAtt:
- RdsDBInstance
- DBInstanceId
DtsJobId:
Description:
zh-cn: DTS任务id。
en: DTS job id.
Value:
Fn::GetAtt:
- DtsInstance
- JobId