实现基于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站点创建上传的文章

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值