-
Notifications
You must be signed in to change notification settings - Fork 35
/
centOS-ecs-oss.yml
234 lines (234 loc) · 6.82 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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建CentOS ECS实例并配置OSS反向代理,支持新建或使用现有实例与OSS Bucket。
en: Create a CentOS ECS instance and configure OSS reverse proxy, supporting the
creation of new or utilization of existing instances along with OSS Buckets.
Parameters:
CommonName:
Type: String
Default: oss-server-sign
BucketName:
AssociationPropertyMetadata:
Length: 6
Prefix: test-bucketname-
CharacterClasses:
- Class: lowercase
min: 1
Description:
zh-cn: Bucket 名称在 OSS 范围内必须全局唯一。长度为3~63个字符。必须以小写英文字母或数字开头和结尾,可包含小写英文字母、数字和短划线(-)。
en: Bucket names must be globally unique within the scope of OSS. The length is 3~63 characters. Must start and end with a lowercase English letter or number, and can contain lowercase English letters, numbers, and dashes (-).
Label:
zh-cn: 新建存储空间名称
en: NewBucketName
AllowedPattern: ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$
AssociationProperty: AutoCompleteInput
Type: String
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
AutoSelectFirst: true
Label:
en: Availability Zone
zh-cn: 可用区
InstanceType:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
InstanceChargeType: PostPaid
SystemDiskCategory: cloud_essd
ZoneId: ${ZoneId}
Label:
en: Instance Type
zh-cn: 实例规格
Password:
NoEcho: true
Type: String
Description:
en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
Label:
en: ECS Instance Password
zh-cn: ECS实例密码
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
Resources:
InstanceRole:
Type: ALIYUN::RAM::Role
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:
- Ref: BucketName
Effect: Allow
VPC:
Type: ALIYUN::ECS::VPC
Properties:
VpcName: myvpc
CidrBlock: 192.168.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: VPC
ZoneId:
Ref: ZoneId
CidrBlock: 192.168.0.0/24
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
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
EcsInstance:
Type: ALIYUN::ECS::Instance
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: cloud_essd
SystemDiskDiskName: SystemDisk
SystemDiskSize: 40
OssBucket:
Type: ALIYUN::OSS::Bucket
Properties:
BucketName:
Ref: BucketName
AccessControl: private
CORSConfiguration:
CORSRule:
- AllowedHeader:
- '*'
AllowedMethod:
- GET
AllowedOrigin:
- '*'
InstanceRunCommand:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Ref: EcsInstance
Type: RunShellScript
CommandContent:
Fn::Sub:
- |
#!/bin/bash
sudo yum install -y nginx
export OSS_PUBLIC_DOMAIN=${OSS_DOMAIN}
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::GetAtt:
- OssBucket
- InternalDomainName
Timeout: 3600
Outputs:
BucketPublicDomainName:
Value:
Fn::GetAtt:
- OssBucket
- DomainName
BucketInternalDomainName:
Value:
Fn::GetAtt:
- OssBucket
- InternalDomainName
Console.Bucket:
Label:
zh-cn: Bucket
en: Bucket
Description:
zh-cn: 文件上传到的bucket控制台页面。可访问该链接上传测试文件。
en: Bucket console page, which you can upload test files.
Value:
Fn::Sub:
- https://oss.console.aliyun.com/bucket/oss-${Region}/${BucketName}
- Region:
Ref: ALIYUN::Region
BucketName:
Ref: BucketName
Console.Url:
Label:
zh-cn: EcsIP
en: EcsIP
Description:
zh-cn: ECS公网地址,可使用此地址+文件访问路径访问bucket资源。
en: Public address of ECS, which you can access bucket resources via file access path.
Value:
Fn::Sub:
- http://${IP}
- IP:
Fn::GetAtt:
- EcsInstance
- PublicIp
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- BucketName
Label:
default: 'OSSBucket'
- Parameters:
- ZoneId
- InstanceType
- Password
Label:
default: 'ECS'
TemplateTags:
- acs:document-help:ecs:基于CentOS的ECS实例实现OSS反向代理