-
Notifications
You must be signed in to change notification settings - Fork 35
/
data-transmission-from-ECS-to-RDS.yml
312 lines (311 loc) · 10.2 KB
/
data-transmission-from-ECS-to-RDS.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建ECS与RDS,配置安全组与网络,部署WordPress及自建数据库,设置DTS同步用户,实现ECS自建数据库向RDS平滑迁移。
en: Create Elastic Compute Service (ECS) instances and Relational Database Service
(RDS) instances, configure security groups and networking, deploy WordPress along
with a self-built database, configure Data Transmission Service (DTS) to synchronize
users, and seamlessly migrate the self-built database on ECS to RDS.
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- EcsInstanceType
- InstancePassword
Label:
default: ECS
- Parameters:
- DBInstanceEngineAndVersion
- DBInstanceClass
- DBUserName
- DBPassword
Label:
default: RDS
TemplateTags:
- acs:technical-solution:database:网站数据库平滑迁移上云-tech_solu_04
Parameters:
Zone:
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Type: String
Description:
zh-cn: 用于创建ECS和RDS的可用区。
en: Availability zone.
Label:
zh-cn: 可用区
en: Availability Zone.
EcsInstanceType:
Type: String
Description:
zh-cn: 运行Wordpress及自建数据库的ECS实例类型。
en: ECS instance which runs WordPress and on-premises database.
Label:
zh-cn: ECS实例类型
en: ECS instance type.
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
SystemDiskCategory: cloud_essd
InstanceChargeType: PostPaid
ZoneId: ${Zone}
Default: ecs.e-c1m1.large
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:
zh-cn: 实例密码
en: Instance Password
ConstraintDescription: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)。
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
DBInstanceEngineAndVersion:
Type: String
Description:
zh-cn: 数据库引擎类型及版本,默认为MySQL 8.0
en: 'Database instance engine type and version, default: MySQL 8.0'
Label:
zh-cn: 引擎类型及版本
en: Engine And Version
Default: MySQL 8.0
AllowedValues:
- MySQL 8.0
DBInstanceClass:
Type: String
Description: '在模拟数据迁移体验中,您可以选择最小规格的数据库实例作为迁移目标实例,以减少成本。在生产环境中选择迁移目标实例,需要确保其规格满足您的业务需求。关于RDS实例规格详情,请参考:<a href="https://help.aliyun.com/zh/rds/apsaradb-rds-for-mysql/specifications-2" target="blank">云数据库RDS MySQL产品规格。</a>'
Label:
en: Target RDS Instance Class
zh-cn: 迁移目标RDS实例规格
AssociationProperty: ALIYUN::RDS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId:
Ref: Zone
EngineVersion: '8.0'
DBInstanceStorageType: cloud_essd
Engine: MySQL
Category: Basic
CommodityCode: bards
Default: mysql.n2e.small.1
DBUserName:
Type: String
Description:
en: Username of RDS database
zh-cn: RDS数据库账号
ConstraintDescription:
en: Consist of 2 to 16 characters of lowercase letters, underline. Must begin with a letter and be end with an alphanumeric character
zh-cn: 由 2 到 16 个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾
Label:
zh-cn: RDS数据库账号
en: RDS DB Username
Default: dbuser
MaxLength: 16
MinLength: 2
DBPassword:
Type: String
Description:
en: RDS database password, consisting of letters, numbers, and underline(_), is 8 to 32 characters long
zh-cn: RDS数据库密码,由字母、数字、下划线(_)组成,长度为8~32个字符
ConstraintDescription:
en: '[8, 32] characters consist of alphanumeric characters, hyphen and underline'
zh-cn: '[8, 32] 个字符由字母数字字符、连字符和下划线组成'
Label:
zh-cn: RDS数据库密码
en: RDS DB Password
MaxLength: 32
MinLength: 8
NoEcho: true
Resources:
RosWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: RosWaitConditionHandle
Timeout: 3600
RosWaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
CidrBlock: 192.168.0.0/24
ZoneId:
Ref: Zone
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
VpcName: database-migration-test
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName: SG-DTS-GROUP-20220101
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
Database:
Type: ALIYUN::RDS::DBInstance
Properties:
DBInstanceClass:
Ref: DBInstanceClass
ZoneId:
Ref: Zone
DBInstanceDescription: Test for database migration
DBInstanceStorage: 20
Category: Basic
DBInstanceStorageType: cloud_essd
VSwitchId:
Ref: VSwitch
Engine: MySQL
VpcId:
Ref: Vpc
SlaveZoneIds:
- Auto
EngineVersion: '8.0'
SecurityIPList:
Fn::GetAtt:
- WebServer
- PrivateIp
MasterUsername:
Ref: DBUserName
MasterUserPassword:
Ref: DBPassword
MasterUserType: Super
SecurityGroupIngress:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SourceCidrIp: 0.0.0.0/0
SecurityGroupId:
Ref: SecurityGroup
IpProtocol: all
PortRange: '-1/-1'
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
IoOptimized: optimized
ImageId: aliyun_3_x64_20G_alibase_
SecurityGroupId:
Ref: SecurityGroup
Password:
Ref: InstancePassword
InternetMaxBandwidthOut: 80
UserData:
Fn::Replace:
- ros-notify:
Fn::GetAtt:
- RosWaitConditionHandle
- CurlCli
- Fn::Join:
- ''
- - '#!/bin/sh'
- |+
- |
DatabaseUser='wordpressuser'
- |
DatabasePwd='password'
- |
DatabaseName='wordpressdb'
- |
DatabaseHost='localhost'
- |
yum update -y
- |
yum install -y unzip zip
- |
yum install -y mysql-server
- |
systemctl start mysqld
- |
systemctl enable mysqld
- |
mysql -e "CREATE DATABASE wordpressdb;"
- |
mysql -e "CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';"
- |
mysql -e "GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost';"
- |
mysql -e "FLUSH PRIVILEGES;"
- |
mysql -e "CREATE USER dtssync1 IDENTIFIED BY 'P@ssw0rd';"
- |
mysql -e "GRANT ALL ON *.* TO 'dtssync1'@'%';"
- |
mysql -e "FLUSH PRIVILEGES;"
- |
mysql -e "SET GLOBAL binlog_format = 'ROW';"
- |
yum install -y nginx
- |
systemctl start nginx
- |
systemctl enable nginx
- |
yum install -y php php-fpm php-mysqlnd
- |
systemctl start php-fpm
- |
systemctl enable php-fpm
- |
cd /usr/share/nginx/html
- |
wget http://wordpress.org/latest.tar.gz
- |
tar xzvf latest.tar.gz
- |
cp -R wordpress/* .
- |
rm -R wordpress
- |
rm -R wordpress
- |
cp wp-config-sample.php wp-config.php
- |
sed -i "s/database_name_here/$DatabaseName/" wp-config.php
- |
sed -i "s/username_here/$DatabaseUser/" wp-config.php
- |
sed -i "s/password_here/${DatabasePwd:-$DatabasePwdDef}/" wp-config.php
- |
sed -i "s/localhost/$DatabaseHost/" wp-config.php
- |
systemctl restart nginx
- |
systemctl restart php-fpm
- |
ros-notify
VSwitchId:
Ref: VSwitch
VpcId:
Ref: Vpc
InstanceType:
Ref: EcsInstanceType
SystemDiskCategory: cloud_essd
AllocatePublicIP: true
ZoneId:
Ref: Zone
Outputs:
ECSInstanceUser:
Description: Username and password for logging in to ECS instance
Value:
Fn::Join:
- ''
- - 'USERNAME: root ; PASSWORD: '
- Ref: InstancePassword
WPUserForSQL:
Description: ECS-hosted database username and password for executing SQL
Value: 'USERNAME: wordpressuser ; PASSWORD: password'
WPUserForDTS:
Description: ECS-hosted database username and password for connecting to DTS
Value: 'USERNAME: dtssync1 ; PASSWORD: P@ssw0rd'
RDSUserDTS:
Description: RDS username and password for connecting to DTS
Value:
Fn::Join:
- ''
- - 'USERNAME: '
- Ref: DBUserName
- ' '
- 'PASSWORD: '
- Ref: DBPassword