-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathecs-high-availability-lamp.yml
More file actions
422 lines (415 loc) · 12.3 KB
/
ecs-high-availability-lamp.yml
File metadata and controls
422 lines (415 loc) · 12.3 KB
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
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建CentOS 7.9 ECS上的LAMP环境,配置静态网页,通过CLB实现高可用性。
en: Set up a LAMP environment on a CentOS 7.9 ECS instance, configure static web
content, and ensure high availability through a Classic Load Balancer (CLB).
Parameters:
LoadBalancerId:
Type: String
Label:
en: CLB Instance ID
zh-cn: CLB实例ID
AssociationProperty: ALIYUN::SLB::Instance::InstanceId
EcsInstanceIds:
Type: CommaDelimitedList
Label:
en: ECS Instance ID List
zh-cn: ECS实例ID列表
Description:
en: Please select 2 ECS instances equipped with CentOS 7 system, <span style="background:#E7E9EB;"><b>the
ECS instance and the CLB instance need to be under the same VPC</b></span>.
zh-cn: 请选择2个搭载CentOS 7系统的ECS实例,<span style="background:#E7E9EB;"><b>ECS实例和CLB实例需要在同一个VPC下</b></span>。
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
MinLength: 2
MaxLength: 2
DbPassword:
Type: String
Label:
en: MySQL Database Password
zh-cn: MySQL数据库密码
Description:
en: "The password must be 8 to 32 characters in length. <br>\nIt must contain\
\ the following character types: uppercase letters, lowercase letters, digits,\
\ and special characters. <br> \nSpecial characters include <span style=\"\
background:#E7E9EB;\"><b>!@#$%^&*()_+-=</b></span>.<br>\n<b>If you repeatedly\
\ provision in this tutorial on the same ECS instance, make sure that the\
\ MySQL database password is exactly the same as the password set when the\
\ template was executed for the first time. Otherwise, the result of provisioning\
\ is unavailable.</b>"
zh-cn: "长度为8~32位,需包含大写字母、小写字母、特殊字符和数字,允许的特殊字符包括<span style=\"background:#E7E9EB;\"\
><b>!@#$%^&*()_+-=</b></span>。<br> \n<b>如果您在同一台ECS实例上重复执行本教程的一键配置模板,请确保MySQL数据库密码和第一次执行模板时设置的密码完全一致。否则一键配置结果不可用。</b>"
AllowedPattern: ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])((?=.*[!@#\$%\^&\*\(\)\-\+])|(?=.*[_\.,:;\-\?]))[a-zA-Z0-9!@#\$%\^&\*\(\)\-\+_\.,:;\-\?]{8,32}$
NoEcho: true
Confirm: true
Resources:
DS_Instances:
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
- Fn::Select:
- 0
- Ref: EcsInstanceIds
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
Properties: {}
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Handle:
Ref: WaitConditionHandle
Timeout: 3720
Count: 1
SecurityGroupIngress_80:
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: 80/80
SecurityGroupIngress_3306:
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: 3306/3306
InstallLAMP:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Ref: EcsInstanceIds
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
if [ ! -f .ros.provision ]; then
echo "Name: 手动部署LAMP环境(CentOS 7)" > .ros.provision
fi
name=$(grep "^Name:" .ros.provision | awk -F':' '{print $2}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "$name" != "手动部署LAMP环境(CentOS 7)" ]]; then
echo "当前实例已使用过\"$name\"教程的一键配置,不能再使用本教程的一键配置"
${WaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"The current instance has already applied the configuration of the \\\"$name\\\" tutorial, and the configuration of this tutorial can no longer be applied.\"}"
exit 0
fi
echo "#########################"
echo "# Check Network"
echo "#########################"
ping -c 2 -W 2 aliyun.com > /dev/null
if [[ $? -ne 0 ]]; then
echo "当前实例无法访问公网"
${WaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"The current instance cannot access the public network.\"}"
exit 0
fi
if ! grep -q "^Step1: Prepare Environment$" .ros.provision; then
echo "#########################"
echo "# Prepare Environment"
echo "#########################"
systemctl status firewalld
systemctl stop firewalld
echo "Step1: Prepare Environment" >> .ros.provision
else
echo "#########################"
echo "# Environment has been ready"
echo "#########################"
fi
if ! grep -q "^Step1: Install Apache$" .ros.provision; then
echo "#########################"
echo "# Install Apache"
echo "#########################"
yum install -y httpd httpd-manual mod_ssl mod_perl mod_auth_mysql
systemctl start httpd
systemctl enable httpd
systemctl status httpd
echo "Step1: Install Apache" >> .ros.provision
else
echo "#########################"
echo "# Apache has been installed"
echo "#########################"
fi
if ! grep -q "^Step2: Install MySQL$" .ros.provision; then
echo "#########################"
echo "# Install MySQL"
echo "#########################"
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql-community-server --nogpgcheck
systemctl start mysqld.service
systemctl status mysqld.service
export MYSQL_PWD=`grep "temporary password" /var/log/mysqld.log | awk '{print $NF}'`
mysqladmin -uroot password '${DbPassword}'
export MYSQL_PWD='${DbPassword}'
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${DbPassword}'"
echo "Step2: Install MySQL" >> .ros.provision
else
echo "#########################"
echo "# MySQL has been installed"
echo "#########################"
fi
if ! grep -q "^Step3: Install PHP$" .ros.provision; then
echo "#########################"
echo "# Install PHP"
echo "#########################"
yum install -y https://repo.ius.io/ius-release-el7.rpm https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install -y php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
systemctl restart httpd
echo "Step3: Install PHP" >> .ros.provision
else
echo "#########################"
echo "# PHP has been installed"
echo "#########################"
fi
${WaitConditionHandle.CurlCli} --data-binary '{"status": "SUCCESS"}'
DependsOn:
- SecurityGroupIngress_3306
- SecurityGroupIngress_80
Page:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Fn::Select:
- Ref: ALIYUN::Index
- Ref: EcsInstanceIds
Type: RunShellScript
Sync: true
CommandContent:
Fn::Sub:
- |
#!/bin/bash
echo "Hello World ! This is ECS0${Index}." > /var/www/html/index.html
systemctl restart httpd
- Index:
Fn::Add:
- 1
- Ref: ALIYUN::Index
DependsOn: InstallLAMP
Count:
Fn::Length:
Ref: EcsInstanceIds
DS_LoadBalancers:
Type: DATASOURCE::SLB::LoadBalancers
Properties:
LoadBalancerId:
Ref: LoadBalancerId
ServerGroup:
Type: ALIYUN::SLB::VServerGroup
Properties:
LoadBalancerId:
Ref: LoadBalancerId
VServerGroupName: TrialTutorial
BackendServers:
- ServerId:
Fn::Select:
- 0
- Ref: EcsInstanceIds
Port: 80
- ServerId:
Fn::Select:
- 1
- Ref: EcsInstanceIds
Port: 80
DependsOn: Page
Listener:
Type: ALIYUN::SLB::Listener
Properties:
VServerGroupId:
Ref: ServerGroup
LoadBalancerId:
Ref: LoadBalancerId
Protocol: http
ListenerPort: 80
HealthCheck:
Switch: 'on'
URI: /
HealthCheckMethod: head
Timeout: 5
HealthyThreshold: 2
UnhealthyThreshold: 2
Interval: 2
Bandwidth: -1
StartListener: true
Outputs:
Url:
Description:
en: Info Page.
zh-cn: 信息页面。
Value:
Fn::Sub:
- http://${IP}
- IP:
Fn::Jq:
- First
- .[0].Address
- Fn::GetAtt:
- DS_LoadBalancers
- LoadBalancers
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- LoadBalancerId
- EcsInstanceIds
- DbPassword
TemplateTags:
- acs:document:试用教程:部署高可用LAMP环境
ALIYUN::ROS::Composer:
8bd485e1:
Rect:
- 411
- 391
- 40
- 100
- 1
- 0
ResT: Composer::ROSParameter::AlibabaCloud
ec190b55:
Parent: 8bd485e1
Rect:
- 300
- 302
- 60
- 150
- 2
- 0
ResT: Composer::ROSParameter::Region
82331f8e:
Res:
- DS_Instances
Parent: ec190b55
Rect:
- 40
- 40
- 190
- 220
- 3
- 0
ResT: DATASOURCE::ECS::Instances
a26f6bd0:
Res:
- WaitConditionHandle
Parent: ec190b55
Rect:
- 40
- 40
- 200
- 260
- 3
- 0
Hidden: true
912efc83:
Res:
- WaitCondition
Parent: ec190b55
Rect:
- 40
- 40
- 140
- 260
- 3
- 0
Hidden: true
b8024d3b:
Res:
- SecurityGroupIngress_80
Parent: ec190b55
Rect:
- 40
- 40
- 200
- 200
- 3
- 0
Hidden: true
250cdc35:
Res:
- SecurityGroupIngress_3306
Parent: ec190b55
Rect:
- 40
- 40
- 80
- 260
- 3
- 0
Hidden: true
91ce99e7:
Res:
- InstallLAMP
Parent: ec190b55
Rect:
- 40
- 40
- 80
- 200
- 3
- 0
Hidden: true
bf5d21ac:
Res:
- Page
Parent: ec190b55
Rect:
- 40
- 40
- 140
- 200
- 3
- 0
Hidden: true
17ce0390:
Res:
- DS_LoadBalancers
Parent: ec190b55
Rect:
- 40
- 40
- 240
- 320
- 3
- 0
ResT: DATASOURCE::SLB::LoadBalancers
5fff6aba:
Res:
- ServerGroup
Parent: ec190b55
Rect:
- 40
- 40
- 120
- 320
- 3
- 0
ce1563ea:
Edge:
- 912efc83
- a26f6bd0
Line: 0:0:0:gray:0
589cf487:
Parent: ec190b55
Edge:
- b8024d3b
- 82331f8e
Line: 0:0:0:gray:0
c5f47165:
Parent: ec190b55
Edge:
- 250cdc35
- 82331f8e
Line: 0:0:0:gray:0