一、实验需求
本次实验内容基于华为云平台模拟企业web集群的构建,其中涉及的知识点包括Linux系统知识、nginx服务的安装及配置应用、云数据库 RDS(Relational Database Service,简称RDS)、虚拟私有云vpc、安全组、SFS弹性文件服务器以及负载均衡等。要求学生通过本次实训掌握web集群的技术特点及实现方法。
二、实验拓扑

三、地址规划
|---------------|------------|-----------------|-----------|
| IP地址 | 主机名 | 系统 | 角色 |
| 192.168.10.11 | ecs-web001 | openEuler 22.03 | 应用服务器 |
| 192.168.10.12 | ecs-web002 | openEuler 22.03 | 应用服务器 |
| 192.168.10.13 | ecs-web003 | openEuler 22.03 | 应用服务器 |
| 192.168.10.14 | | | 数据库服务器 |
| 192.168.10.15 | | | SFS(共享存储) |
| | | | 负载均衡器 |
四、实验步骤
任务一:创建虚拟私有云vpc





创建好后如下图所示

任务二:申请三台云服务器ECS






网络配置

高级配置


创建好如下图所示

任务三:购买数据库实例RDS








购买好后如下图示:

创建安全组,放行3306端口




添加安全组




登录数据库测试



任务四:购买弹性文件服务SFS
弹性文件服务提供按需扩展的高性能文件存储(NAS),可为云上多个弹性云服务器(Elastic Cloud Server,ECS),容器(CCE&CCI),裸金属服务器(BMS)提供共享访问。





创建好如如下图所示

任务五:部署CMS系统
1、准备LNMP环境。
1> 购买一个公网IP (EIP)





创建好如如下图所示

2> 绑定web1


shell链接公网ip:


下载nginx和php:
[root@ecs-web-0001 ~]# yum install nginx php php-mysqlnd -y
#测试nginx和php协同
[root@ecs-web-0001 ~]# cd /usr/share/nginx/html/
[root@ecs-web-0001 html]# vim test.php
<?php
phpinfo();
?>
启动nginx
[root@ecs-web-0001 html]# systemctl enable --now nginx


安全组规则放行80端口。
创建安全组




云服务加入安全组
三个web都需要添加


测试协同

3> 挂载共享存储
/usr/share/nginx/html 挂载
查看挂载命令:


临时挂载
[root@ecs-web-0001 ~]# mount -t nfs -o vers=3,nolock,noresvport 61a7c02c-2708-4a0e-81b2-6b1454815690.sfsturbo.internal:/ /usr/share/nginx/html/
[root@ecs-web-0001 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 731M 0 731M 0% /dev/shm
tmpfs 293M 4.2M 289M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/vda1 40G 3.0G 35G 8% /
tmpfs 731M 0 731M 0% /tmp
61a7c02c-2708-4a0e-81b2-6b1454815690.sfsturbo.internal:/ 1.2T 0 1.2T 0% /usr/share/nginx/html

永久挂载
[root@ecs-web-0001 ~]# vim /etc/fstab
# 添加
61a7c02c-2708-4a0e-81b2-6b1454815690.sfsturbo.internal:/ /usr/share/nginx/html/ nfs vers=3,nolock,noresvport 0 0
[root@ecs-web-0001 ~]# mount -a


4> 上传应用代码


[root@ecs-web-0001 ~]# ll
total 7968
-rw-r--r-- 1 root root 8157155 Sep 19 15:35 XunRuiCMS-Study.zip
# 解压
[root@ecs-web-0001 ~]# unzip XunRuiCMS-Study.zip -d /usr/share/nginx/html/
5> 应用环境监测

[root@ecs-web-0001 ~]# yum install php-xml php-mbstring php-gd -y
6> 在线安装
[root@ecs-web-0001 html]# vim /etc/nginx/nginx.conf
server_name localhost; 将原有的 server_name _t; 修改为localhost
重启服务
[root@ecs-web-0001 html]# systemctl restart nginx php-fpm

浏览器直接访问:1.94.216.71



7> 配置数据库
注意:数据库安全组放行3306端口

创建一个数据库

创建一个用户:
使用命令行创建的方法:
MySQL [(none)]> create user cms@'192.168.8.%' identified by 'Cms@123456';
Query OK, 0 rows affected (0.016 sec)
MySQL [(none)]> grant all on cms.* to cms@'192.168.8.%';
Query OK, 0 rows affected (0.001 sec)
也可以在云上直接创建:






其他两台web服务器操作:
一个是准备lnmp环境
二是挂载共享存储
先把公网ip依次分给另外两个主机



shell登录

[root@ecs-web-0002 ~]# yum install nginx php php-gd php-mbstring php-xml php-mysqlnd -y
[root@ecs-web-0002 ~]# vim /etc/fstab
# 添加
61a7c02c-2708-4a0e-81b2-6b1454815690.sfsturbo.internal:/ /usr/share/nginx/html/ nfs vers=3,nolock,noresvport 0 0
[root@ecs-web-0002 ~]# mount -a
[root@ecs-web-0002 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 731M 0 731M 0% /dev/shm
tmpfs 293M 4.2M 289M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/vda1 40G 3.0G 35G 8% /
tmpfs 731M 0 731M 0% /tmp
61a7c02c-2708-4a0e-81b2-6b1454815690.sfsturbo.internal:/ 1.2T 31M 1.2T 1% /usr/share/nginx/html
[root@ecs-web-0003 ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.


测试一下

web3也是以上操作
8>配置负载均衡





查看

9>添加监听


配置后端分配策略

添加后端服务器组





查看:

测试:
