-
Notifications
You must be signed in to change notification settings - Fork 35
/
custom-image-ecs-datadisk.yml
502 lines (494 loc) · 14.4 KB
/
custom-image-ecs-datadisk.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 单实例自定义镜像部署,含数据盘与可选公网IP,支持新建或指定VPC配置。
en: Deployment of single-instance custom images, inclusive of data disks and optional
public IP addresses, with support for creating or specifying VPC configurations.
Conditions:
CreateVpcConditions:
Fn::Equals:
- true
- Ref: WhetherCreateVpc
IfAllocatePublicIP:
Fn::Equals:
- Ref: AllocatePublicIP
- true
Parameters:
PayType:
Type: String
Label:
en: ECS Instance Charge Type
zh-cn: 付费类型
AssociationProperty: ChargeType
AssociationPropertyMetadata:
LocaleKey: InstanceChargeType
Default: PostPaid
AllowedValues:
- PostPaid
- PrePaid
PayPeriodUnit:
Type: String
Label:
en: Pay Period Unit
zh-cn: 购买资源时长周期
AssociationProperty: PayPeriodUnit
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
Default: Month
AllowedValues:
- Month
- Year
PayPeriod:
Type: Number
Label:
en: Period
zh-cn: 购买资源时长
AssociationProperty: PayPeriod
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
Default: 1
AllowedValues:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
EcsInstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceChargeType: ${InstanceChargeType}
ZoneId:
Type: String
Label:
en: Availability Zone
zh-cn: 可用区
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
WhetherCreateVpc:
Type: Boolean
Label:
en: WhetherCreateVpc
zh-cn: 是否新建VPC
Default: false
VpcCidrBlock:
Type: String
Label:
en: VPC CIDR IPv4 Block
zh-cn: 专有网络IPv4网段
Description:
zh-cn: VPC的ip地址段范围,<br>您可以使用以下的ip地址段或其子网:<br><font color='green'>[10.0.0.0/8]</font><br><font
color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use
the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font
color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>'
AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- true
Default: 192.168.0.0/16
VSwitchCidrBlock:
Type: String
Label:
en: VSwitch CIDR Block
zh-cn: 交换机子网网段
Description:
zh-cn: 必须属于VPC的子网段。
en: Must belong to the subnet segment of VPC.
AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
AssociationPropertyMetadata:
VpcCidrBlock: VpcCidrBlock
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- true
Default: 192.168.1.0/24
VpcId:
Type: String
Label:
en: VPC ID
zh-cn: 专有网络VPC实例ID
AssociationProperty: ALIYUN::ECS::VPC::VPCId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- false
Default: ''
VSwitchId:
Type: String
Label:
en: VSwitch ID
zh-cn: 交换机实例ID
AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
AssociationPropertyMetadata:
VpcId: ${VpcId}
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Equals:
- ${WhetherCreateVpc}
- false
Default: ''
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: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
InstanceType: ${EcsInstanceType}
AllowedValues:
- cloud_efficiency
- cloud_ssd
- cloud_essd
SystemDiskSize:
Type: Number
Label:
zh-cn: 系统盘空间 (GB)
en: System Disk Space (GB)
Default: 200
DataDiskCategory:
Type: String
Label:
zh-cn: 数据盘类型
en: Data disk type
AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory
AssociationPropertyMetadata:
InstanceType: EcsInstanceType
ZoneId: ZoneId
LocaleKey: DiskCategory
DataDiskSize:
Type: Number
Label:
zh-cn: 数据盘空间
en: Data disk space
Description:
zh-cn: ECS实例数据盘大小,单位为GiB。取值范围:20~32768
en: 'ECS Instance disk size, range of values: 20-32768, units: GB'
Default: 200
MinValue: 20
MaxValue: 32768
AllocatePublicIP:
Type: Boolean
Label:
zh-cn: 开启公网IP
en: allocate public ip
Default: true
InternetMaxBandwidthOut:
Type: Number
Label:
zh-cn: 流量公网带宽
en: Internet Max Bandwidth Out
Description:
zh-cn: 取值范围0-100, 0为不开公网ip
en: no public ip if zero
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${AllocatePublicIP}
- true
Default: 5
MinValue: 0
MaxValue: 100
Resources:
EcsVpc:
Type: ALIYUN::ECS::VPC
Condition: CreateVpcConditions
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateVpcConditions
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: EcsVpc
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
# 按照软件名称设置安全组名称
#SecurityGroupName: nginx-sg
VpcId:
Fn::If:
- CreateVpcConditions
- Ref: EcsVpc
- Ref: VpcId
# 按照软件监听的端口,设置入方向规则(安全组默认出方向的全部端口都是放行的)
#SecurityGroupIngress:
# - PortRange: 80/80
# Priority: 1
# SourceCidrIp: 0.0.0.0/0
# IpProtocol: tcp
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Fn::If:
- CreateVpcConditions
- Ref: EcsVpc
- Ref: VpcId
VSwitchId:
Fn::If:
- CreateVpcConditions
- Ref: EcsVSwitch
- Ref: VSwitchId
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7
IoOptimized: optimized
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
SystemDiskCategory:
Ref: SystemDiskCategory
# 系统盘大小可以根据需要调整
SystemDiskSize:
Ref: SystemDiskSize
# 数据盘配置
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
MaxAmount: 1
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
# 公网带宽, 为 0 代表不开公网
InternetMaxBandwidthOut:
Fn::If:
- IfAllocatePublicIP
- Ref: InternetMaxBandwidthOut
- 0
InstanceName:
Fn::Join:
- '-'
- - Ref: ALIYUN::StackName
- '[1,4]'
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
# 等待命令执行完成的超时时间
Timeout: 300
InstanceRunCommand:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
CommandContent:
Fn::Sub:
- |
#!/bin/bash
# 1. 如果使用了数据盘,需要对数据盘进行格式化,并挂载到指定目录,这里假定挂载到/data
init_and_mount_data_disk() {
local fs_type=$1
local mount_point=$2
# 找出磁盘设备(排除分区)
devices=(`lsblk -o NAME,FSTYPE --noheadings --nodeps | awk '$2 == "" {print $1}'`)
# 找出不存在文件系统的磁盘设备
for device in ${!devices[@]};
do
lsblk -o NAME,FSTYPE --noheadings | awk '$2 != "" {print $1}' | grep ${!device}
if [[ $? -eq 1 ]]; then
data_disk=${!device}
break
fi
done
# 为数据盘创建文件系统
mkfs -t ${!fs_type} /dev/${!data_disk}
cp /etc/fstab /etc/fstab.bak
mkdir ${!mount_point}
# 更新/etc/fstab并挂载磁盘
echo `blkid /dev/${!data_disk} | awk '{print $2}' | sed 's/\\\"//g'` ${!mount_point} ext4 defaults 0 0 >> /etc/fstab
mount -a
}
# 挂盘到/data
init_and_mount_data_disk ext4 /data
# 2. 安装软件,或者对软件进行初始化配置,比如将数据文件目录指定到数据盘目录
# yum install -y nginx
# 3. 如果需要开机自启动,请添加系统服务并启用
# systemctl enable nginx.service
# 4. 配置启动脚本或者启动系统服务
# systemctl start nginx.service
# 5. 执行成功回调WaitCondition结束waitCondition的等待
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
# 脚本里任何地方如果发现执行失败,使用以下命令返回FAILURE和错误信息
# ${CurlCli} -d "{\"Data\" : \"error message\", \"status\" : \"FAILURE\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Type: RunShellScript
# 按照命令执行时间设置超时,单位是秒;命令执行超时则部署失败
Timeout: 300
# outputs是根据软件需求定义
# Outputs are defined according to software requirements
# 以下是以nginx为例,输出了网站公网访问地址
# The following is an example of nginx, which outputs the public network access address of the website
#Outputs:
# endpoint:
# Condition: IfAllocatePublicIP
# Description:
# zh-cn: 对外暴露的公网IP地址
# en: Public IP Addresses
# Value:
# Fn::Sub:
# - http://${ServerAddress}
# - ServerAddress:
# Fn::Select:
# - 0
# - Fn::GetAtt:
# - EcsInstanceGroup
# - PublicIps
Metadata:
ALIYUN::ROS::Interface:
## 参数组的顺序会确定用户创建服务实例页面的参数排列顺序
## The order of the parameter groups determines the order in which the parameters are arranged on the user creation service instance page
## 如果绝大部分实例规格都适用,比如x86架构,可以按注释中将可用区放在前面选择
## If most of the instance specifications are applicable, such as the x86 architecture, you can select the availability zone in front of the note
# ParameterGroups:
# - Parameters:
# - ZoneId
# Label:
# default:
# zh-cn: 可用区配置
# en: Zone Configuration
# - Parameters:
# - WhetherCreateVpc
# - VpcCidrBlock
# - VSwitchCidrBlock
# - VpcId
# - VSwitchId
# Label:
# default:
# zh-cn: VPC配置
# en: VPC Configuration
# - Parameters:
# - PayType
# - PayPeriodUnit
# - PayPeriod
# Label:
# default:
# en: PayType Configuration
# zh-cn: 付费类型配置
# - Parameters:
# - EcsInstanceType
# - InstancePassword
# - SystemDiskCategory
# - SystemDiskSize
# - DataDiskCategory
# - DataDiskSize
# - AllocatePublicIP
# - InternetMaxBandwidthOut
# Label:
# default:
# en: Instance
# zh-cn: ECS实例配置
ParameterGroups:
- Parameters:
- PayType
- PayPeriodUnit
- PayPeriod
Label:
default:
en: PayType Configuration
zh-cn: 付费类型配置
- Parameters:
- EcsInstanceType
Label:
default:
zh-cn: ECS实例规格配置
en: ECS Instance Type Configuration
- Parameters:
- ZoneId
Label:
default:
zh-cn: 可用区配置
en: Zone Configuration
- Parameters:
- WhetherCreateVpc
- VpcCidrBlock
- VSwitchCidrBlock
- VpcId
- VSwitchId
Label:
default:
zh-cn: VPC配置
en: VPC Configuration
- Parameters:
- InstancePassword
- SystemDiskCategory
- SystemDiskSize
- DataDiskCategory
- DataDiskSize
- AllocatePublicIP
- InternetMaxBandwidthOut
Label:
default:
en: Instance
zh-cn: ECS实例详细配置
TemplateTags:
- acs:example:ISV软件部署:单实例自定义镜像部署带数据盘公网IP可选