-
Notifications
You must be signed in to change notification settings - Fork 35
/
migrate-rds-mysql-to-polardb-mysql.yml
309 lines (306 loc) · 9.46 KB
/
migrate-rds-mysql-to-polardb-mysql.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 一键升级RDS MySQL到PolarDB MySQL,自动配置网络、安全与数据迁移,无需改动应用代码。
en: One-click upgrade from RDS MySQL to PolarDB MySQL, with automatic configuration
of network, security, and data migration, eliminating the need for any modifications
to application code.
Parameters:
ZoneId:
Type: String
Label:
en: Zone ID
zh-cn: 可用区ID
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ZoneId
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${InstanceType}
Default: cloud_essd
Password:
Type: String
Label:
en: ECS Instance Password
zh-cn: ECS实例密码
Description:
en: 'The password must be 8 to 32 characters in length and must contain at least
three of the following types: uppercase letters, lowercase letter, digits,
and special characters. Special characters include <span style="background:#E7E9EB;"><b>!@#$%^&*()_+-=</b></span>'
zh-cn: 必须包含三种及以上类型:大写字母、小写字母、数字、特殊符号。长度为8~32位。特殊字符包括<span style="background:#E7E9EB;"><b>!@#$%^&*()_+-=</b></span>
AssociationProperty: ALIYUN::ECS::Instance::Password
NoEcho: true
DBInstanceClass:
Type: String
Label:
en: RDS Instance Class
zh-cn: RDS实例规格
AssociationProperty: ALIYUN::RDS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
EngineVersion: '8.0'
DBInstanceStorageType: cloud_essd
Engine: MySQL
Category: HighAvailability
CommodityCode: bards
DBInstanceStorage:
Type: Number
Label:
en: Instance Storage
zh-cn: 实例存储
Description:
en: 'Incrementing in every 5G, unit: GB'
zh-cn: 每5G递增,单位:GB
ConstraintDescription:
en: '[20, 32000] Incrementing in every 5G, unit: GB'
zh-cn: '[20, 32000] 每 5G 递增,单位:GB'
MinValue: 20
MaxValue: 32000
Default: 100
RdsAccountPassword:
Type: String
Label:
en: RDS Account Password
zh-cn: RDS账号密码
Description:
en: 'The password must be 8 to 32 characters in length and must contain at least
three of the following types: uppercase letters, lowercase letter, digits,
and special characters. Special characters include <span style="background:#E7E9EB;"><b>!@#$%^&*()_+-=</b></span>'
zh-cn: 必须包含三种及以上类型:大写字母、小写字母、数字、特殊符号。长度为8~32位。特殊字符包括<span style="background:#E7E9EB;"><b>!@#$%^&*()_+-=</b></span>
AssociationProperty: ALIYUN::RDS::Instance::AccountPassword
NoEcho: true
PolarDBNodeClass:
Type: String
Label:
en: PolarDBNodeClass
zh-cn: PolarDB集群规格
Default: polar.mysql.x4.large
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
VpcName: vpc_rds2polardb
CidrBlock: 192.168.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName: vsw_rds2polardb
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName: sg_rds2polardb
VpcId:
Ref: Vpc
SecurityGroupIngress_3306:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 3306/3306
RdsInstance:
Type: ALIYUN::RDS::DBInstance
Properties:
DBInstanceDescription: rds_2polardb
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
ZoneId:
Ref: ZoneId
Engine: MySQL
EngineVersion: '8.0'
DBInstanceClass:
Ref: DBInstanceClass
DBInstanceNetType: Intranet
Category: HighAvailability
SlaveZoneIds:
- Ref: ZoneId
DBInstanceStorageType: cloud_essd
DBInstanceStorage:
Ref: DBInstanceStorage
AllocatePublicConnection: true
SecurityIPList: 192.168.0.0/16
SecurityGroupId:
Ref: SecurityGroup
RdsDatabase:
Type: ALIYUN::RDS::Database
Properties:
DBInstanceId:
Ref: RdsInstance
CharacterSetName: utf8mb4
DBName: db_rds2polardb
RdsAccount:
Type: ALIYUN::RDS::Account
Properties:
AccountName: u_rds2polardb
AccountType: Normal
AccountPassword:
Ref: RdsAccountPassword
DBInstanceId:
Ref: RdsInstance
RdsAccountPrivilege:
Type: ALIYUN::RDS::AccountPrivilege
Properties:
AccountPrivilege: ReadWrite
DBInstanceId:
Ref: RdsInstance
DBName:
Ref: RdsDatabase
AccountName:
Ref: RdsAccount
InstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceName: ecs_rds2polardb
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
ZoneId:
Ref: ZoneId
SecurityGroupId:
Ref: SecurityGroup
ImageId: centos_7_6
InstanceType:
Ref: InstanceType
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize: 40
Password:
Ref: Password
IoOptimized: optimized
MaxAmount: 1
AllocatePublicIP: true
InternetMaxBandwidthOut: 100
InternetChargeType: PayByTraffic
Tags:
- Key: rds
Value: polardb
PrepareMySQLEnvironment:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Fn::GetAtt:
- InstanceGroup
- InstanceIds
Type: RunShellScript
Sync: true
Timeout: 7200
CommandContent:
Fn::Sub: |-
#!/bin/bash
echo "################################"
echo "# Install MySQL"
echo "################################"
yum -y install mysql
mysql --version
echo "################################"
echo "# Create MySQL Table"
echo "################################"
mysql -h${RdsInstance.InnerConnectionString} -uu_rds2polardb -p${RdsAccountPassword} -Ddb_rds2polardb -e"CREATE TABLE t_rds2polardb(id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, gmt_create datetime NOT NULL);"
echo "################################"
echo "# Prepare MySQL Script"
echo "################################"
cat > ~/loop_insert_query_mysql.sh << \EOF
export MYSQL_HOST=${RdsInstance.InnerConnectionString}
export MYSQL_PWD=${RdsAccountPassword}
while true; do
mysql -A -uu_rds2polardb -Ddb_rds2polardb -NBe'insert into t_rds2polardb(gmt_create) values(now());select concat("系统时间:",now()," 数据写入时间:",max(gmt_create)," 总行数:",count(*)) from t_rds2polardb;show variables like "polardb_version";'
sleep 5
done
EOF
chmod +x ~/loop_insert_query_mysql.sh
cat > ~/loop_query_polardb.sh << \EOF
export MYSQL_HOST=${PolarDBCluster.PrimaryConnectionString}
export MYSQL_PWD=${RdsAccountPassword}
while true; do
mysql -A -uu_rds2polardb -Ddb_rds2polardb -NBe'select concat("系统时间:",now()," 数据写入时间:",max(gmt_create)," 总行数:",count(*)) from t_rds2polardb;show variables like "polardb_version";'
sleep 5
done
EOF
chmod +x ~/loop_query_polardb.sh
DependsOn:
- RdsAccountPrivilege
PolarDBCluster:
Type: ALIYUN::POLARDB::DBCluster
Properties:
DBClusterDescription: rds2_polardb
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupIds:
- Ref: SecurityGroup
DBType: MySQL
ClusterNetworkType: VPC
DBVersion: '8.0'
DBNodeClass:
Ref: PolarDBNodeClass
SecurityIPList: 192.168.0.0/16
PayType: Postpaid
CreationCategory: Normal
CreationOption: MigrationFromRDS
SourceResourceId:
Ref: RdsInstance
StorageType: PSL5
DependsOn:
- RdsAccountPrivilege
Outputs:
RdsInnerConnectionString:
Description:
zh-cn: 内网连接地址。
en: Rds Inner Connection address.
Value:
Fn::GetAtt:
- RdsInstance
- InnerConnectionString
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- ZoneId
Label:
en: Basic Configuration
zh-cn: 基础配置
- Parameters:
- InstanceType
- SystemDiskCategory
- Password
Label:
en: ECS Configuration
zh-cn: ECS配置
- Parameters:
- DBInstanceClass
- DBInstanceStorage
- RdsAccountPassword
Label:
en: RDS Configuration
zh-cn: RDS配置
- Parameters:
- PolarDBNodeClass
Label:
en: PolarDB Configuration
zh-cn: PolarDB配置
TemplateTags:
- acs:technical-solution:db:RDS MySQL迁移至PolarDB MySQL版-tech_solu_25