35-LNMP架构拆分

35-LNMP架构拆分


1

1.LNMP架构拆分:数据库
db01 10.0.0.51
web01 10.0.0.7
第一步准备一台10.0.0.51服务器
1.安装mariadb服务
[root@db01 ~]#yum -y install mariadb-server
2.启动mariadb 加入开机自启动
[root@db01 ~]#systemctl start mariadb
[root@db01 ~]#systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@db01 ~]#netstat -tunlp 
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 ~]# mysqldump -uroot -plzy123.com -A >all.sql
第三步:将all.sql拷贝到db01
[root@web01 ~]# scp all.sql 172.16.1.51:/root

第四步:db01服务器将all.sql导入到本地mariadb数据库
[root@db01 ~]#mysql -uroot < all.sql
[root@db01 ~]#systemctl restart mariadb			#重启数据库服务使密码生效

授权一个远程用户实现远程连接
[root@db01 ~]#mysql -uroot -plzy123.com
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.
# 使用以下命令授权远程用户lzy 管理所有的库和所有的表,密码为lzy123.com
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 ~]# systemctl stop mariadb
[root@web01 ~]# systemctl disable mariadb
Removed symlink /etc/systemd/system/multi-user.target.wants/mariadb.service.

测试远程连接数据库:
#先用root用户测试,远程不允许root用户登录数据库
[root@web01 ~]# mysql -h 172.16.1.51 -uroot -plzy123.com 
ERROR 1045 (28000): Access denied for user 'root'@'172.16.1.7' (using password: YES)
#再用授权用户lzy测试,使用授用户可以登录到远程db01的数据库
[root@web01 ~]# mysql -h 172.16.1.51 -ulzy -plzy123.com
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]# grep 'lzy123.com' ./ -r						#代码目录下-r递归查找
./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]# egrep 'DB_USER|DB_HOST' wordpress/wp-config.php 
define( 'DB_USER', 'lzy' );
define( 'DB_HOST', '172.16.1.51' );

访问业务进行测试:www.wp.com

修改phpshe业务数据库信息
[root@web01 code]# cat phpshe/config.php 
<?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 ~]#groupadd -g666 www
[root@web02 ~]#useradd -u666 -g666 -M -s /sbin/nologin www
[root@web02 ~]#id www
uid=666(www) gid=666(www) groups=666(www)
3.web02服务器部署nginx
[root@web01 code]# scp /etc/yum.repos.d/php.repo root@10.0.0.8:/etc/yum.repos.d/

4.web02服务器部署php
上传php71.tar.gz
解压
[root@web02 ~]#yum -y localinstall *.rpm
[root@web02 ~]#rpm -qa |grep php |wc -l
19
5.nginx配置无差异同步web01
rsync -avz --delete 172.16.1.7:/etc/nginx /etc		#将远端的nginx文件夹无差异同步到本地/etc目录下
6.php配置无差异同步web01
[root@web02 php-fpm.d]#rsync -avz 172.16.1.7:/etc/php-fpm.d/www.conf /etc/php-fpm.d/
7.web01将整个代码目录拷贝到web02
[root@web01 /]# tar -zcvf code.tar.gz code/
[root@web01 /]# scp code.tar.gz root@172.16.1.8:/
[root@web02 /]#tar -xf code.tar.gz
[root@web02 /]#ll -d /code
drwxr-xr-x 5 root root 314 Apr 18 09:11 /code
8.修改session目录权限
[root@web02 /]#chown www.www /var/lib/php/session/
[root@web02 /]#ll -d /var/lib/php/session/
drwxrwx--- 2 www www 6 Oct 26  2019 /var/lib/php/session/
9.启动服务
[root@web02 /]#systemctl start nginx php-fpm
[root@web02 /]#systemctl enable nginx php-fpm
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 ~]# yum -y install nfs-utils
3.配置nfs服务
[root@nfs ~]# cat /etc/exports
/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 ~]# groupadd -g666 www
[root@nfs ~]# useradd -u666 -g666 -M -s /sbin/nologin www
[root@nfs ~]# id www
uid=666(www) gid=666(www) groups=666(www)
[root@nfs ~]# mkdir -p /code/wp
[root@nfs ~]# mkdir -p /code/she
[root@nfs ~]# chown www.www /code/{wp,she}
[root@nfs ~]# ll -d /code/{wp,she}
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 ~]# systemctl start nfs
[root@nfs ~]# systemctl enable nfs

6.检查nfs服务
[root@nfs ~]# cat /var/lib/nfs/etab 
/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]# scp -r /code/wordpress/wp-content/uploads/2024 root@10.0.0.31:/code/wp
[root@web02 04]#scp -r /code/wordpress/wp-content/uploads/2024/04/* root@10.0.0.31:/code/wp/2024/04
3.客户端挂载查看图片
[root@web01 04]# mount -t nfs 172.16.1.31:/code/wp /code/wordpress/wp-content/uploads
[root@web02 04]#mount -t nfs 172.16.1.31:/code/wp /code/wordpress/wp-content/uploads
[root@web01 04]# df -h
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]# chown -R www.www /code/wp
浏览器测试

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

atomLg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值