分散式部署LNMP+WordPress

2020-10-28 11:00:59

nginx服務部署

首先,我們用以前搭建的虛擬機器器,他們分別是:
①連線到→主從資料庫
②連線到→Nginx
③連線到→PHP

①nginx節點設定

[root@nginx ~]# vi /usr/local/nginx/conf/nginx.conf
#access_log  logs/host.access.log  main;

   location / {
            root   /www;                            #更改網頁目錄
            index  index.php index.html index.htm;       #新增index.php
        }
        ....(此處省略部分)

   location ~ \.php$ {                   #去掉location前面的註釋
            root     /www;         #更改目錄為/www
            fastcgi_pass   192.168.128.42:9000;      #這裡新增PHP主機地址
            #IP地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

在這裡插入圖片描述

[root@nginx ~]# vi /usr/local/nginx/conf/fastcgi_params

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
#檔案中新增上面這一行程式碼
fastcgi_param  REQUEST_URI        $request_uri;

②建立使用者和使用者組

事先用檔案傳輸工具(博主用的是xftp)將wordpress安裝包放到nginx節點和PHP節點/usr/local/src目錄下
wordpress安裝包連結(這裡我們用的版本為wordpress-4.7.3)
連結:https://pan.baidu.com/s/12c7fjyVBvknzh0lp_PRHYg
提取碼:4730

Nginx節點

[root@nginx ~]# mkdir /www           #建立目錄
[root@nginx ~]# chown nginx:nginx /www/    #修改使用者和使用者組為nginx
[root@nginx ~]# yum -y install unzip      #安裝解壓工具
[root@nginx ~]# unzip wordpress-4.7.3-zh_CN.zip 
[root@nginx ~]# mv wordpress/* /www/      #移動檔案

PHP節點

[root@php ~]# mkdir /www
[root@php ~]# chown nginx:nginx /www/     #修改使用者和使用者組為nginx

[root@php ~]# yum -y install unzip
[root@php ~]# unzip wordpress-4.7.3-zh_CN.zip 
[root@php ~]# mv wordpress/* /www/

③設定wordpress檔案

nginx節點

[root@nginx ~]# cp /www/wp-config-sample.php /www/wp-config.php   (重新命名)
[root@nginx ~]# vi /www/wp-config.php  
按照以下進行修改
// ** MySQL 設定 - 具體資訊來自您正在使用的主機 ** //
/** WordPress資料庫的名稱 */
define('DB_NAME', 'wordpress');         (資料庫名稱)

/** MySQL資料庫使用者名稱 */
define('DB_USER', 'root');              (資料庫使用者)

/** MySQL資料庫密碼 */
define('DB_PASSWORD', 'SICT');          (資料庫密碼)

/** MySQL主機 */
define('DB_HOST', '192.168.128.111');   (主資料庫ip)

/** 建立資料表時預設的文字編碼 */
define('DB_CHARSET', 'utf8');           (資料庫編碼)

/** 資料庫整理型別。如不確定請勿更改 */
define('DB_COLLATE', '');

改完的組態檔直接傳到PHP節點

[root@nginx ~]# scp /www/wp-config.php root@192.168.128.144:/www/      (PHP節點ip地址)
      (scp進PHP節點)
The authenticity of host '192.168.128.144 (192.168.128.144)' can't be established.
ECDSA key fingerprint is 43:9c:67:d7:3f:06:53:60:43:d4:41:5f:af:3a:67:01.
Are you sure you want to continue connecting (yes/no)? yes   (確認是否進行連線)
Warning: Permanently added '192.168.128.144' (ECDSA) to the list of known hosts.
root@192.168.128.144's password:       (PHP節點的密碼)
wp-config.php                                                     100% 2909     2.8KB/s   00:00   (傳輸進度)

④資料庫節點設定

主資料庫節點

[root@mysql0 ~]# mysql -uroot -pSICT
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.44-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@mysql0 ~]# 

⑤驗證WordPress應用

Nginx節點
[root@nginx ~]# nginx -s reload

在瀏覽器中鍵入nginx地址
在這裡插入圖片描述
出現著名的WordPress五分鐘安裝程式,填寫必要的資訊,然後單擊左下角「安裝 WordPress」按鈕,進行 WordPress應用的安裝。