一、.如何將LNMP拆分為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 -pwhf.com < /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/*
二、如何擴展多臺web節點,簡稱web集群
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.確保172.16.1.8 nginx配置 php配置 代碼 和 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
三、如何將多臺節點的靜態資源共享至NFS
1.準備172.16.1.31 nfs存儲服務器
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.找到web存儲的圖片所在的路徑 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
[root@web02 ~]# mount -t nfs 172.16.1.31:/data/blog /code/wordpress/wp-content/uploads
PS: 注意權限問題
[root@nfs ~]# chown -R www.www /data/
5.訪問網站 測試
關注作者,我會不定期在頭條分享Java,Spring,MyBatis,Netty源碼分析,高併發、高性能、分佈式、微服務架構的原理,JVM性能優化、分佈式架構,BATJ面試 等資料...
轉發此文,關注並私信小編“學習”web前端課程資料馬上免費領取
閱讀更多 前端你怎麼看 的文章