How LNMP split into LNP + MySQL

1.备份172.16.1.7上的数据库信息
[root@web01 ~]# mysqldump -uroot -p'oldxu.com' --all-databases > mysql-all.sql

2.将172.16.1.7 上的数据推送至172.16.1.51
[root@web01 ~]# scp mysql-all.sql [email protected]:/tmp

3.登录172.16.1.51 恢复数据  ()
[root@db01 ~]# yum install mariadb mariadb-server -y
[root@db01 ~]# systemctl enable mariadb
[root@db01 ~]# systemctl start mariadb

读取sql文件至数据库中
[root@db01 ~]# mysql -uroot < /tmp/mysql-all.sql
[root@db01 ~]# systemctl restart mariadb

配置一个远程用户,允许其他服务器能通过远程的方式连接
MariaDB [(none)]> grant all privileges on *.* to 'all'@'%' identified by 'oldxu.com';
MariaDB [(none)]> flush privileges;
​4.将 172.16.1.7 程序连接本地的数据库,修改为远程的数据库    ( 应用割接 )
​[root@web01 ~]# systemctl disable mariadb
​[root@web01 ~]# systemctl stop mariadb

wordpress ​[root@web01 wordpress]# find ./ -type f | xargs grep "oldxu.com" ​./wp-config.php:define( 'DB_PASSWORD', 'oldxu.com' );

/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );

/** MySQL数据库用户名 */
define( 'DB_USER', 'all' );

/** MySQL数据库密码 */
define( 'DB_PASSWORD', 'oldxu.com' );

/** MySQL主机 */
define( 'DB_HOST', '172.16.1.51' );

wecenter
[root@web01 zh]# find ./ -type f  | xargs grep "oldxu.com"
./system/config/database.php:  'password' => 'oldxu.com',

edusoho
[root@web01 edusoho]# find ./ -type f  | xargs grep "oldxu.com"
./app/config/parameters.yml

清理缓存
[root@web01 edusoho]# rm -rf /code/edusoho/app/cache/*

22. How to extend more than one web node, referred to as web cluster

1.准备一台172.16.1.8的服务器
2.确保172.16.1.8 上安装了 Nginx PHP
yum -y install nginx php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb


3. Make sure 172.16.1.8 nginx php configuration code and configuration consistent 172.16.1.7

    1.创建用户和用户组
    [root@web02 ~]# groupadd -g 666 www
    [root@web02 ~]# useradd -u666 -g666 www

    2.切到172.16.1.7 上执行如下操作
    [root@web01 ~]# rsync -avz --delete  /etc/nginx [email protected]:/etc/
    [root@web01 ~]# rsync -avz --delete  /etc/php.ini [email protected]:/etc/
    [root@web01 ~]# rsync -avz --delete  /etc/php-fpm.d [email protected]:/etc/
    
        3.打包代码
        [root@web01 ~]# tar czf code.tar.gz /code
    
        4.拷贝代码
        [root@web01 ~]# scp code.tar.gz [email protected]:/tmp
    3.回到172.16.1.8  然后解包  授权  重启服务,并加入开机自启
        [root@web02 ~]# tar xf /tmp/code.tar.gz -C /
        [root@web02 ~]# systemctl restart nginx php-fpm
        [root@web02 ~]# systemctl enable nginx php-fpm

23. How will multiple nodes of static resources to NFS share

1. Prepare 172.16.1.31 nfs server storage

    1) 安装
    [root@nfs ~]# yum install nfs-utils -y
    
    2) 配置
    [root@nfs ~]# cat /etc/exports
    /data/blog 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
    /data/edu 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
    /data/zh 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

    3) 初始化环境
    [root@nfs ~]# mkdir -p /data/{blog,zh,edu}
    [root@nfs ~]# groupadd -g 666 www
    [root@nfs ~]# useradd -u666 -g666 www
    [root@nfs ~]# chown -R www.www /data/

    4) 启动
    [root@nfs ~]# systemctl enable nfs
    [root@nfs ~]# systemctl restart nfs


3. Locate the web path where the picture was stored http://blog.oldxu.com/wp-content/uploads/2019/09/tt.jpeg

[root@web01 wp-content]# mv uploads/ uploads_bak
[root@web01 wp-content]# scp -rp uploads_bak/* [email protected]:/data/blog/
[root@web01 wp-content]# mkdir uploads

4.在 172.16.1.7 172.16.1.8 ....  应用服务器上进行挂载
[root@web01 wp-content]# mount -t nfs 172.16.1.31:/data/blog /code/wordpress/wp-content/uploads


PS: Note that permission problems
[root @ nfs ~] # chown -R www.www / data /

4.访问网站 测试

Question 1: If we added a 172.16.1.9 application server, how to achieve rapid expansion?
1. Prepare LNP environment
2. Obtain the PHP configuration file Nginx
3. obtain project code
4. mount NFS storage

Question 2: There are multiple WEB servers, how to access?

解决方法一:  DNS轮询 DNS---> 多个IP
    1.所有的web节点都必须有公网IP      -->成本增加
    2.所有的web节点都有公网IP            -->安全无法保证
    
解决方法二: 反向代理
    1.所有web应用不需要有公网IP地址     -->成本降低
    2.只对外暴露一个公网IP,安全可控  -->安全可控

Guess you like

Origin www.cnblogs.com/baozexu/p/11568884.html