-
Notifications
You must be signed in to change notification settings - Fork 35
/
ecs-mount-multiple-uninitialized-data-disks.yml
386 lines (353 loc) · 9.51 KB
/
ecs-mount-multiple-uninitialized-data-disks.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建ECS实例,配置VPC、安全组,挂载两个数据盘,自定义磁盘类别与大小,设置网络与安全规则。
en: Create an ECS instance, configure VPC and security groups, attach two data disks,
customize disk categories and sizes, and set up network and security rules.
Parameters:
ImageId:
Type: String
Label: ECS Image Id
Description: Image Id, represents the image resource to startup one ECS instance,
<a href='#/product/cn-beijing/list/imageList' target='_blank'>View image resources</a>
Default: centos_6
VpcName:
Type: String
Label: Vpc Name
Description: The VPC name
ConstraintDescription: '[2, 128] English or Chinese characters'
Default: myvpc
MinLength: 2
MaxLength: 128
SecondDataDiskCategory:
Type: String
Label: Second Data Disk Category
Description: 'System disk category: average cloud disk(cloud), efficient cloud
disk(cloud_efficiency) or SSD cloud disk(cloud_ssd)'
Default: cloud_ssd
AllowedValues:
- cloud
- cloud_efficiency
- cloud_ssd
SystemDiskSize:
Type: Number
Label: System Disk Size
Description: 'Disk size of the system disk, range from 20 to 500 GB. If you specify
with your own image, make sure the system disk size bigger than image size. '
Default: 40
Password:
Type: String
Label: ECS Instance Password
Description: The login password of ECS instances
ConstraintDescription: Consist of 8 to 30 characters of alphanumeric characters.
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
MinLength: 8
MaxLength: 30
NoEcho: true
Confirm: true
FirstDataDiskName:
Type: String
Label: First Data Disk Name
Description: Display name of the first disk, [2, 128] English or Chinese characters,
must start with a letter or Chinese in size, can contain numbers, '_' or '.',
'-'.
Default: DataDisk_1
ZoneId:
Type: String
Label: Zone Id
Description: The available zone Id, <a href='#/product/cn-beijing/list/zoneList'
target='_blank'>View the available zones</a>
MountPoint:
Type: String
Label: Mount Point
Description: The mount point of data disk
DestinationCidrBlock:
Type: String
Label: Destination CidrBlock
Description: Route destination network, for example 192.168.1.0/24 or 192.168.1.0
Default: 192.168.1.0
SecondDataDiskSize:
Type: Number
Label: Second Data Disk Size
Description: 'The size of the Second volume, unit in GB.Value range: cloud: [5,2000],
cloud_efficiency: [20,32768], cloud_ssd: [20,32768], ephemeral_ssd: [5,800].The
value should be equal to or greater than the specific snapshot.'
Default: 40
VSwitchCidrBlock:
Type: String
Label: VSwitch CidrBlock
Description: VSwitch subnet which is within VPC
Default: 10.0.10.0/24
InstanceType:
Type: String
Label: ECS Instance Type
Description: The ECS instance type, <a href='#/product/cn-beijing/list/typeList'
target='_blank'>View instance types</a>
Default: ecs.c5.large
AllowedValues:
- ecs.c5.large
- ecs.g5.large
- ecs.c5.xlarge
- ecs.g5.xlarge
SecurityGroupName:
Type: String
Label: Security Group Name
Description: The security group name
Default: mysecuritygroup
VpcCidrBlock:
Type: String
Label: Vpc CidrBlock
Description: |-
The IP address range of the VPC in the CIDR block form. You can use the following IP address ranges and their subnets:
10.0.0.0/8
172.16.0.0/12 (Default)
192.168.0.0/16
Default: 10.0.0.0/8
AllowedValues:
- 192.168.0.0/16
- 172.16.0.0/12
- 10.0.0.0/8
FirstDataDiskCategory:
Type: String
Label: First Data Disk Category
Description: 'System disk category: average cloud disk(cloud), efficient cloud
disk(cloud_efficiency) or SSD cloud disk(cloud_ssd)'
Default: cloud_ssd
AllowedValues:
- cloud
- cloud_efficiency
- cloud_ssd
SystemDiskDiskName:
Type: String
Label: System Disk Name
Description: Name of created system disk.
Default: SystemDisk
FirstDataDiskSize:
Type: Number
Label: First Data Disk Size
Description: 'The size of the first volume, unit in GB.Value range: cloud: [5,2000],
cloud_efficiency: [20,32768], cloud_ssd: [20,32768], ephemeral_ssd: [5,800].The
value should be equal to or greater than the specific snapshot.'
Default: 40
TotalDataDisk:
Type: String
Label: Total Data Disk
Description: The number of disks mounted in instance
SecondDataDiskName:
Type: String
Label: Second Data Disk Name
Description: Second Data Disk Name
Default: DataDisk_2
SystemDiskCategory:
Type: String
Label: System Disk Category
Description: 'System disk category: average cloud disk(cloud), efficient cloud
disk(cloud_efficiency) or SSD cloud disk(cloud_ssd)'
Default: cloud_ssd
AllowedValues:
- cloud
- cloud_efficiency
- cloud_ssd
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: VpcName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Fn::GetAtt:
- Vpc
- VpcId
CidrBlock:
Ref: VSwitchCidrBlock
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupName:
Ref: SecurityGroupName
NewEip:
Type: ALIYUN::ECS::EIP
Properties:
InternetChargeType: PayByTraffic
Bandwidth: 1
SecurityGroupIngress:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: intranet
PortRange: -1/-1
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId:
Ref: ImageId
IoOptimized: optimized
AllocatePublicIP: 'false'
SystemDiskSize:
Ref: SystemDiskSize
Password:
Ref: Password
DiskMappings:
- Category:
Ref: FirstDataDiskCategory
DiskName:
Ref: FirstDataDiskName
Size:
Ref: FirstDataDiskSize
- Category:
Ref: SecondDataDiskCategory
DiskName:
Ref: SecondDataDiskName
Size:
Ref: SecondDataDiskSize
SystemDiskDiskName:
Ref: SystemDiskDiskName
SystemDiskCategory:
Ref: SystemDiskCategory
UserData:
Fn::Join:
- ''
- - '#!/bin/sh
'
- 'logs=~/mount_logs
'
- 'i=1
'
- total=
- Ref: TotalDataDisk
- '
'
- mountpoint=
- Ref: MountPoint
- '
'
- 'while [ $i -le $total ]
'
- 'do
'
- ' j=`echo $i|awk ''{printf "%c", 97+$i}''`
'
- 'fdisk -S 56 /dev/vd$j <<ESXU
'
- 'n
'
- 'p
'
- '1
'
- '
'
- '
'
- 'w
'
- 'ESXU
'
- ' echo "/dev/vd$j is fdisked!" >> $logs
'
- ' mkfs.ext4 /dev/vd${j}1
'
- ' if [ $? -eq 0 ];then
'
- ' echo "/dev/vd${j}1 is formated!" >> $logs
'
- ' fi
'
- ' touch ~/test_ftab
'
- ' mkdir $mountpoint$i
'
- 'cat << ESXU > ~/test_ftab
'
- '/dev/vd${j}1 $mountpoint$i ext4 defaults 0
0
'
- 'ESXU
'
- ' cat ~/test_ftab >> /etc/fstab
'
- ' mount -a
'
- ' chmod -R 777 $mountpoint$i
'
- ' rm -rf ~/test_ftab
'
- ' echo "/dev/vd${j}1 is mounted!" >> $logs
'
- ' let i+=1
'
- 'done
'
InstanceType:
Ref: InstanceType
EIPBind:
Type: ALIYUN::ECS::EIPAssociation
Properties:
InstanceId:
Ref: WebServer
AllocationId:
Ref: NewEip
SecurityGroupEgress:
Type: ALIYUN::ECS::SecurityGroupEgress
Properties:
SecurityGroupId:
Ref: SecurityGroup
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
PortRange: -1/-1
Outputs:
SecurityGroupId:
Description: generated security group id for security group.
Value:
Fn::GetAtt:
- SecurityGroup
- SecurityGroupId
InstanceId:
Description: The instance id of created ecs instance.
Value:
Fn::GetAtt:
- WebServer
- InstanceId
ZoneId:
Description: Zone id of created instance.
Value:
Fn::GetAtt:
- WebServer
- ZoneId
VSwitchId:
Description: Id of created VSwitch.
Value:
Fn::GetAtt:
- VSwitch
- VSwitchId
NewEipId:
Description: ID that Aliyun assigns to represent the allocation of the address
for use with VPC. Returned only for VPC elastic IP addresses.
Value:
Fn::GetAtt:
- NewEip
- AllocationId
VpcId:
Description: Id of created VPC.
Value:
Fn::GetAtt:
- Vpc
- VpcId