1、拆分LNMP數(shù)據(jù)庫至獨立服務(wù)器概念
(1)為什么要進行數(shù)據(jù)庫的拆分
由于單臺服務(wù)器運行LNMP架構(gòu)會導(dǎo)致網(wǎng)站訪問緩慢,當(dāng)內(nèi)存被吃滿時,容易導(dǎo)致系統(tǒng)出現(xiàn)oom,從而kill掉MySQL數(shù)據(jù)庫,所以需要將web和數(shù)據(jù)庫進行獨立部署。
(2)數(shù)據(jù)庫拆分后解決了什么問題
1.緩解web網(wǎng)站的壓力
2.增強數(shù)據(jù)庫的讀寫性能
3.提高用戶訪問的速度
(3)數(shù)據(jù)庫拆分架構(gòu)演變過程
一體機
客戶端-------LNMP服務(wù)器
拆分?jǐn)?shù)據(jù)庫
客戶端--------Nginx+PHP服務(wù)器--------MySQL服務(wù)器
2、拆分wordpress數(shù)據(jù)庫至獨立服務(wù)器
(1)數(shù)據(jù)庫拆分環(huán)境規(guī)劃
主機名稱 應(yīng)用環(huán)境 IP地址
Server-1 nginx+php 192.168.2.4
client-1 mariadb 192.168.2.5
(2)備份192.168.2.4服務(wù)器上數(shù)據(jù)庫的數(shù)據(jù)
[root@Server-1 ~]# mysqldump -uroot -pP@ssw0rd --all-databases --single-transaction >mariadb-all.sql
#一定要檢查文件內(nèi)是否有數(shù)據(jù),因為失敗了也會有文件產(chǎn)生。
[root@Server-1 ~]#cat mariadb-all.sql
(3)傳輸192.168.2.4的備份數(shù)據(jù)至192.168.2.5的服務(wù)器上
[root@Server-1 ~]# scp mariadb-all.sql root@192.168.2.5:/code
(4)需要先在192.168.2.5服務(wù)器上安裝mariadb數(shù)據(jù)庫,然后使用命令進行還原。
#安裝mariadb數(shù)據(jù)庫客戶端和服務(wù)端
[root@Client-1 ~]# yum -y install mariadb mariadb-server
#啟動并加入開機自啟
[root@Client-1 ~]# systemctl enable mariadb
[root@Client-1 ~]# systemctl start mariadb
#導(dǎo)入數(shù)據(jù)庫信息,重啟數(shù)據(jù)庫
[root@Client-1 ~]# mysql
[root@Client-1 ~]# systemctl restart mariadb
#查看數(shù)據(jù)庫是否導(dǎo)入成功
[root@Client-1 ~]# mysql -uroot -pP@ssw0rd
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| edusoho |
| mysql |
| performance_schema |
| test |
| wecenter |
| wordpress |
+--------------------+
7 rows in set (0.01 sec)
(5)將web程序連接的本地數(shù)據(jù)庫修改到遠程數(shù)據(jù)庫上。
#先在本地192.168.2.4服務(wù)器上停止本地的數(shù)據(jù)庫
[root@Server-1 ~]# systemctl disable mariadb
[root@Server-1 ~]# systemctl stop mariadb
#在192.168.2.5的服務(wù)器上授權(quán)遠程主機能夠能連接數(shù)據(jù)庫
[root@Client-1 ~]# mysql -uroot -pP@ssw0rd
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by 'P@ssw0rd';
Query OK, 0 rows affected (0.02 sec)
#在192.168.2.4服務(wù)器上測試遠程賬戶能否連接192.168.2.5的數(shù)據(jù)庫
[root@Server-1 ~]# mysql -h 192.168.2.5 -uroot -pP@ssw0rd
MariaDB [(none)]>
#在192.168.2.4服務(wù)器上修改web程序wordpress連接數(shù)據(jù)庫的配置文件
[root@Server-1 ~]# vim /code/wordpress/wp-config.php
// ** MySQL 設(shè)置 - 具體信息來自您正在使用的主機 ** //
/** WordPress數(shù)據(jù)庫的名稱 */
define('DB_NAME', 'wordpress');
/** MySQL數(shù)據(jù)庫用戶名 */
define('DB_USER', 'root');
/** MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD', 'P@ssword');
/** MySQL主機 */
define('DB_HOST', '192.168.2.5');
#注:配置完直接訪問wordpress.zxc.com查看
3、拆分wecenter和edusoho數(shù)據(jù)庫至獨立服務(wù)器
(1)在192.168.2.4服務(wù)器上修改web程序wordpress連接數(shù)據(jù)庫的配置文件
#不知道數(shù)據(jù)庫配置文件,可以使用grep查找數(shù)據(jù)庫密碼來查看數(shù)據(jù)庫配置文件
[root@Server-1 wecenter]# grep -R "P@ssw0rd" *
system/config/database.php: 'password' => 'P@ssw0rd',
[root@Server-1 wecenter]# vim system/config/database.php
?php'charset'] = 'utf8mb4';
$config['prefix'] = 'aws_';
$config['driver'] = 'MySQLi';
$config['master'] = array (
'charset' => 'utf8mb4',
'host' => '192.168.2.5',
'username' => 'root',
'password' => 'P@ssw0rd',
'dbname' => 'wecenter',
);
$config['slave'] = false;
#注:配置完直接訪問wecenter.zxc.com查看
(2)在192.168.2.4服務(wù)器上修改web程序edusoho連接數(shù)據(jù)庫的配置文件
[root@Server-1 edusoho]# vim edusoho/app/config/parameters.yml
database_driver: pdo_mysql
database_host: 192.168.2.5
database_port: 3306
database_name: edusoho
database_user: root
database_password: 'P@ssw0rd'
#必須清理緩存
[root@Server-1 edusoho]# rm -rf /code/edusoho/edusoho/app/cache/*
#注:配置完直接訪問edu.zxc.com查看
4、擴展多臺web服務(wù)器集群
(1)為什么要擴展多臺web節(jié)點
?? 單臺web服務(wù)器能抗住的訪問量是有限的,配置多臺web服務(wù)器能提升更高的訪問速度。
(2)擴展多臺web解決了什么問題
1、單臺web節(jié)點故障,會導(dǎo)致業(yè)務(wù)down機
2、多臺web節(jié)點能夠保證業(yè)務(wù)的持續(xù)穩(wěn)定,擴展性高
3、多臺web節(jié)點能有效的提升用戶訪問網(wǎng)站的速度
(3)多臺web節(jié)點技術(shù)架構(gòu)組成,如下圖所示
(4)快速擴展一臺web
? ① 統(tǒng)一環(huán)境
#1、準(zhǔn)備對應(yīng)的www用戶
[root@Server-2 ~]# groupadd -g666 www
[root@Server-2 ~]# useradd -u666 -g666 www
#2、拷貝Server-1上面的yum倉庫
[root@Server-2 ~]# scp root@192.168.2.4:/etc/yum.repos.d/*.repo /etc/yum.repos.d/
#3、安裝nginx和php
[root@Server-2 ~]# 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
? ② 統(tǒng)一配置(同步Server-1上面的配置到Server-2)
#1、同步nginx
[root@Server-2 ~]# rsync -avz --delete root@192.168.2.4:/etc/nginx/ /etc/nginx/
[root@Server-2 ~]# nginx -t
[root@Server-2 ~]# systemctl enable nginx
[root@Server-2 ~]# systemctl start nginx
#2、同步php(/etc/php-fpm.conf /etc/php-fpm.d /etc/php.ini)
[root@Server-2 ~]# rsync -avz --delete root@192.168.2.4:/etc/php* /etc/
[root@Server-2 ~]# systemctl enable php-fpm
[root@Server-2 ~]# systemctl start php-fpm
#3、統(tǒng)一代碼
[root@Server-1 ~]# tar czf code.tar.gz /code #在Server-1上打包站點
[root@Server-1 ~]# scp code.tar.gz root@192.168.2.6:/tmp #在Server-1上將打包好的代碼發(fā)送給Server-2
[root@Server-2 ~]# tar xf /tmp/code.tar.gz -C / #在Server-2上進行解壓,并解壓到/目錄下
#4、配置解析進行訪問(把host上.4的注釋,復(fù)制改成.6)
缺點: 就是當(dāng)用戶上傳圖片、視頻附件等靜態(tài)資源僅上傳到一臺web服務(wù)器上,那么其他的web服務(wù)器則無法訪問到該圖片。
5、拆分靜態(tài)資源至獨立服務(wù)器
(1)為什么拆分靜態(tài)資源至獨立存儲服務(wù)器
????當(dāng)后端的web節(jié)點出現(xiàn)多臺時,會導(dǎo)致用戶上傳的圖片、視頻附件等內(nèi)容僅上傳到一臺web服務(wù)器上,那么其他的web服務(wù)器則無法訪問到該圖片。
(2)新增一臺NFS存儲解決了什么問題
1、保證了多臺web節(jié)點靜態(tài)資源一致。
2、有效節(jié)省多臺web節(jié)點的存儲空間。
3、統(tǒng)一管理靜態(tài)資源,便于后期推送至CDN進行靜態(tài)資源加速。
(3)多臺web節(jié)點技術(shù)架構(gòu)組成,如下圖所示
(4)快速擴展一臺web節(jié)點的環(huán)境規(guī)劃
主機名 應(yīng)用環(huán)境 IP地址
Server-1 Nginx+PHP 192.168.2.4
Server-2 Nginx+PHP 192.168.2.6
NFS NFS 192.168.2.7
MySQL MySQL 192.168.2.5
(5)快速擴展一臺web節(jié)點詳細步驟
? ① 準(zhǔn)備192.168.2.7共享存儲服務(wù)器,規(guī)劃目錄,配置好權(quán)限
#1、創(chuàng)建用戶
[root@nfs ~]# groupadd -g666 www
[root@nfs ~]# useradd -u666 -g666 www
#2、安裝
[root@nfs ~]# yum install nfs-utils -y
#3、配置
[root@nfs ~]# cat /etc/exports
/data/wordpress 192.168.2.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/wecenter 192.168.2.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/edu 192.168.2.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
#4、根據(jù)配置,創(chuàng)建目錄,準(zhǔn)備用戶,授權(quán)等等
[root@nfs ~]# rm -rf /data/
[root@nfs ~]# mkdir /data/{wordpress,wecenter ,edu} -p
[root@nfs ~]# chown -R www.www /data/
#5、啟動
[root@nfs ~]# systemctl enable nfs-utils
[root@nfs ~]# systemctl restart nfs-utils
? ② 將圖片較多的Server-2服務(wù)器,推送到nfs共享存儲上
#1、查看圖片右鍵保存鏈接,可看見上傳路徑
http://wordpress.zxc.com/wp-content/uploads/2022/03/timg.jpg
#2、把上傳文件夾推送到nfs共享存儲上
[root@Server-2 ~]# cd /code/wordpress/wp-content
[root@Server-2 wp-content]# scp -r uploads/* root@192.168.2.7:/data/wordpress/
注意:需要上nfs服務(wù)器上進行重新的遞歸授權(quán),否則會出現(xiàn)無法上傳文件的錯誤
[root@nfs ~]# chown -R www.www /data/
? ③ Server-1和Server-2分別都進行掛載,此時圖片進行實現(xiàn)了共享
mount -t nfs 192.168.2.7:/data/wordpress /code/wordpress/wp-content/uploads/
-
PHP
+關(guān)注
關(guān)注
0文章
454瀏覽量
27230 -
MYSQL數(shù)據(jù)庫
+關(guān)注
關(guān)注
0文章
96瀏覽量
9739 -
CDN網(wǎng)絡(luò)
+關(guān)注
關(guān)注
0文章
11瀏覽量
6878
發(fā)布評論請先 登錄
在AvaotaA1全志T527開發(fā)板上使用AvaotaOS 部署 LNMP 服務(wù)
nginx重啟命令linux步驟是什么?
nginx重啟命令linux步驟是什么?
【NanoPi NEO試用體驗】之安裝配置Nginx環(huán)境WEB網(wǎng)站詳解
Linux運維Nginx軟件優(yōu)化之Nginx性能優(yōu)化
nginx錯誤頁面配置
玩轉(zhuǎn)Firefly-RK3399資料匯總(一)
主要學(xué)習(xí)下nginx的安裝配置
Nginx架構(gòu)介紹 Nginx服務(wù)器模型分析

ECS配置lnmp的詳細步驟資料說明

Nginx目錄結(jié)構(gòu)有哪些

Nginx 如何實現(xiàn)高性能低消耗

評論