35-LNMP架构拆分
1.LNMP架构拆分:数据库
db01 10.0.0.51
web01 10.0.0.7
第一步准备一台10.0.0.51服务器
1.安装mariadb服务
[root@db01 ~]
2.启动mariadb 加入开机自启动
[root@db01 ~]
[root@db01 ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@db01 ~]
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1294/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1455/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2491/mysqld
第二步:将web01上的数据库所有的内容导出到all.sql
[root@web01 ~]
第三步:将all.sql拷贝到db01
[root@web01 ~]
第四步:db01服务器将all.sql导入到本地mariadb数据库
[root@db01 ~]
[root@db01 ~]
授权一个远程用户实现远程连接
[root@db01 ~]
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all on *.* to lzy@'%' identified by 'lzy123.com';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
第五步:web01服务器修改业务代码数据信息指向db01
[root@web01 ~]
[root@web01 ~]
Removed symlink /etc/systemd/system/multi-user.target.wants/mariadb.service.
测试远程连接数据库:
[root@web01 ~]
ERROR 1045 (28000): Access denied for user 'root'@'172.16.1.7' (using password: YES)
[root@web01 ~]
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>quit
Bye
6.修改代码中的数据库连接配置信息
先查找到数据库配置信息在哪个文件中
[root@web01 code]
./wordpress/wp-config.php:define( 'DB_PASSWORD', 'lzy123.com' );
./webcenter/system/config/database.php: 'password' => 'lzy123.com',
./phpshe/config.php:$pe['db_pw'] = 'lzy123.com'; //数据库密码
[root@web01 code]
define( 'DB_USER', 'lzy' );
define( 'DB_HOST', '172.16.1.51' );
访问业务进行测试:www.wp.com
修改phpshe业务数据库信息
[root@web01 code]
<?php
$pe['db_host'] = '172.16.1.51'; //数据库主机地址
$pe['db_name'] = 'phpshe'; //数据库名称
$pe['db_user'] = 'lzy'; //数据库用户名
$pe['db_pw'] = 'lzy123.com'; //数据库密码
$pe['db_coding'] = 'utf8';
$pe['url_model'] = 'pathinfo_safe'; //url模式,可选项(pathinfo/pathinfo_safe/php)
$pe['h5_host'] = ''; //手机版网址
define('dbpre','pe_'); //数据库表前缀
2.LNMP架构拆分:扩展web服务
web01 10.0.0.7
web02 10.0.0.8
db01 10.0.0.51
1.准备一台web02
2.创建虚拟用户www
[root@web02 ~]
[root@web02 ~]
[root@web02 ~]
uid=666(www) gid=666(www) groups=666(www)
3.web02服务器部署nginx
[root@web01 code]
4.web02服务器部署php
上传php71.tar.gz
解压
[root@web02 ~]
[root@web02 ~]
19
5.nginx配置无差异同步web01
rsync -avz --delete 172.16.1.7:/etc/nginx /etc
6.php配置无差异同步web01
[root@web02 php-fpm.d]
7.web01将整个代码目录拷贝到web02
[root@web01 /]
[root@web01 /]
[root@web02 /]
[root@web02 /]
drwxr-xr-x 5 root root 314 Apr 18 09:11 /code
8.修改session目录权限
[root@web02 /]
[root@web02 /]
drwxrwx--- 2 www www 6 Oct 26 2019 /var/lib/php/session/
9.启动服务
[root@web02 /]
[root@web02 /]
10.测试服务
Windows做域名解析浏览器访问www.wp.com www.she.com
3.配置nfs服务
10.0.0.7 web01 客户端
10.0.0.8 web02 客户端
10.0.0.31 nfs NFS服务器
1.准备一台NFS服务器
10.0.0.31
2.安装nfs服务
[root@web01 ~]
3.配置nfs服务
[root@nfs ~]
/code/wp 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/code/she 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
4.创建必要数据
[root@nfs ~]
[root@nfs ~]
[root@nfs ~]
uid=666(www) gid=666(www) groups=666(www)
[root@nfs ~]
[root@nfs ~]
[root@nfs ~]
[root@nfs ~]
drwxr-xr-x 2 www www 6 Apr 18 20:17 /code/she
drwxr-xr-x 2 www www 6 Apr 18 20:17 /code/wp
5.启动nfs服务
[root@nfs ~]
[root@nfs ~]
6.检查nfs服务
[root@nfs ~]
/code/she 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)
/code/wp 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)
客户端挂载:
1.web01和web02都安装nfs-utils但是不启动服务
yum install -y nfs-utils
2.将web01和web02上本地本地磁盘上的图片推送到nfs服务器
[root@web01 04]
[root@web02 04]
3.客户端挂载查看图片
[root@web01 04]
[root@web02 04]
[root@web01 04]
Filesystem Size Used Avail Use% Mounted on
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda3 18G 2.6G 16G 15% /
/dev/sda1 197M 110M 88M 56% /boot
tmpfs 199M 0 199M 0% /run/user/0
172.16.1.31:/code/wp 18G 2.0G 16G 12% /code/wordpress/wp-content/uploads
4.修改NFS上共享目录的权限
[root@nfs 04]
浏览器测试