-
Notifications
You must be signed in to change notification settings - Fork 35
/
mysql-centos8.yml
304 lines (304 loc) · 9.34 KB
/
mysql-centos8.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建Centos8 ECS实例,配置安全组与EIP,自动安装MySQL服务并设置用户访问。
en: Create a CentOS 8 ECS instance, configure security groups and Elastic IP (EIP),
automatically install MySQL service, and set up user access.
Conditions:
CreateEcs:
Fn::Equals:
- 创建ECS
- Ref: EcsCondition
HasEcs:
Fn::Equals:
- 使用已有ECS
- Ref: EcsCondition
Parameters:
ZoneId:
Type: String
Label:
zh-cn: 可用区ID
en: Available Zone ID
Description:
zh-cn: 可用区ID。<br><b>注: <font color='blue'>选择可用区前请确认该可用区是否支持创建ECS资源的规格</font></b>
en: Availability Zone ID,<br><b>note: <font color='blue'>Before selecting, please
confirm that the Availability Zone supports the specification of creating
ECS resources</font></b>
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${EcsCondition}
- 创建ECS
Default: Null
InstanceType:
Type: String
Label:
zh-cn: 实例类型
en: Instance Type
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Equals:
- ${EcsCondition}
- 创建ECS
Default: Null
SystemDiskCategory:
Type: String
Label:
zh-cn: 系统磁盘类型
en: System Disk Category
Description:
zh-cn: '<font color=''blue''><b>可选值:</b></font><br>[cloud_efficiency: <font
color=''green''>高效云盘</font>]<br>[cloud_ssd: <font color=''green''>SSD云盘</font>]<br>[cloud_essd:
<font color=''green''>ESSD云盘</font>]<br>[cloud: <font color=''green''>普通云盘</font>]<br>[ephemeral_ssd:
<font color=''green''>本地SSD盘</font>]'
en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency:
<font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD
Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud:
<font color=''green''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local
SSD Cloud Disk</font>]'
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
InstanceType: ${InstanceType}
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Equals:
- ${EcsCondition}
- 创建ECS
Default: Null
InstancePassword:
Type: String
Label:
zh-cn: 实例密码
en: Instance Password
Description:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;<br>特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
en: The 8-30 long login password of instance, consists of the uppercase, lowercase
letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
ConstraintDescription:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers,
special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${EcsCondition}
- 创建ECS
Default: Null
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: '8'
MaxLength: '30'
NoEcho: true
MySQLUserName:
Type: String
Label:
en: MySQL User Name
zh-cn: MySQL用户名称
Description:
en: English letters, numbers, or "-" are allowed. The number of characters should
be less than or equal to 64.
zh-cn: 允许英文字母、数字或 “-”。字符数应小于等于 64 个。
AllowedPattern: ^[a-zA-Z0-9-]{1,64}$
MySQLPassword:
Type: String
Label:
zh-cn: MySQL密码
en: MySQL Password
Description:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;<br>特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
en: The 8-30 long login password of instance, consists of the uppercase, lowercase
letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
ConstraintDescription:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers,
special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: '8'
MaxLength: '30'
NoEcho: true
EcsCondition:
Type: String
Label:
zh-cn: 是否创建ECS
en: FTP server access username
Default: 创建ECS
AllowedValues:
- 使用已有ECS
- 创建ECS
EcsInstanceId:
Type: String
Label:
en: ECS Instance ID
zh-cn: ECS实例ID
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS
Default:
Resources:
DS_Instances:
Type: DATASOURCE::ECS::Instances
Condition: HasEcs
Properties:
InstanceIds:
- Ref: EcsInstanceId
SecurityGroupIngress_22:
Type: ALIYUN::ECS::SecurityGroupIngress
Condition: HasEcs
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 22/22
SecurityGroupIngress_3306:
Type: ALIYUN::ECS::SecurityGroupIngress
Condition: HasEcs
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 3306/3306
EcsVpc:
Type: ALIYUN::ECS::VPC
Condition: CreateEcs
Properties:
CidrBlock: 192.168.0.0/16
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateEcs
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: EcsVpc
CidrBlock: 192.168.1.0/24
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Condition: CreateEcs
Properties:
VpcId:
Ref: EcsVpc
SecurityGroupIngress:
- Priority: 1
PortRange: 22/22
NicType: internet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- Priority: 1
PortRange: 3306/3306
NicType: internet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
VpcEip:
Type: ALIYUN::VPC::EIP
Condition: CreateEcs
Properties:
Bandwidth: 5
EcsInstance:
Type: ALIYUN::ECS::Instance
Condition: CreateEcs
Properties:
VpcId:
Fn::GetAtt:
- EcsVpc
- VpcId
VSwitchId:
Ref: EcsVSwitch
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_8
SystemDiskCategory:
Ref: SystemDiskCategory
AllocatePublicIP: false
Password:
Ref: InstancePassword
InstanceType:
Ref: InstanceType
EipAssociation:
Type: ALIYUN::VPC::EIPAssociation
Condition: CreateEcs
Properties:
InstanceId:
Fn::GetAtt:
- EcsInstance
- InstanceId
AllocationId:
Ref: VpcEip
DependsOn:
- VpcEip
InstallMySQL:
Type: 'ALIYUN::ECS::RunCommand'
Properties:
InstanceIds:
- Fn::If:
- CreateEcs
- Ref: EcsInstance
- Ref: EcsInstanceId
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |
#!/bin/bash
sudo dnf -y install @mysql
sudo systemctl enable --now mysqld
mysql -uroot -e "create user '${MySQLUserName}'@'%' identified by '${MySQLPassword}'"
mysql -uroot -e "grant all privileges on *.* to '${MySQLUserName}'@'%'with grant option"
mysql -uroot -e "flush privileges"
mysqladmin -uroot password '${MySQLPassword}'
Outputs:
DbCommand:
Description: Remotely log in to mysql command.
Value:
Fn::If:
- CreateEcs
- Fn::Sub: mysql -u ${MySQLUserName} -h ${VpcEip.EipAddress} -p
- Fn::Sub:
- mysql -u ${MySQLUserName} -h ${IP} -p
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress
end
- Fn::GetAtt:
- DS_Instances
- Instances
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- ZoneId
- InstanceType
- SystemDiskCategory
- InstancePassword
Label:
default: ECS
- Parameters:
- MySQLUserName
- MySQLPassword
Label:
default: MySQL
TemplateTags:
- acs:document-help:ecs:手动部署MySQL(CentOS 8)