-
Notifications
You must be signed in to change notification settings - Fork 35
/
ecs-with-2-data-disk.yml
269 lines (249 loc) · 7.39 KB
/
ecs-with-2-data-disk.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建ECS实例,配置安全组、快照数据盘x2、系统盘设置,优化IO,挂载点自动配置脚本。
en: Create an ECS instance, configure security groups, set up snapshot for data
disks (x2), configure the system disk, optimize I/O performance, and automate
the configuration of mount points with a script.
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
SecurityGroupId:
Type: String
Label: Security Group Id
Description: The id of the security group. e.g. sg-xxxxxxxxxxxxx.
IoOptimized:
Type: String
Label: Io Optimized
Description: The 'optimized' instance can provide better IO performance. Support
'none' and 'optimized' only, default is 'none'.
Default: optimized
AllowedValues:
- none
- optimized
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
SecondDataDiskSourceSnapshotId:
Type: String
Label: Second Data Disk Source Snapshot Id
Description: The snapshot ID of the second data disk.
FirstDataDiskName:
Type: String
Label: First Data Disk Name
Description: Display name of the first data 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: Ecs Zone Id
Description: Ecs Available Zone Id, <a href='#/product/cn-beijing/list/zoneList'
target='_blank'>View zoneid info</a>
MountPoint:
Type: String
Label: Mount Point
Description: The mount point of data disk
SecondDataDiskSize:
Type: Number
Label: Second Data Disk Size
Description: 'The size of the second data disk, 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
VSwitchId:
Type: String
Label: VSwitch Id
Description: The vSwitch Id of ecs instance.
VpcId:
Type: String
Label: Vpc Id
Description: The VPC id of ecs instance.
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
FirstDataDiskSourceSnapshotId:
Type: String
Label: First Data Disk Source Snapshot Id
Description: The snapshot ID of the first data disk.
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 Disk Name
Description: Name of system disk.
Default: SystemDisk
FirstDataDiskSize:
Type: Number
Label: First Data Disk Size
Description: 'The size of the first data disk, 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 instances mounted under data disk
SecondDataDiskName:
Type: String
Label: Second Data Disk Name
Description: Display name of the second data disk, [2, 128] English or Chinese
characters, must start with a letter or Chinese in size, can contain numbers,
'_' or '.', '-'.
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:
WebServer:
Type: ALIYUN::ECS::Instance
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: VpcId
VSwitchId:
Ref: VSwitchId
SecurityGroupId:
Ref: SecurityGroupId
ImageId:
Ref: ImageId
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: FirstDataDiskCategory
SnapshotId:
Ref: FirstDataDiskSourceSnapshotId
DiskName:
Ref: FirstDataDiskName
Size:
Ref: FirstDataDiskSize
- Category:
Ref: SecondDataDiskCategory
SnapshotId:
Ref: SecondDataDiskSourceSnapshotId
DiskName:
Ref: SecondDataDiskName
Size:
Ref: SecondDataDiskSize
Password:
Ref: Password
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}''`
'
- ' 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
IoOptimized:
Ref: IoOptimized
SystemDiskDiskName:
Ref: SystemDiskDiskName
SystemDiskCategory:
Ref: SystemDiskCategory
Outputs:
InstanceId:
Description: The instance id of ecs instance.
Value:
Fn::GetAtt:
- WebServer
- InstanceId
ZoneId:
Description: Zone id of created instance.
Value:
Fn::GetAtt:
- WebServer
- ZoneId