forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e-commerce-business-and-database.yml
839 lines (802 loc) · 26.3 KB
/
e-commerce-business-and-database.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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 电商业务及数据库上云。
en: E-commerce business and database on the cloud.
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- InstanceType
- ECS_ZoneId_1
- ECS_ZoneId_2
- Password
Label:
default: ECS
- Parameters:
- DBInstanceClass
- RDS_ZoneId_1
- RDS_ZoneId_2
- DBPassword
Label:
default: RDS
- Parameters:
- LoadBalancerSpec
- SLB_ZoneId_1
Label:
default: SLB
TemplateTags:
- acs:technical-solution:network:ECS:电商行业业务及数据库上云
Parameters:
ECS_ZoneId_1:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: ECS可用区A
en: Availability Zone A of ECS
Description:
en: An availability zone to create for the ECS instance, <font color='red'><b>ensure that the current region has
at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建ECS实例的可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
ECS_ZoneId_2:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: ECS可用区B
en: Availability Zone B of ECS
Description:
en: An availability zone to create for the ECS instance, <font color='red'><b>ensure that the current region has
at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建ECS实例的可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
RDS_ZoneId_1:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: RDS主可用区
en: Master availability zone
Description:
en: The master availability zone to create for the RDS instance, <font color='red'><b>ensure that the current
region has at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建RDS实例的主可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
RDS_ZoneId_2:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Label:
zh-cn: RDS备可用区
en: Slave availability zone
Description:
en: The slave availability zone to create for the RDS instance, <font color='red'><b>ensure that the current
region has at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建RDS实例的备可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
InstanceType:
Type: String
Label:
en: ECS Instance Type
zh-cn: ECS实例规格
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
SystemDiskCategory: cloud_essd
Constraints:
InstanceTypeFamily: 'ecs.u1'
Password:
Type: String
Label:
en: ECS instance password
zh-cn: ECS实例密码
Description:
en: 'Length 8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-='
zh-cn: 长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
ConstraintDescription:
en: '8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-='
zh-cn: 8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
MinLength: 8
MaxLength: 32
NoEcho: true
DBInstanceClass:
Type: String
Label:
en: Specifications
zh-cn: 规格
Description:
en: 'Select the instance specification based on the type of database engine
and the available area support;<br>see detail: <a href=''https://www.alibabacloud.com/help/doc-detail/26312.html''
target=''_blank''><b><font color=''blue''>Instance specification sheet</font></b></a>'
zh-cn: 根据数据库引擎的类型和可用的区域支持选择实例规格;<br>请参见详细信息:<a href='https://help.aliyun.com/document_detail/26312.html'
target='_blank'><b><font color='blue'>实例规格表</font></b></a>
Default: rds.mysql.s2.large
DBPassword:
Type: String
Label:
en: Database password
zh-cn: 数据库密码
Description:
en: 'Length 8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-= <br>It applies to both the password of the self-built database on ECS and
the password of RDS.'
zh-cn: 长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)<br>同时适用于ECS上自建数据库的密码与RDS的密码。
ConstraintDescription:
en: '8-32 characters, can contain size letters, Numbers and special symbols,
including: !@#$%^&*()_+-='
zh-cn: 8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
MinLength: 8
MaxLength: 32
NoEcho: true
LoadBalancerSpec:
Type: String
Label:
en: Load balancer instance specification
zh-cn: 负载均衡实例规格
Default: slb.s1.small
AssociationProperty: ALIYUN::SLB::Instance::InstanceType
SLB_ZoneId_1:
Type: String
AssociationProperty: ALIYUN::NLB::Zone::ZoneId
Label:
zh-cn: SLB主可用区
en: Master availability zone
Description:
en: The master availability zone to create for the SLB instance, <font color='red'><b>ensure that the current
region has at least two different availability zones to choose from</b>. If there are no two availability zones,
please change other parameters or switch to another region and check again.
zh-cn: 创建SLB实例的主可用区,<font color='red'><b>请确保当前地域有至少两个不同的可用区可供选择</b></font>。若无双可用区,请修改其他参数或切换至其他地域后重新查看。
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
VpcName: E_Commerce_Vpc
CidrBlock: 192.168.0.0/16
ECS_Vsw_1:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ECS_ZoneId_1
CidrBlock: 192.168.0.0/24
ECS_Vsw_2:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: ECS_ZoneId_2
CidrBlock: 192.168.1.0/24
SLB_Vsw_1:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: SLB_ZoneId_1
CidrBlock: 192.168.2.0/24
RDS_Vsw_1:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: RDS_ZoneId_1
CidrBlock: 192.168.3.0/24
RDS_Vsw_2:
Type: ALIYUN::ECS::VSwitch
Properties:
VpcId:
Ref: Vpc
ZoneId:
Ref: RDS_ZoneId_2
CidrBlock: 192.168.4.0/24
ECommerceSg:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 22/22
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 443/443
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 3389/3389
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: icmp
NicType: intranet
LocalWebSiteSg:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 22/22
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 443/443
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: 3306/3306
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
- PortRange: -1/-1
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: icmp
NicType: intranet
CloudWebSite_1:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: ECommerceSg
VSwitchId:
Ref: ECS_Vsw_1
InstanceName: cloud-web-site-1
HostName: cloud-web-site-1
ZoneId:
Ref: ECS_ZoneId_1
InstanceChargeType: PostPaid
InstanceType:
Ref: InstanceType
ImageId: centos_7_9_x64_20G_alibase
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
AllocatePublicIP: false
Password:
Ref: Password
CloudWebSite_2:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: ECommerceSg
VSwitchId:
Ref: ECS_Vsw_2
InstanceName: cloud-web-site-2
HostName: cloud-web-site-1
ZoneId:
Ref: ECS_ZoneId_2
InstanceChargeType: PostPaid
InstanceType:
Ref: InstanceType
ImageId: centos_7_9_x64_20G_alibase
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
AllocatePublicIP: false
Password:
Ref: Password
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
LoadBalancerSpec:
Ref: LoadBalancerSpec
VpcId:
Ref: Vpc
VSwitchId:
Ref: SLB_Vsw_1
LoadBalancerName: slb-ds-demo
MasterZoneId:
Ref: SLB_ZoneId_1
SlbListener:
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
SlbBackendServerAttachment:
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
- Ref: CloudWebSite_1
- Ref: CloudWebSite_2
BackendServerWeightList:
- 100
- 100
LoadBalancerId:
Ref: Slb
LocalWebSite:
Type: ALIYUN::ECS::Instance
Properties:
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: LocalWebSiteSg
VSwitchId:
Ref: ECS_Vsw_2
InstanceName: local-web-site
HostName: local-web-site
ZoneId:
Ref: ECS_ZoneId_2
InstanceChargeType: PostPaid
InstanceType:
Ref: InstanceType
ImageId: centos_7_9_x64_20G_alibase
SystemDiskCategory: cloud_essd
SystemDiskSize: 40
AllocatePublicIP: false
Password:
Ref: Password
Eip_0:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 100
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
Eip_1:
Type: ALIYUN::VPC::EIP
Properties:
Bandwidth: 100
InstanceChargeType: Postpaid
InternetChargeType: PayByTraffic
VpcEipAssociation_0:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: Slb
AllocationId:
Ref: Eip_0
VpcEipAssociation_1:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: LocalWebSite
AllocationId:
Ref: Eip_1
PrepareLocalData:
Type: ALIYUN::ECS::RunCommand
DependsOn:
- VpcEipAssociation_1
- InstallWebsite
Properties:
Sync: true
Type: RunShellScript
Timeout: 3600
InstanceIds:
- Ref: LocalWebSite
CommandContent:
Fn::Sub: |-
#!/bin/bash
cat > mysql-community.repo << \EOF
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=https://opentuna.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=0
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://opentuna.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=0
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://opentuna.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
EOF
mv mysql-community.repo /etc/yum.repos.d/
yum -y install mysql-community-server
echo log_bin=ON >> /etc/my.cnf
echo server-id=1 >> /etc/my.cnf
systemctl start mysqld
systemctl enable mysqld
TmpPassword=`grep 'A temporary password is generated' /var/log/mysqld.log | awk '{print $NF}'`
mysql -u root -p$TmpPassword --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${DBPassword}'; FLUSH PRIVILEGES;"
cat > setup_mysql.sql << \EOF
CREATE DATABASE `e_commerce_website`;
CREATE USER `e_commerce_user` IDENTIFIED BY "${DBPassword}";
GRANT ALL ON *.* TO "e_commerce_user"@"%";
FLUSH PRIVILEGES;
USE `e_commerce_website`;
CREATE TABLE `products` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(36) NOT NULL,
`price` varchar(36) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO products (`name`, `price`) values
("ProductName1","100"),
("ProductName2","150"),
("ProductName3","200");
EOF
chmod +x setup_mysql.sql
mysql -uroot -p${DBPassword} < setup_mysql.sql
sed -i 's/${RdsDBInstance.InnerConnectionString}/127.0.0.1/g' /var/www/html/mysql_demo.php
RdsDBInstance:
Type: ALIYUN::RDS::DBInstance
Properties:
Category: HighAvailability
DBInstanceStorageType: local_ssd
ZoneId:
Ref: RDS_ZoneId_1
SlaveZoneIds:
- Ref: RDS_ZoneId_2
VpcId:
Ref: Vpc
VSwitchId:
Fn::Join:
- ','
- - Ref: RDS_Vsw_1
- Ref: RDS_Vsw_2
DBInstanceClass:
Ref: DBInstanceClass
DBInstanceStorage: 100
DBMappings:
- CharacterSetName: utf8
DBName: e_commerce_website
Engine: MySQL
EngineVersion: '5.6'
MasterUserPassword:
Ref: DBPassword
MasterUserType: Super
MasterUsername: e_commerce_user
SecurityIPList: 192.168.0.0/16
SecurityGroupId:
Ref: ECommerceSg
DtsInstance:
Type: ALIYUN::DTS::Instance
DependsOn: PrepareLocalData
Properties:
JobId:
Fn::GetAtt:
- MigrationJob
- DtsJobId
InstanceClass: small
PayType: PostPaid
Type: MIGRATION
SourceRegion:
Ref: ALIYUN::Region
DestinationRegion:
Ref: ALIYUN::Region
SourceEndpointEngineName: MySQL
DestinationEndpointEngineName: MySQL
MigrationJob:
Type: ALIYUN::DTS::MigrationJob2
Properties:
DtsJobName: e-commerce-migration
SourceEndpoint:
InstanceType: ECS
InstanceID:
Ref: LocalWebSite
EngineName: MYSQL
Port: '3306'
Region:
Ref: ALIYUN::Region
UserName: e_commerce_user
Password:
Ref: DBPassword
DestinationEndpoint:
InstanceType: RDS
InstanceID:
Ref: RdsDBInstance
EngineName: MYSQL
Region:
Ref: ALIYUN::Region
UserName: e_commerce_user
Password:
Ref: DBPassword
StructureInitialization: true
DataInitialization: true
DataSynchronization: true
DbList:
e_commerce_website:
name: e_commerce_website
all: true
DependsOn:
- RdsDBInstance
- InstallWebsite
- PrepareLocalData
InstallWebsite:
Type: ALIYUN::ECS::RunCommand
Properties:
Sync: true
Type: RunShellScript
Timeout: 3600
InstanceIds:
- Ref: CloudWebSite_1
- Ref: CloudWebSite_2
- Ref: LocalWebSite
CommandContent:
Fn::Sub: |-
#!/bin/bash
set -e
yum -y install nginx php php-mysql php-fpm
cat > /etc/nginx/conf.d/e-commerce-website.conf << \EOF
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
cd /var/www/html
cat > index.html << \EOF
<!DOCTYPE html>
<html>
<head>
<title>电商网站首页</title>
<meta http-equiv="Conten-Type" content="text/html"; charset="utf-8">
<style>
/* 顶部导航栏 */
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
background-color: #ff4400;
color: #fff;
}
.logo h1 {
margin: 0;
font-size: 24px;
}
.logo p {
margin: 0;
font-size: 14px;
}
nav ul {
list-style: none;
display: flex;
}
nav ul li {
margin-right: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
font-size: 16px;
}
/* 主要内容 */
main {
padding: 20px;
}
.search-bar {
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
background-color: #fff;
margin-bottom: 20px;
}
.search-bar input[type="text"] {
padding: 5px;
width: 400px;
border: none;
border-radius: 20px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.search-bar button {
padding: 8px 15px;
background-color: #ff4400;
border: none;
color: #fff;
border-radius: 20px;
cursor: pointer;
}
/* 其他内容样式补充... */
.iframe-wrapper {
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.iframe-wrapper iframe {
border: none;
width: 100%;
height: 100%;
}
/* 底部 */
footer {
background-color: #333333;
color: #fff;
padding: 20px;
}
footer ul {
list-style: none;
display: flex;
justify-content: center;
margin: 0;
padding: 0;
}
footer ul li {
margin-right: 20px;
}
footer ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
</style>
</head>
<body>
<!-- 顶部导航栏 -->
<header>
<div class="logo">
<h1>网站Logo</h1>
<p>公司口号</p>
</div>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">产品分类</a></li>
<li><a href="#">特惠促销</a></li>
<li><a href="#">关于我们</a></li>
<li><a href="#">联系我们</a></li>
</ul>
</nav>
</header>
<!-- 主要内容 -->
<main>
<div class="featured-products">
<h2>特别推荐</h2>
<div class="iframe-wrapper">
<iframe src="mysql_demo.php"></iframe>
</div>
</div>
</main>
<!-- 底部 -->
<footer>
<ul>
<li><a href="#">关于我们</a></li>
<li><a href="#">联系我们</a></li>
<li><a href="#">帮助中心</a></li>
<li><a href="#">隐私政策</a></li>
</ul>
</footer>
</body>
</html>
EOF
cat > mysql_demo.php << \EOF
<?php
// 连接数据库
$host = "${RdsDBInstance.InnerConnectionString}";
$username = "e_commerce_user";
$password = "${DBPassword}";
$database = "e_commerce_website";
$conn = new mysqli($host, $username, $password, $database);
if ($conn->connect_error) {
die("数据库连接失败:" . $conn->connect_error);
}
// 查询商品数据
$query = "SELECT * FROM products";
$result = $conn->query($query);
// 构建商品信息的HTML
$productHTML = "";
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$productHTML .= '
<div>
<h3>商品名称:' . $row["name"] . '</h3>
<p>商品价格:' . $row["price"] . '元</p>
</div>
';
}
} else {
$productHTML = "没有找到任何商品。";
}
// 关闭数据库连接
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>商品列表</title>
<style>
/* 商品列表样式 */
.product-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 20px;
overflow: hidden;
}
.product {
border: 1px solid #ccc;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<div class="product-list">
<?php echo $productHTML; ?>
</div>
</body>
</html>
EOF
systemctl start php-fpm
systemctl enable php-fpm
systemctl start nginx
systemctl enable nginx
Outputs:
LocalAddress:
Description:
zh-cn: 本地网站访问地址。
en: Local website access address.
Value:
Fn::Sub: http://${Eip_1.EipAddress}
CloudWebsiteAddress:
Description:
zh-cn: 云网站访问地址。
en: Cloud website access address.
Value:
Fn::Sub: http://${Eip_0.EipAddress}
DBInstanceId:
Description:
zh-cn: RDS实例ID。
en: RDS instance id.
Value:
Fn::GetAtt:
- RdsDBInstance
- DBInstanceId
DtsJobId:
Description:
zh-cn: DTS任务名称。
en: DTS job name.
Value:
Fn::Sub: '<a href="https://dtsnew.console.aliyun.com/migrate/${ALIYUN::Region}" target="_blank">e-commerce-migration</a>'