forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lnmp-basic.yml
486 lines (486 loc) · 16.4 KB
/
lnmp-basic.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Deploy LNMP(Linux+Nginx+MySQL+PHP) stack on 1 ECS instance. *** WARNING ***
Only support CentOS-7.
zh-cn: 在1个ECS实例上部署 LNMP(Linux+Nginx+MySQL+PHP)堆栈;模板仅支持 CentOS-7。
Parameters:
SelectExistECS:
Type: Boolean
Label:
en: Whether to select an existing instance
zh-cn: 是否选择已有实例
Description:
en: Whether to select an existing Centos7 system instance. The Centos7 system instance must be connected to a public network.
zh-cn: 是否选择已有Centos7系统实例,实例需要开通公网。
Default: false
ZoneId:
Type: String
Label:
en: Available Zone ID
zh-cn: 可用区ID
Description:
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>
zh-cn: 可用区ID。<br><b>注: <font color='blue'>选择可用区前请确认该可用区是否支持创建ECS资源的规格</font></b>
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
AssociationPropertyMetadata:
ZoneId: ZoneId
Visible:
Condition:
Fn::Equals:
- ${SelectExistECS}
- false
Default: null
ECSInstanceId:
Type: String
Label:
en: Existing ECS Instance
zh-cn: 已创建ECS实例
Description:
en: Select an ECS instance with the CentOS 7.9 64-bit operating system.
zh-cn: 选择已存在操作系统为CentOS 7.9 64位的ECS实例。
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
AssociationPropertyMetadata:
ZoneId: ZoneId
Visible:
Condition:
Fn::Equals:
- ${SelectExistECS}
- true
Default: null
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
Description:
en: 'Fill in specifications that can be used under availability zone;</b></font><br>general
specifications:<font color=''red''><b>ecs.c5.large</b></font><br>note: a few
zones do not support general specifications<br>see detail: <a href=''https://www.alibabacloud.com/help/en/doc-detail/25378.html''
target=''_blank''><b><font color=''blue''>Instance Specification Family</font></a></b>'
zh-cn: 填写可用区下可使用的规格;<br>通用规格:<font color='red'><b>ecs.c5.large</b></font><br>注:可用区可能不支持通用规格<br>规格详见:<a
href='https://help.aliyun.com/document_detail/25378.html' target='_blank'><b><font
color='blue'>实例规格族</font></a></b>
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ZoneId
Visible:
Condition:
Fn::Equals:
- ${SelectExistECS}
- false
Default: ecs.c5.large
SystemDiskCategory:
Type: String
Label:
en: System Disk Category
zh-cn: 系统磁盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
InstanceType: ${InstanceType}
ZoneId: ZoneId
Visible:
Condition:
Fn::Equals:
- ${SelectExistECS}
- false
Default: cloud_efficiency
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
Description:
en: The 8-30 long login password of instance, consists of the uppercase, lowercase
letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三个;<br>特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
ConstraintDescription:
en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers,
special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
zh-cn: 长度8-30,必须包含大写字母、小写字母、数字、特殊符号三种;特殊字符包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${SelectExistECS}
- false
MinLength: '8'
MaxLength: '30'
NoEcho: true
Default: null
DBName:
Type: String
Label:
en: DB Name
zh-cn: 数据库名称
Description:
en: MySQL database name, [1, 64] English or Chinese characters, must start with
a letter or Chinese in size, can contain numbers, '_' or '.', '-'.
zh-cn: MySQL数据库名称,[1, 64] 英文或中文字符,必须以字母或中文开头,可以包含数字、下划线或“.”、“-”。
ConstraintDescription:
en: Consist of 2 to 64 characters of lowercase letters, underline. Must begin
with a letter and be end with an alphanumeric character
zh-cn: 由 2 到 64 个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾
Default: MyDatabase
MinLength: 1
MaxLength: 64
DBUser:
Type: String
Label:
en: DB Username
zh-cn: 数据库用户名
Description:
en: Username for MySQL database access.It consists of lowercase letters, numbers
and underscores (_), and begins with a letter. Not longer than 16 characters.
zh-cn: MySQL数据库访问的用户名。它由小写字母、数字和下划线(_)组成,以字母开头。不超过16个字符。
ConstraintDescription:
en: Consist of 2 to 16 characters of lowercase letters, underline. Must begin
with a letter and be end with an alphanumeric character
zh-cn: 由 2 到 16 个小写字母组成,下划线。必须以字母开头,以字母数字字符结尾
Default: DefaultUser
MinLength: 2
MaxLength: 16
DBPassword:
Type: String
Label:
en: DB Password
zh-cn: 数据库密码
Description:
en: The MySQL password, consisting of letters, numbers, and underline(_), 8
to 32 characters in length
zh-cn: MySQL密码,数据库访问大小写字母、数字和下划线(_),8-32个字符
ConstraintDescription:
en: '[8, 32] characters consist of alphanumeric characters, hyphen and underline'
zh-cn: '[8, 32] 个字符由字母数字字符、连字符和下划线组成'
MinLength: 8
MaxLength: 32
NoEcho: true
DBRootPassword:
Type: String
Label:
en: DB Root Password
zh-cn: 数据库root用户密码
Description:
en: Root password for MySQL, consisting of letters, numbers, and underline(_),
8 to 32 characters in length
zh-cn: MySQL的root密码, 由字母、数字、下划线(_)组成,长度为8~32个字符
ConstraintDescription:
en: Consisting of letters, numbers, and underline(_), 8 to 32 characters in
length
zh-cn: 由字母、数字和下划线(_)组成,长度为8到32个字符
MinLength: 8
MaxLength: 32
NoEcho: true
NginxDownloadUrl:
Type: String
Label:
en: Nginx Source
zh-cn: Nginx源
Description:
en: nginx-.rpm source download path.
zh-cn: nginx-*.rpm源下载路径
Default: http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Conditions:
IsSelectExistECS:
Fn::Equals:
- Ref: SelectExistECS
- false
NotSelectExistECS:
Fn::Equals:
- Ref: SelectExistECS
- true
Resources:
EcsVpc:
Type: ALIYUN::ECS::VPC
Condition: IsSelectExistECS
Properties:
CidrBlock: 192.168.0.0/16
Metadata:
ALIYUN::ROS::Designer:
id: 598ced8b-0ba4-40a8-a781-1d48e26ca15f
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Condition: IsSelectExistECS
Properties:
VpcId:
Ref: EcsVpc
SecurityGroupEgress:
- DestCidrIp: 0.0.0.0/0
IpProtocol: all
NicType: intranet
PortRange: -1/-1
Priority: 1
SecurityGroupIngress:
- IpProtocol: all
NicType: intranet
PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
Metadata:
ALIYUN::ROS::Designer:
id: 7a621d9a-c803-4121-ba09-30dc9a417423
EcsVSwitch:
Type: ALIYUN::ECS::VSwitch
Condition: IsSelectExistECS
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: EcsVpc
CidrBlock: 192.168.1.0/24
Metadata:
ALIYUN::ROS::Designer:
id: dae2dd74-1b30-4975-8b70-4877f4c2d9d3
WebServer:
Type: ALIYUN::ECS::Instance
Condition: IsSelectExistECS
Properties:
VpcId:
Fn::GetAtt:
- EcsVpc
- VpcId
VSwitchId:
Ref: EcsVSwitch
SecurityGroupId:
Ref: EcsSecurityGroup
ImageId: centos_7
InstanceType:
Ref: InstanceType
InternetMaxBandwidthOut: 80
IoOptimized: optimized
Password:
Ref: InstancePassword
SystemDiskCategory:
Ref: SystemDiskCategory
Metadata:
ALIYUN::ROS::Designer:
id: 0af5b81e-0e55-4e6a-ba96-45cf7a730510
ExistWebServer:
Type: DATASOURCE::ECS::Instances
Condition: NotSelectExistECS
Properties:
InstanceId:
Ref: ECSInstanceId
Command:
Type: ALIYUN::ECS::Command
Properties:
Timeout: 1800
CommandContent:
Fn::Base64Encode:
Fn::Sub:
- |-
#!/bin/bash
NginxUrl=${NginxUrl}
dbname=${DBName}
dbuser=${DBUser}
dbpassword=${DBPassword}
dbrootpassword=${DBRootPassword}
export HOME=/root
export HOSTNAME=`hostname`
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/^SELINUX=/# SELINUX=/' /etc/selinux/config
sed -i '/# SELINUX=/a SELINUX=disabled' /etc/selinux/config
setenforce 0
yum install yum-priorities -y
yum -y install aria2
aria2c $NginxUrl
rpm -ivh nginx-*.rpm
yum -y install nginx
systemctl start nginx.service
systemctl enable nginx.service
yum -y install php-fpm
systemctl start php-fpm.service
systemctl enable php-fpm.service
sed -i '/FastCGI/,/htaccess/s/ #/ /' /etc/nginx/conf.d/default.conf
sed -i '/FastCGI/s/^ / #/' /etc/nginx/conf.d/default.conf
sed -i '/htaccess/s/^ / #/' /etc/nginx/conf.d/default.conf
sed -i '/SCRIPT_FILENAME/s/\/scripts/\/usr\/share\/nginx\/html\//' /etc/nginx/conf.d/default.conf
yum -y install mariadb mariadb-server
systemctl start mariadb.service
systemctl enable mariadb.service
yum -y install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-mcrypt
MDSRING=`find / -name mbstring.so`
echo extension=$MDSRING >> /etc/php.ini
systemctl restart mariadb.service
mysqladmin -u root password "$dbrootpassword"
$(mysql $dbname -u root --password="$dbrootpassword" >/dev/null 2>&1 </dev/null); (( $? != 0 ))
echo CREATE DATABASE $dbname \; > /tmp/setup.mysql
echo GRANT ALL ON $dbname.* TO "$dbuser"@"localhost" IDENTIFIED BY "'$dbpassword'" \; >> /tmp/setup.mysql
mysql -u root --password="$dbrootpassword" < /tmp/setup.mysql
$(mysql $dbname -u root --password="$dbrootpassword" >/dev/null 2>&1 </dev/null); (( $? != 0 ))
cd /root
systemctl restart php-fpm.service
systemctl restart nginx.service
echo \<?php > /usr/share/nginx/html/test.php
echo \$conn=mysql_connect\("'127.0.0.1'", "'$dbuser'", "'$dbpassword'"\)\; >> /usr/share/nginx/html/test.php
echo if \(\$conn\){ >> /usr/share/nginx/html/test.php
echo echo \"LNMP platform connect to mysql is successful\!\"\; >> /usr/share/nginx/html/test.php
echo }else{ >> /usr/share/nginx/html/test.php
echo echo \"LNMP platform connect to mysql is failed\!\"\; >> /usr/share/nginx/html/test.php
echo } >> /usr/share/nginx/html/test.php
echo phpinfo\(\)\; >> /usr/share/nginx/html/test.php
echo \?\> >> /usr/share/nginx/html/test.php
${CurlCli} -d '{"data" : "Install nginx."}'
- NginxUrl:
Ref: NginxDownloadUrl
DBName:
Ref: DBName
DBUser:
Ref: DBUser
DBPassword:
Ref: DBPassword
DBRootPassword:
Ref: DBRootPassword
CurlCli:
Fn::GetAtt:
- WebServerConditionHandle
- CurlCli
Type: RunShellScript
Name:
Ref: ALIYUN::StackId
DependsOn:
- WebServerConditionHandle
Invocation:
Type: ALIYUN::ECS::Invocation
Properties:
InstanceIds:
- Fn::If:
- IsSelectExistECS
- Fn::GetAtt:
- WebServer
- InstanceId
- Ref: ECSInstanceId
CommandId:
Ref: Command
WebServerConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
Metadata:
ALIYUN::ROS::Designer:
id: ec1625d7-b79b-496d-ba3a-5c46be0c1181
WebServerWaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WebServerConditionHandle
Timeout: 1800
DependsOn: WebServer
Metadata:
ALIYUN::ROS::Designer:
id: b528acf3-d6df-43bd-b17e-a22cd32f72e7
Outputs:
NginxWebsiteURL:
Description: URL for newly created Nginx home page.
Value:
Fn::Sub:
- 'http://${IP}:80/test.php'
- IP:
'Fn::If':
- IsSelectExistECS
- 'Fn::GetAtt':
- WebServer
- PublicIp
- 'Fn::Jq':
- First
- >-
if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0]
else .[0].EipAddress.IpAddress end
- 'Fn::GetAtt':
- ExistWebServer
- Instances
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- SelectExistECS
- ZoneId
- ECSInstanceId
- InstanceType
- SystemDiskCategory
- InstancePassword
Label:
default: ECS
- Parameters:
- DBName
- DBUser
- DBPassword
- DBRootPassword
Label:
default: Database
- Parameters:
- NginxDownloadUrl
Label:
default: Nginx
TemplateTags:
- acs:example:网站:部署LNMP(Linux+Nginx+MySQL+PHP)环境
ALIYUN::ROS::Designer:
05871fb7-6c4d-4dc1-abb9-084ad7c14d1c:
source:
id: 0af5b81e-0e55-4e6a-ba96-45cf7a730510
target:
id: 7a621d9a-c803-4121-ba09-30dc9a417423
z: 1
0af5b81e-0e55-4e6a-ba96-45cf7a730510:
position:
x: 386
y: 163
size:
height: 60
width: 60
z: 2
598ced8b-0ba4-40a8-a781-1d48e26ca15f:
embeds:
- dae2dd74-1b30-4975-8b70-4877f4c2d9d3
- 7a621d9a-c803-4121-ba09-30dc9a417423
position:
x: 192
y: 50
size:
height: 314
width: 318.0537109375
z: 0
7a621d9a-c803-4121-ba09-30dc9a417423:
position:
x: 229
y: 163
size:
height: 60
width: 60
z: 1
a828cca7-7ef3-4441-b51d-1ed7c419ad0d:
source:
id: b528acf3-d6df-43bd-b17e-a22cd32f72e7
target:
id: ec1625d7-b79b-496d-ba3a-5c46be0c1181
z: 1
b528acf3-d6df-43bd-b17e-a22cd32f72e7:
position:
x: 567
y: 252
size:
height: 60
width: 60
z: 0
dae2dd74-1b30-4975-8b70-4877f4c2d9d3:
embeds:
- 0af5b81e-0e55-4e6a-ba96-45cf7a730510
position:
x: 347
y: 123
size:
height: 151
width: 122
z: 1
ec1625d7-b79b-496d-ba3a-5c46be0c1181:
position:
x: 567
y: 98
size:
height: 60
width: 60
z: 0