實現基於NFS共享的LAMP wordpress應用

實現基於NFS共享的LAMP wordpress應用

nfs服務器端配置

//下載安裝包
yum -y install nfs-utils

//啓動服務
systemctl start nfs

//創建共享目錄
mkdir -p /data/wordpress/webdata

------------------------------
//新建編輯共享子配置文件
vim /etc/exports.d/wp.exports

//文件內容爲
/data/wordpress/webdata   192.168.26.0/24(rw)

//重啓服務
systemctl restart nfs
-------------------------------

mysql_A服務器配置

//下載安裝包
yum -y isntall mariadb-server

//安全加固,設置密碼
mysql_secure_installation

//進入數據庫
mysql

//創建服務對應庫
CREATE DATABASE wordpress;

//創建訪問數據庫用戶並授予權限
GRANT ALL ON wordpress.* TO wordpress@'192.168.26.18' IDENTIFIED BY 'wordpress';

//創建有複製權限的用戶賬戶給次聯slave使用(用於主主複製)
GRANT REPLICATION SLAVE ON *.* TO repliuser@'192.168.26.%' IDENTIFIED BY 'centos';

//刷新用戶權限
FLUSH PRIVILEGES

mysql_B服務器配置

//下載安裝包
yum -y isntall mariadb-server

//安全加固,設置密碼
mysql_secure_installation

//進入數據庫
mysql

//創建服務對應庫
CREATE DATABASE wordpress;

//創建訪問數據庫用戶並授予權限
GRANT ALL ON wordpress.* TO wordpress@'192.168.26.28' IDENTIFIED BY 'wordpress';

//創建有複製權限的用戶賬戶給次聯slave使用(用於主主複製)
GRANT REPLICATION SLAVE ON *.* TO repliuser@'192.168.26.%' IDENTIFIED BY 'centos';

//刷新用戶權限
FLUSH PRIVILEGES

wordpress_A配置

//將wordpress5.3安裝包傳進虛擬主機
wordpress-5.3-zh_CN.tar.gz

//解包到指定目錄
tar xf wordpress-5.3-zh_CN.tar.gz -C /var/www/html

//目錄授權
chown -R /var/www/html/wordpress

//下載安裝包
yum -y install php-fpm php-mysqlnd php-json httpd

//啓動服務
systemctl start httpd

//新建wordpress下存放圖片的缺失文件
mkdir /var/www/html/wordpress/wp-content/uploads

//設置開機自動掛載共享目錄
echo "192.168.26.37:/data/wordpress/webdata	/var/www/html/wordpress/wp-content/uploads	nfs	_netdev	0 0" >> /etc/fstab

//手動掛載目錄立即生效
mount 192.168.26.37:/data/wordpress/webdata /var/www/html/wordpress/wp-content/uploads
----------------------------------------
//新建編輯httpd子配置文件
vim /etc/httpd/conf.d/wp.conf

//文件內容爲
DirectoryIndex index.php
<virtualhost *:80>
        ServerName "bokebi.A.org"
        DocumentRoot "/var/www/html/wordpress"
        <directory /var/www/html/wordpress>
                require all granted
        </directory>
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/wordpress/$1
</virtualhost>
-------------------------------------------

//編輯修改php子配置文件
;listen = /run/php-fpm/www.sock
listen = 127.0.0.1:9000

//重啓httpd服務
systemctl restart httpd

//啓動php服務
systemctl start php-fpm.service

wordpress_B配置

//將wordpress5.3安裝包傳進虛擬主機
wordpress-5.3-zh_CN.tar.gz

//解包到指定目錄
tar xf wordpress-5.3-zh_CN.tar.gz -C /var/www/html

//目錄授權
chown -R /var/www/html/wordpress

//下載安裝包
yum -y install php-fpm php-mysqlnd php-json httpd

//啓動服務
systemctl start httpd

//新建wordpress下存放圖片的缺失文件
mkdir /var/www/html/wordpress/wp-content/uploads

//設置開機自動掛載共享目錄
echo "192.168.26.37:/data/wordpress/webdata	/var/www/html/wordpress/wp-content/uploads	nfs	_netdev	0 0" >> /etc/fstab

//手動掛載目錄立即生效
mount 192.168.26.37:/data/wordpress/webdata /var/www/html/wordpress/wp-content/uploads
----------------------------------------
//新建編輯httpd子配置文件
vim /etc/httpd/conf.d/wp.conf

//文件內容爲
DirectoryIndex index.php
<virtualhost *:80>
        ServerName "bokebi.B.org"
        DocumentRoot "/var/www/html/wordpress"
        <directory /var/www/html/wordpress>
                require all granted
        </directory>
        ProxyRequests Off
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/wordpress/$1
</virtualhost>
-------------------------------------------

//編輯修改php子配置文件
;listen = /run/php-fpm/www.sock
listen = 127.0.0.1:9000

//重啓httpd服務
systemctl restart httpd

//啓動php服務
systemctl start php-fpm.service

windows端設置

//編輯windows端hosts文件
C:\Windows\System32\drivers\etc\hosts

//新增兩行
192.168.26.18   bokebi.A.org
192.168.26.28   bokebi.B.org

公共設置-按步驟設置

//訪問bokebi.A.org

按正常步驟完成安裝步驟

主要注意填寫連接數據庫的地址bokebi.A.org填寫爲192.168.26.47

//按正常步驟完成安裝步驟

主要注意填寫連接數據庫的地址bokebi.B.org填寫爲192.168.26.27

=========================================================

#mysql_A數據庫設置

vim /etc/my.cnf.d/server.cnf

//編輯配置文件添加以下數據

[mysqld]
server_id=17
log_bin
auto_increment_offset=1   #開始點
auto_increment_increment=2   #增長幅度
---------------------------------------
systemctl restart mariadb.service   #重啓其服務
---------------------------------------
//登錄mysql
[root@master ~]# mysql -u用戶名 -p密碼

//查看二進制日誌POS點
MariaDB [(none)]> SHOW MASTER LOGS;
+--------------------+-----------+
| Log_name           | File_size |
+--------------------+-----------+
| mariadb-bin.000001 |       245 |
+--------------------+-----------+
1 row in set (0.00 sec)

=========================================================

#mysql_B數據庫設置
vim /etc/my.cnf.d/server.cnf

//編輯配置文件添加以下數據

[mysqld]
server_id=27
log_bin
auto_increment_offset=2   #開始點
auto_increment_increment=2   #增長幅度
---------------------------------------
systemctl restart mariadb.service   #重啓服務
---------------------------------------
//登錄mysql
[root@master ~]# mysql -u用戶名 -p密碼

//查看change master to幫助,查找模板
MariaDB [(none)]> HELP CHANGE MASTER TO;

//修改數據執行change master to
MariaDB [(none)]> CHANGE MASTER TO
    ->   MASTER_HOST='192.168.26.47',
    ->   MASTER_USER='repliuser',
    ->   MASTER_PASSWORD='centos',
    ->   MASTER_PORT=3306,
    ->   MASTER_LOG_FILE='mariadb-bin.000001',
    ->   MASTER_LOG_POS=245,
    ->   MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected (0.01 sec)
----------------------------------------
MariaDB [(none)]> START SLAVE;   #開啓slave
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW SLAVE STATUS\G   #查看slave狀態
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.26.17
                  Master_User: repliuser
                  Master_Port: 3306
                Connect_Retry: 10
              Master_Log_File: mariadb-bin.000001
          Read_Master_Log_Pos: 406
               Relay_Log_File: mariadb-relay-bin.000003
                Relay_Log_Pos: 692
        Relay_Master_Log_File: mariadb-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 406
              Relay_Log_Space: 988
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 17
1 row in set (0.00 sec)
-------------------------------------
//查看次聯slave的POS點
MariaDB [(none)]> SHOW MASTER LOGS;
+--------------------+-----------+
| Log_name           | File_size |
+--------------------+-----------+
| mariadb-bin.000001 |       245 |
+--------------------+-----------+
1 row in set (0.00 sec)

=========================================================

#mysql_A進行進一步設置

//查看change master to幫助,查找模板
MariaDB [(none)]> HELP CHANGE MASTER TO;

//修改數據執行change master to
MariaDB [(none)]> CHANGE MASTER TO
    ->   MASTER_HOST='192.168.26.27',
    ->   MASTER_USER='repliuser',
    ->   MASTER_PASSWORD='centos',
    ->   MASTER_PORT=3306,
    ->   MASTER_LOG_FILE='mariadb-bin.000001',
    ->   MASTER_LOG_POS=245,
    ->   MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected (0.01 sec)
-------------------------------------
MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.26.27
                  Master_User: repliuser
                  Master_Port: 3306
                Connect_Retry: 10
              Master_Log_File: mariadb-bin.000001
          Read_Master_Log_Pos: 245
               Relay_Log_File: mariadb-relay-bin.000002
                Relay_Log_Pos: 531
        Relay_Master_Log_File: mariadb-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 245
              Relay_Log_Space: 827
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 27
1 row in set (0.00 sec)

測試實驗結果

  • 瀏覽器訪問bokebi.A.org 登陸賬號

在這裏插入圖片描述

在這裏插入圖片描述

  • 登錄管理站點

在這裏插入圖片描述

  • 編輯新建文章,連續點兩次發佈文章

在這裏插入圖片描述

  • 瀏覽器訪問bokebi.B.org 登陸能查看bokebi.A.org站點創建上傳的文章

在這裏插入圖片描述

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章