forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp-centos7.yml
376 lines (376 loc) · 12.5 KB
/
ftp-centos7.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建Centos7 ECS实例,配置安全组,安装部署FTP服务,支持自定义ECS或新建ECS资源。
en: Create a Centos 7 ECS instance, configure security groups, install and deploy
FTP services, supporting customization of ECS or the creation of new ECS resources.
Conditions:
CreateEcs:
Fn::Equals:
- 创建ECS
- Ref: EcsCondition
HasEcs:
Fn::Equals:
- 使用已有ECS
- Ref: EcsCondition
Parameters:
EcsCondition:
Type: String
Label:
zh-cn: 是否创建ECS
en: FTP server access username
AllowedValues:
- 使用已有ECS
- 创建ECS
Default: 使用已有ECS
EcsInstanceId:
Type: String
Default: Null
Label:
en: ECS Instance ID
zh-cn: ECS实例ID
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 创建ECS
FTPUser:
Label:
zh-cn: FTP服务访问用户名
en: FTP server access username
Type: String
Default: ftptest
FTPUserPassword:
Label:
zh-cn: FTP服务访问用户密码
en: FTP server access username
Type: String
NoEcho: true
SystemDiskCategory:
Default: Null
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
InstanceType: ${InstanceType}
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS
Type: String
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>]'
Label:
zh-cn: 系统磁盘类型
en: System Disk Category
InstancePassword:
ConstraintDescription:
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers, special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
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()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
MinLength: '8'
Label:
zh-cn: 实例密码
en: Instance Password
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
NoEcho: true
Default: Null
MaxLength: '30'
Type: String
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS
InstanceType:
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS
Type: String
Default: Null
Label:
zh-cn: 实例类型
en: Instance Type
ZoneId:
Default: Null
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Type: String
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>
Label:
zh-cn: 可用区ID
en: Available Zone ID
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${EcsCondition}
- 使用已有ECS
Outputs:
FTPServerAddress:
Condition: CreateEcs
Description: FTP server Connection address.
Value:
Fn::Join:
- ''
- - ftp://
- Fn::GetAtt:
- VpcEip
- EipAddress
- ':21'
FtpServerAddress:
Condition: HasEcs
Description: FTP server Connection address.
Value:
Fn::Sub:
- ftp://${IP}:21
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress end
- Fn::GetAtt:
- DS_Instances
- Instances
Resources:
DS_Instances:
Condition: HasEcs
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
- Ref: EcsInstanceId
SecurityGroupIngress_22:
Condition: HasEcs
Type: ALIYUN::ECS::SecurityGroupIngress
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_50000:
Condition: HasEcs
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 50000/50010
SecurityGroupIngress_21:
Condition: HasEcs
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 21/21
InstallFtp:
Condition: HasEcs
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Ref: EcsInstanceId
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub:
- |
#!/bin/bash
# install ftp
yum install -y vsftpd
adduser '${FTPUser}'
echo '${FTPUserPassword}' | passwd --stdin '${FTPUser}'
mkdir /var/ftp/test
touch /var/ftp/test/testfile.txt
chown -R '${FTPUser}':'${FTPUser}' /var/ftp/test
touch /etc/vsftpd/chroot_list
sed -i 's/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf
sed -i 's/listen=NO/listen=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/listen_ipv6=YES/\# listen_ipv6=YES/' /etc/vsftpd/vsftpd.conf
echo "local_root=/var/ftp/test" >>/etc/vsftpd/vsftpd.conf
echo "pasv_enable=YES" >>/etc/vsftpd/vsftpd.conf
echo "allow_writeable_chroot=YES" >>/etc/vsftpd/vsftpd.conf
echo "pasv_min_port=50000" >>/etc/vsftpd/vsftpd.conf
echo "pasv_max_port=50010" >>/etc/vsftpd/vsftpd.conf
echo "pasv_address=${IP}" >>/etc/vsftpd/vsftpd.conf
sed -i 's/\#anon_upload_enable=YES/anon_upload_enable=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/\#chroot_local_user=YES/chroot_local_user=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/\#chroot_list_enable=YES/chroot_list_enable=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's%#chroot_list_file=/etc/vsftpd/chroot_list%chroot_list_file=/etc/vsftpd/chroot_list%' /etc/vsftpd/vsftpd.conf
chmod o+w /var/ftp/pub/
systemctl enable vsftpd.service
systemctl restart vsftpd.service
${WaitConditionHandle.CurlCli} -d "{\"status\" : \"SUCCESS\"}"
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress end
- Fn::GetAtt:
- DS_Instances
- Instances
DependsOn:
- SecurityGroupIngress_21
- SecurityGroupIngress_22
EcsSecurityGroup:
Condition: CreateEcs
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupIngress:
- Priority: 1
PortRange: 22/22
NicType: internet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- Priority: 1
PortRange: 21/21
NicType: internet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
- Priority: 1
PortRange: 50000/50010
NicType: internet
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
VpcId:
Ref: EcsVpc
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateEcs
Properties:
VpcId:
Ref: EcsVpc
CidrBlock: 192.168.1.0/24
ZoneId:
Ref: ZoneId
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 1800
DependsOn: EcsInstance
VpcEip:
Condition: CreateEcs
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 5
EipAssociation:
Condition: CreateEcs
DependsOn:
- VpcEip
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Fn::GetAtt:
- EcsInstance
- InstanceId
AllocationId:
Ref: VpcEip
EcsInstance:
Condition: CreateEcs
Type: ALIYUN::ECS::Instance
Properties:
UserData:
Fn::Sub: |
#!/bin/bash
# install ftp
yum install -y vsftpd
adduser '${FTPUser}'
echo '${FTPUserPassword}' | passwd --stdin '${FTPUser}'
mkdir /var/ftp/test
touch /var/ftp/test/testfile.txt
chown -R '${FTPUser}':'${FTPUser}' /var/ftp/test
touch /etc/vsftpd/chroot_list
sed -i 's/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf
sed -i 's/listen=NO/listen=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/listen_ipv6=YES/\# listen_ipv6=YES/' /etc/vsftpd/vsftpd.conf
echo "local_root=/var/ftp/test" >>/etc/vsftpd/vsftpd.conf
echo "pasv_enable=YES" >>/etc/vsftpd/vsftpd.conf
echo "allow_writeable_chroot=YES" >>/etc/vsftpd/vsftpd.conf
echo "pasv_min_port=50000" >>/etc/vsftpd/vsftpd.conf
echo "pasv_max_port=50010" >>/etc/vsftpd/vsftpd.conf
echo "pasv_address=${VpcEip.EipAddress}" >>/etc/vsftpd/vsftpd.conf
sed -i 's/\#anon_upload_enable=YES/anon_upload_enable=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/\#chroot_local_user=YES/chroot_local_user=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/\#chroot_list_enable=YES/chroot_list_enable=YES/' /etc/vsftpd/vsftpd.conf
sed -i 's%#chroot_list_file=/etc/vsftpd/chroot_list%chroot_list_file=/etc/vsftpd/chroot_list%' /etc/vsftpd/vsftpd.conf
chmod o+w /var/ftp/pub/
systemctl enable vsftpd.service
systemctl restart vsftpd.service
${WaitConditionHandle.CurlCli} -d "{\"status\" : \"SUCCESS\"}"
SystemDiskCategory:
Ref: SystemDiskCategory
VpcId:
Fn::GetAtt:
- EcsVpc
- VpcId
AllocatePublicIP: false
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7
VSwitchId:
Ref: EcsVSwitch
Password:
Ref: InstancePassword
InstanceType:
Ref: InstanceType
EcsVpc:
Condition: CreateEcs
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- EcsCondition
- EcsInstanceId
- ZoneId
- InstanceType
- SystemDiskCategory
- InstancePassword
- FTPUser
- FTPUserPassword
Label:
default: ECS
TemplateTags:
- acs:document-help:ecs:手动搭建FTP站点(CentOS 7)