二.私有云基础架构
【项目概述】
经过云计算基础知识及核心技术的学习后,希望进一步了解 IT 基础架构的演变过
程,通过学习传统架构、集群架构以及私有云基础架构的相关知识,认识企业从传统 IT 基
础架构到私有云基础架构转型的必要性。
【项目实施】
任务2.1 传统架构下应用的部署
本 任 务 的 目 标 为 在 传 统 架 构 下 搭 建 LAMP
(Linux+Apache+MySQL/MariaDB+PHP,流行的开源软件组合)环境并部署
WordPress 服务,为了方便演示,本书在项目 1 安装好的单台 openEuler 22.09 系
统虚拟机中模拟。节点基础配置见表 2-1。
虚拟机版本 | 主机名 | IP地址 | 安装服务 |
openEuler 22.09 | web01 | 192.168.213.133 | Apache、PHP、MariaDB |
2.1.1基础环境准备
(1)配置静态IP地址
修改网卡配置文件,示例修改内容如下。
[root@web01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=a8c477c5-fdf7-46a2-b8ae-306495bc96dc DEVICE=ens33 ONBOOT=yes IPADDR="192.168.213.133" NETMASK="255.255.255.0" GATEWAY="192.168.213.2" DNS1="192.168.213.2" |
(2)配置yum源
打开/etc/yum.repos.d/openEuler.repo文件
把下面这段放进去
[root@web01 ~]# vi /etc/yum.repos.d/openEuler.repo |
[OS] name=OS baseurl=https://archives.openeuler.openatom.cn/openEuler-22.09/OS/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://archives.openeuler.openatom.cn/openEuler-22.09/OS/$basearch/RPM-GPG-KEY-openEuler [everything] name=everything baseurl=https://archives.openeuler.openatom.cn/openEuler-22.09/everything/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://archives.openeuler.openatom.cn/openEuler-22.09/everything/$basearch/RPM-GPG-KEY-openEuler [EPOL] name=EPOL baseurl=https://archives.openeuler.openatom.cn/openEuler-22.09/EPOL/main/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://archives.openeuler.openatom.cn/openEuler-22.09/OS/$basearch/RPM-GPG-KEY-openEuler [debuginfo] name=debuginfo baseurl=https://archives.openeuler.openatom.cn/openEuler-22.09/debuginfo/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://archives.openeuler.openatom.cn/openEuler-22.09/debuginfo/$basearch/RPM-GPG-KEY-openEuler [source] name=source baseurl=https://archives.openeuler.openatom.cn/openEuler-22.09/source/ enabled=1 gpgcheck=1 gpgkey=https://archives.openeuler.openatom.cn/openEuler-22.09/source/RPM-GPG-KEY-openEuler [update] name=update baseurl=https://archives.openeuler.openatom.cn/openEuler-22.09/update/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://archives.openeuler.openatom.cn/openEuler-22.09/OS/$basearch/RPM-GPG-KEY-openEuler |
清理yum缓存,并出现生成即可
[root@controller ~]# yum clean all [root@controller ~]# yum makecache [root@controller ~]# yum update |
(3)关闭防火墙
[root@web01 ~]# systemctl stop firewalld |
(4)关闭 SELinux
[root@web01 ~]# setenforce 0 |
2.1.2安装Apache服务
具体操作如下。
[root@web01 ~]# dnf install -y httpd [root@web01 ~]# systemctl enable --now httpd [root@web01 ~]# apachectl -v Server version: Apache/2.4.51 (Unix) Server built: Sep 7 2022 00:00:00 |
到浏览器输入虚拟机 IP 地址进行 Apache 访问测试,测试成功界面如图 2-5
所 示
。
2.1.3安装PHP服务
- 安装PHP及其模块
[root@web01 ~]# dnf -y install php php-common php-cli php-gd php-pdo php-devel php-xml php-mysqlnd |
- 编写测试界面文件
[root@web01 ~]# vi /var/www/html/php-test.php <?php phpinfo(); ?> |
重启 Apache 服务,并到浏览器中访问 http://192.168.213.133/php-test.php,PHP
测试成功界面如图 2-6 所示。
[root@web01 ~]# systemctl restart httpd |
2.1.4 安装并配置数据库服务
(1)安装软件包
[root@web01~]# dnf install mysql-config mariadb mariadb-server python3-PyMySQL |
(2)新增配置文件/etc/my.cnf.d/openstack.cnf,内容如下
[root@web01 ~]# cat /etc/my.cnf.d/openstack.cnf [mysqld] bind-address = 192.168.213.133 default-storage-engine = innodb innodb_file_per_table = on max_connections = 4096 collation-server = utf8_general_ci character-set-server = utf8 |
(3)启动服务器
[root@web01 ~]# systemctl start mariadb |
(4)初始化数据库
[root@web01 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] y New password: 000000 Re-enter new password: 000000 Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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? [Y/n] 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? [Y/n] y ... Success! By default, MariaDB 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? [Y/n] 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? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! |
(5)验证,根据设置的密码,检查是否能登录mariadb
[root@web01 ~]# mysql -uroot -p |
(6)创建数据库
创建WordPress数据库并开启root用户远程访问的权限。
MariaDB [(none)]> create database wordpress; Query OK, 1 row affected (0.000 sec) #创建用户(如果不存在) MariaDB [(none)]> CREATE USER 'root'@'%' IDENTIFIED BY 'secure_password123'; Query OK, 0 rows affected (0.001 sec) #授予权限 MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'%'; Query OK, 0 rows affected (0.001 sec) #刷新权限 MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.000 sec) #开启root用户远程访问的权限 MariaDB [(none)]> grant all privileges on wordpress.* to root@'%' identified by '000000'; Query OK, 0 rows affected (0.001 sec) |
2.1.5 安装WordPress
将从官网下载的 wordpress-6.7-zh_CN.zip文件传输到/root 目录下,然后
将压缩包解压到 Apache 网页文件夹中。
#安装unzip(仅限Centos/RHEL) [root@web01 ~]# yum install unzip -y #解压到Apache目录 [root@web01 ~]# unzip /root/wordpress-6.7-zh_CN.zip -d /var/www/html/ #验证解压结果 确保解压后生成wordpress子目录,且路径为/var/www/html/wordpress; [root@web01 ~]# ls -l /var/www/html/wordpress # 应看到 WordPress 的核心文件(如 wp-config-sample.php, wp-admin 等) |
对解压出来的 wordpress 文件夹赋予权限。
# 设置 http 根目录/var/www/的所有组为 apache [root@web01 ~]# chown -R :apache /var/www// # 设置 http 根目录/var/www 的所有者为 apache [root@web01 ~]# chown -R apache /var/www/ # 设置 http 根目录/var/www 的组下的所有用户具有读写权限 [root@web01 ~]# chmod -R 775 /var/www/ #重启服务 [root@web01 html]# systemctl restart httpd |
在浏览器中访问 http://192.168.213.133/wordpress 界面查看,可以访问到如图 2-
7 所示的 WordPress 测试界面。
图 2-7 WordPress 测试界面
接下来,输入数据库相关配置信息即可完成数据库连接,如图 2-8 所示。
图 2-8 连接数据库
数据库主机填这个 localhost
图 2-9 WordPress 数据库连接成功
自定义站点相关的表单,例如登录用户名及密码等,如图 2-10 所示。
图 2-10 WordPress 站点配置
至此,WordPress 部署成功,如图 2-11 所示。
图 2-11 WordPress 部署成功界面
任务2.2 集群架构下应用部署
为了进一步说明集群架构相较于传统架构的优越性,本任务在任务 2.1 的
基础上,安装三台 openEuler22.09 系统的虚拟机,拓展集群架构,完成
WordPress 应用部署。每台虚拟机所安装的服务及节点基础配置情况见表 2-2。
表 2-2 节点基础配置
虚拟机版本 | 主机名 | IP地址 | 安装服务 |
openEuler 22.09 | Web01 | 192.168.213.133 | Apache、PHP |
openEuler 22.09 | database | 192.168.213.134 | MariaDB |
openEuler 22.09 | web02 | 192.168.213.135 | Apache、PHP |
2.2.1基础环境准备
参照任务 2.1.1 中基础环境准备的部分,完成三台虚拟机基础环境配置,此
处不再赘述。
2.2.2服务安装
- 安装Mariadb服务
在 “ database” 节 点 安 装 MariaDB 服 务 并 设 置 root 用 户 密 码 , 创 建
“wordpress”数据库,具体操作参考任务 2.1 中的 2.1.4 小节配置数据库服务的
操作步骤,此处不再赘述。
2.安装WordPress
在 web01 节点、web02 节点安装 Apache、PHP 服务,然后部署 WordPress,
具体操作步骤参考任务 2.1 中的 2.1.5 小节中安装 WordPress 的内容,此处不再赘述。
3.部署 WordPress 时需要注意的一处是,在 web01 节点和 web02 节点数据库
连接信息的设置界面中,数据库主机均填写 database 节点的 IP,完整的填写示
例如图 2-12 所示。
图 2-12 配置数据库信息
上面数据库主机填写的是database节点的IP地址
3. web02 节点验证
在完成 web02 节点 WordPress 的部署后,使用浏览器进入 WordPress 界面, 同样进行数据库连接,会发现网页提示已安装过,如图 2-13 所示,这说明 web02 节点已经连接上了 database 节点的 MariaDB 数据库。
web02 节点验证成功,直接单击“登录”便可以正常访问站点,如图 2-14
所示。
即使把 web01 节点的 Apache 服务关闭,web02 节点的 WordPress 仍然正常
工作,如图 2-15 所示。
图 2-15 关闭 web01 节点后 web02 节点的测试界面
4. database 节点验证
在 database 节点,登录 MariaDB 数据库,查看数据库列表信息,如下所示。
[root@database ~]# mysql -uroot -p000000 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | wordpress | +--------------------+ 4 rows in set (0.000 sec) |
进入“wordpress”数据库查看表单详情,结果如下所示,发现 web01 和
web02 的用户数据已经录入数据库中,说明在集群架构下部署 WordPress 应用
是有效的。
MariaDB [(none)]> use wordpress; MariaDB [wordpress]> select * from wp_users; +----+------------+------------------------------------+---------------+------------------+----------------------------------+---------------------+---------------------+-------------+--------------+ | ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name | +----+------------+------------------------------------+---------------+------------------+----------------------------------+---------------------+---------------------+-------------+--------------+ | 1 | mys | $P$BC4Kd7fziAPag6BZaevzXvuory4ICl/ | mys | 445517363@qq.com | http://192.168.213.135/wordpress | 2025-02-28 07:34:04 | | 0 | mys | +----+------------+------------------------------------+---------------+------------------+----------------------------------+---------------------+---------------------+-------------+--------------+ 1 row in set (0.000 sec) |
喜欢的话给博主个一键三连呀,有问题可以一起交流学习呀,后续还有