forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcentOS-ecs-oss.yml
381 lines (372 loc) · 10.2 KB
/
centOS-ecs-oss.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
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Implement OSS on CentOS ECS.
zh-cn: 基于CentOS的ECS实例实现OSS反向代理
Parameters:
CreateECS:
Type: Boolean
Label:
en: If use new ECS instance.
zh-cn: 是否新建ECS实例
Default: true
ExistedEcsInstanceId:
Type: String
Label:
en: Select An Existing CentOS ECS Instance ID
zh-cn: 请选择带有CentOS镜像的实例ID
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateECS}
- false
Default: ''
ECSZoneId:
Type: String
Label:
en: VPC Zone
zh-cn: VPC支持的可用区
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateECS}
- true
Default: ''
InstanceType:
Type: String
Description:
zh-cn: 选择可用区下可使用的规格。
en: Fill in the specifications that can be used under the availability zone.
Label:
zh-cn: ECS实例规格
en: ECS Instance Type
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ECSZoneId}
Visible:
Condition:
Fn::Equals:
- ${CreateECS}
- true
Default: 'ecs.c6e.large'
Password:
Type: String
Label:
zh-cn: ECS 实例密码
en: ECS Instance Password
Description:
en: Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol
in).
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)。
ConstraintDescription: '[8, 30] characters, consists of uppercase letter, lowercase
letter and special characters.'
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
Confirm: true
Default: Null
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateECS}
- true
EcsSystemDiskCategory:
Type: String
Label:
en: System Disk Type
zh-cn: 系统盘类型
Description:
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>]'
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>]'
Default: cloud_ssd
AllowedValues:
- cloud_efficiency
- cloud_ssd
- cloud
- cloud_essd
- ephemeral_ssd
AssociationPropertyMetadata:
ZoneId: ${ECSZoneId}
InstanceType: ${InstanceType}
Visible:
Condition:
Fn::Equals:
- ${CreateECS}
- true
CreateOSS:
Type: Boolean
Label:
en: If create new OSSBucket
zh-cn: 是否新建OSS Bucket
Default: true
BucketName:
Type: String
Label:
zh-cn: 存储空间名称
en: Bucket Name
Description:
en: The Bucket name cannot be changed after it is created successfully. The Bucket name must be unique in OSS.
zh-cn: Bucket名称,创建成功后将不可更改,Bucket名称在OSS全局范围内必须唯一。
ConstraintDescription:
en: Must begin and be end with a lowercase letter or number. The length is within
[3, 63]
zh-cn: 必须以小写英文字母或数字开头和结尾。长度为3~63个字符。
Default: myprodbucket
AllowedPattern: ^[a-z0-9]{1}[a-z0-9\-]{1,62}[a-z0-9]{1}$
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateOSS}
- true
ExistedBucketName:
Type: String
Label:
zh-cn: 已有存储空间名称
en: Your Existed Bucket Name
AssociationProperty: ALIYUN::OSS::Bucket::BucketName
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateOSS}
- false
Default: ''
Conditions:
CreateInstance:
Fn::Equals:
- Ref: CreateECS
- true
NotCreateInstance:
Fn::Equals:
- Ref: CreateECS
- false
CreateOSSBucket:
Fn::Equals:
- Ref: CreateOSS
- true
Resources:
InstanceRole:
Type: ALIYUN::RAM::Role
Condition: CreateInstance
DependsOn: OssBucket
Properties:
RoleName:
Fn::Replace:
- "_": "."
- Fn::Join:
- "_"
- - "OSSRole"
- Ref: ALIYUN::StackName
AssumeRolePolicyDocument:
Statement:
- Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service:
- ecs.aliyuncs.com
Version: '1'
Policies:
- PolicyName:
Ref: ALIYUN::StackName
PolicyDocument:
Version: '1'
Statement:
- Action:
- oss:GetObject
Resource:
- Fn::Sub:
- acs:oss:*:*:${BucketName}/*
- BucketName:
Fn::If:
- CreateOSSBucket
- Ref: BucketName
- Ref: ExistedBucketName
Effect: Allow
VPC:
Type: ALIYUN::ECS::VPC
Condition: CreateInstance
Properties:
VpcName: myvpc
CidrBlock: 192.168.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: CreateInstance
Properties:
VpcId:
Ref: VPC
ZoneId:
Ref: ECSZoneId
CidrBlock: 192.168.0.0/24
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Condition: CreateInstance
Properties:
VpcId:
Ref: VPC
SecurityGroupName: mysg
SecurityGroupType: normal
SecurityGroupIngress:
- SourceCidrIp: 0.0.0.0/0
PortRange: 80/80
IpProtocol: tcp
- SourceCidrIp: 0.0.0.0/0
PortRange: 22/22
IpProtocol: tcp
SecurityGroupIngress_80:
Type: ALIYUN::ECS::SecurityGroupIngress
Condition: NotCreateInstance
Properties:
SecurityGroupId:
Fn::Jq:
- First
- ".SecurityGroupIds[0]"
- Fn::Select:
- 0
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
PortRange: 80/80
EcsInstance:
Type: ALIYUN::ECS::Instance
Condition: CreateInstance
DependsOn:
- OssBucket
- InstanceRole
Properties:
VpcId:
Ref: VPC
VSwitchId:
Ref: VSwitch
HostName: WebServer
ImageId: centos_7
IoOptimized: optimized
AllocatePublicIP: true
RamRoleName:
Fn::GetAtt:
- InstanceRole
- RoleName
InstanceChargeType: PostPaid
SpotStrategy: NoSpot
InstanceType:
Ref: InstanceType
Password:
Ref: Password
SecurityGroupId:
Ref: SecurityGroup
SystemDiskCategory:
Ref: EcsSystemDiskCategory
SystemDiskSize: 40
OssBucket:
Type: ALIYUN::OSS::Bucket
Condition: CreateOSSBucket
Properties:
BucketName:
Ref: BucketName
AccessControl: private
CORSConfiguration:
CORSRule:
- AllowedHeader:
- '*'
AllowedMethod:
- GET
AllowedOrigin:
- '*'
DS_Instances:
Type: DATASOURCE::ECS::Instances
Condition: NotCreateInstance
Properties:
InstanceIds: [Ref: ExistedEcsInstanceId]
InstanceRunCommand:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Fn::If:
- CreateInstance
- [Ref: EcsInstance]
- [Ref: ExistedEcsInstanceId]
Type: RunShellScript
CommandContent:
Fn::Sub:
- |
#!/bin/bash
sudo yum install -y nginx
sudo sed -i "46 a \ \tlocation / {\n \ \t\ \tproxy_pass http://${OSS_DOMAIN};\n \ \t} " /etc/nginx/nginx.conf
cd /usr/sbin
sudo ./nginx
- OSS_DOMAIN:
Fn::If:
- CreateOSSBucket
- Fn::GetAtt:
- OssBucket
- InternalDomainName
- Fn::Join:
- ""
- - Ref: ExistedBucketName
- ".oss-"
- Ref: ALIYUN::Region
- ".aliyuncs.com"
Timeout: 3600
DependsOn:
- SecurityGroupIngress_80
Outputs:
EcsInstanceId:
Description: The instance id of created ecs instance
Value:
Fn::If:
- Condition: CreateInstance
- Ref: EcsInstance
- Ref: ExistedEcsInstanceId
ECSPublicIP:
Description: Public IP address of ECS.
Condition: CreateInstance
Value:
Fn::GetAtt:
- EcsInstance
- PublicIp
OSSBucketName:
Value:
Fn::If:
- CreateOSSBucket
- Fn::GetAtt:
- OssBucket
- Name
- Ref: ExistedBucketName
BucketRegion:
Value:
Ref: ALIYUN::Region
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- CreateECS
- ExistedEcsInstanceId
- ECSZoneId
- InstanceType
- Password
- EcsSystemDiskCategory
Label:
default: 'ECS'
- Parameters:
- CreateOSS
- BucketName
- ExistedBucketName
Label:
default: 'OSSBucket'
TemplateTags:
- acs:document-help:ecs:基于CentOS的ECS实例实现OSS反向代理