华为云可以为您提供丰富的解决方案,现以搭建网站业务为例介绍华为云的应用场景。
小型网站一般会部署在单台服务器上,用户对页面的访问,动静态内容的使用,数据库的使用和计算全部是在一台服务器上完成的。当网站业务发展到中型规模时,数据库的访问量剧增,单台服务器配置已不能满足业务要求,此时,可将数据库和网站程序分开部署在不同的服务器上分担性能压力。
以使用华为云搭建某论坛网站为例,在这种场景下有以下需求:
- 将数据节点与业务节点分开部署在不同的服务器上。
- 可针对不同业务量动态调整服务器个数。
- 可自动将流量分发到多台服务器。
- 网站备案。
根据国家规定,如果客户网站所使用的服务器是在中国大陆,就需要进行ICP备案,没有备案的域名不能访问网站。如果使用国际版则不需要。
设计方案
针对应用场景的各项需求,使用华为云建站方案及所需服务
搭建网站:购买两台弹性云服务器代替传统服务器,分别作为网站的数据节点和基础业务节点。由虚拟私有云为弹性云服务器提供网络资源。购买服务器过程中,用户可以根据实际部署方案的要求,选择是否为云服务器挂载云硬盘作为数据盘。购买弹性云服务器,虚拟私有云,云硬盘(可选)。
目的:将数据节点与业务节点分开部署。
配置特性:根据业务需求和策略采用弹性伸缩,使用基础业务节点的镜像动态地调整作为业务节点的弹性云服务器实例个数,保证业务平稳健康运行。购买弹性伸缩。
目的:针对不同业务量动态调整服务器个数。
配置特性:使用负载均衡将访问流量自动分发到多台业务节点弹性云服务器,扩展应用系统对外的服务能力,实现更高水平的应用程序容错性能。购买弹性负载均衡。
目的:自动将流量分发到多台服务器。
架构图
- 为弹性云服务器1绑定弹性公网IP,搭建数据库。
- 先解绑弹性云服务器1上的弹性公网IP,再将弹性公网IP绑定至弹性云服务器2上,搭建Web环境并部署网站程序。
- 弹性伸缩可以根据业务量的变化,通过弹性云服务器2的镜像生成弹性伸缩组中的弹性云服务器。弹性伸缩组使用弹性负载均衡监听器。
- 网站访客通过弹性负载均衡服务的公网IP访问网站。弹性负载均衡服务将访问流量自动分发到多台弹性云服务器。
配置例子
搭建流程
准备软件-搭建数据库-搭建web环境-部署网站代码-验证搭建结果
准备软件
WinSCP-WinSCP是在Windows环境下使用SSH的开源图形化SFTP客户端,用于在本地与远程计算机间安全的复制文件。下载地址:WinSCP
Discuz X3.3软件包-请在Discuz官方网站下载Discuz X3.3(简体UTF8)软件包 ,用于部署网站程序。Discuz相关软件包和资料请官方网站在获取。
搭建数据库
安装MySQL
本文档以CentOS 7.2操作系统为例安装MySQL。
- 远程登录云服务器discuz01,填写用户名和密码。
- 依次执行以下命令,安装MySQL。
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server --nogpgcheck
配置MySQL
- 执行以下命令,启动MySQL服务。
systemctl enable mysqld
2.查看MySQL运行状态。
systemctl status mysqld.service
回显信息如下所示:
# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-08-23 10:54:55 CST; 7s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 7873 (mysqld)
CGroup: /system.slice/mysqld.service
└─7873 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 23 10:54:49 ecs-adc3-420652-aed6 systemd[1]: Starting MySQL Server...
Aug 23 10:54:55 ecs-adc3-420652-aed6 systemd[1]: Started MySQL Server.
3.执行以下命令,获取安装MySQL时自动设置的root用户密码。
grep 'temporary password' /var/log/mysqld.log
回显如下类似信息。
2021-08-16T11:33:37.790533Z 1 [Note] A temporary password is generated for root@localhost: ;8nPd29lhs,k
4.执行以下命令,并按照回显提示信息进行操作,加固MySQL。
Securing the MySQL server deployment.
Enter password for user root: #输入上一步骤中获取的安装MySQL时自动设置的root用户密码
The existing password for the user account root has expired. Please set a new password.
New password: #设置新的root用户密码
Re-enter new password: #再次输入密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N #是否更改root用户密码,输入N
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y #是否删除匿名用户,输入Y
Success.
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y #禁止root远程登录,输入Y
Success.
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y #是否删除test库和对它的访问权限,输入Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y #是否重新加载授权表,输入Y
Success.
All done!
5.执行以下命令,再根据提示输入数据库管理员root账号的密码进入数据库。
6.执行以下命令,使用MySQL数据库。
7.执行以下命令,查看用户列表。
说明:
此命令及以下数据库语句均以分号结尾,请勿忽略。
8.执行以下命令,刷新用户列表并允许所有IP对数据库进行访问。
update user set host='%' where user='root' LIMIT 1;
9.执行以下命令,强制刷新权限。允许同一子网中设置为允许访问的云服务器通过私有IP对MySQL数据库进行访问。
10.执行以下命令,退出数据库。
11.执行以下命令,重启MySQL服务。
12.执行以下命令,设置开机自动启动MySQL服务。
13.执行以下命令,关闭防火墙。
systemctl stop firewalld.service
14.重新查看防火墙状态是否为关闭。
搭建Web环境
安装Web环境
将弹性公网IP从云服务器discuz01上解绑,并绑定至云服务器discuz02上。
- 远程登录云服务器discuz02,填写用户名和密码。
- 依次执行以下命令,安装MySQL。
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server --nogpgcheck
3.执行以下命令,安装Apache服务器、PHPFastCGI管理器、MySQL客户端和MySQL数据库服务器。
yum install -y httpd php php-fpm mysql mysql-server php-mysql
回显如下,说明安装成功。
Complete!
4.执行以下命令,更新安装Apache服务器、PHPFastCGI管理器、MySQL客户端和MySQL数据库服务器。
yum reinstall -y httpd php php-fpm mysql mysql-server php-mysql
回显如下,更新安装成功。
Complete!
配置Web环境
1.执行以下命令,启动httpd服务。
2.执行以下命令,设置开机自动启动httpd服务。
3.执行以下命令,启动php-fpm服务。
4.执行以下命令,设置开机自动启动php-fpm服务。
5.执行以下命令,关闭防火墙。
systemctl stop firewalld.service
6.执行以下命令,重新查看防火墙状态是否为关闭。
7.执行以下命令,启动MySQL服务。
8.执行以下命令,设置开机自动启动MySQL服务。
systemctl enable mysqld.service
9.在浏览器中输入http://弹性公网IP地址 ,即可访问服务器的默认主页。
部署网站代码
- 在本地PC上解压缩“Discuz_X3.3_SC_UTF8.zip”至文件夹“Discuz_X3.3_SC_UTF8”。
- 使用WinSCP工具将文件夹“Discuz_X3.3_SC_UTF8”中的“update”文件夹中的文件上传至云服务器discuz02的“/var/www/html”路径下。具体操作请参考WinSCP相关使用文档。
- 默认只有root用户才有写权限,所以需要登录discuz02,执行以下命令将写权限赋予给其他用户。chmod -R 777 /var/www/html
- 在浏览器里输入地址:http://弹性公网IP地址进入安装界面。请按照Discuz安装向导进行安装。
- 数据库服务器地址即为discuz01的私有IP地址。
- 数据库密码是discuz01配置的数据库管理员root账号的密码。
验证搭建结果
在浏览器中输入:http://弹性公网IP地址/forum.php 可登录论坛主页则说明网站搭建成功。
欲知更多详情或购买流程请联系
Telegram:Moon_cloud9