二.私有云基礎架構
【項目概述】
經過云計算基礎知識及核心技術的學習后,希望進一步了解 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) |
喜歡的話給博主個一鍵三連呀,有問題可以一起交流學習呀,后續還有?