微信開放平臺登錄好口碑的關(guān)鍵詞優(yōu)化
簡介
? NFS 是Network File System的縮寫,即網(wǎng)絡(luò)文件系統(tǒng)。一種使用于分散式文件系統(tǒng)的協(xié)定,由Sun公司開發(fā),于1984年向外公布。功能是通過網(wǎng)絡(luò)讓不同的機器、不同的操作系統(tǒng)能夠彼此分享個別的數(shù)據(jù),讓應(yīng)用程序在客戶端通過網(wǎng)絡(luò)訪問位于服務(wù)器磁盤中的數(shù)據(jù),是在類Unix系統(tǒng)間實現(xiàn)磁盤文件共享的一種方法。
? NFS 的基本原則是“容許不同的客戶端及服務(wù)端通過一組RPC分享相同的文件系統(tǒng)”,它是獨立于操作系統(tǒng),容許不同硬件及操作系統(tǒng)的系統(tǒng)共同進行文件的分享。
? NFS在文件傳送或信息傳送過程中依賴于RPC協(xié)議。RPC,遠程過程調(diào)用 (Remote Procedure Call) 是能使客戶端執(zhí)行其他系統(tǒng)中程序的一種機制。NFS本身是沒有提供信息傳輸?shù)膮f(xié)議和功能的,但NFS卻能讓我們通過網(wǎng)絡(luò)進行資料的分享,這是因為NFS使用了一些其它的傳輸協(xié)議。而這些傳輸協(xié)議用到這個RPC功能的??梢哉fNFS本身就是使用RPC的一個程序?;蛘哒fNFS也是一個RPC SERVER。所以只要用到NFS的地方都要啟動RPC服務(wù),不論是NFS SERVER或者NFS CLIENT。這樣SERVER和CLIENT才能通過RPC來實現(xiàn)PROGRAM PORT的對應(yīng)??梢赃@么理解RPC和NFS的關(guān)系:NFS是一個文件系統(tǒng),而RPC是負責(zé)負責(zé)信息的傳輸。
參考:https://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html
網(wǎng)站數(shù)據(jù)的一致性--》NFS服務(wù)器
壓力測試--》ab
監(jiān)控 --》zabbix
為什么需要nfs服務(wù)器?
? 保障網(wǎng)站數(shù)據(jù)的一致性--》不管負載均衡器將請求分配到那臺后端的服務(wù)器,客戶機看到的內(nèi)容是一樣。
nfs服務(wù)器是否是最佳的解決方法?
? 答案: 不是的
? ? ? ? nfs是比較廉價的解決方法,一般的公司不會采用,性能不是特別棒,建議使用專用的存儲服務(wù)器。
存儲服務(wù)器?
SAN
? 優(yōu)點:讀寫性能好,有災(zāi)備
? ? SAN:區(qū)域存儲網(wǎng)絡(luò)
? ? 存儲區(qū)域網(wǎng)絡(luò)(Storage Area Network,簡稱SAN)采用網(wǎng)狀通道(Fibre Channel ,簡稱FC,區(qū)別與Fiber Channel光纖通道)技術(shù),通過FC交換機連接存儲陣列和服務(wù)器主機,建立專用于數(shù)據(jù)存儲的區(qū)域網(wǎng)絡(luò)。
? 缺點: 需要一筆費用
NAS
NAS(Network Attached Storage)網(wǎng)絡(luò)存儲基于標準網(wǎng)絡(luò)協(xié)議實現(xiàn)數(shù)據(jù)傳輸,為網(wǎng)絡(luò)中的Windows / Linux / Mac OS 等各種不同操作系統(tǒng)的計算機提供文件共享和數(shù)據(jù)備份。
? ? ? ? 比較便宜使用tcp/ip網(wǎng)絡(luò)協(xié)議,在日常的生活和工作里使用,例如:可以將所有手機,電腦里的圖片集中存儲。
? ? ? ? 小型帶系統(tǒng)的存儲設(shè)備
nfs是什么?
?網(wǎng)絡(luò)文件系統(tǒng),英文Network File System(NFS),是由SUN公司研制的UNIX表示層協(xié)議(presentation layer protocol),能使使用者訪問網(wǎng)絡(luò)上別處的文件就像在使用自己的計算機一樣。
nfs解決了什么問題?
? 數(shù)據(jù)同源: 到同一個地方去拿數(shù)據(jù),保障數(shù)據(jù)的一致性
nfs的優(yōu)點和缺點
? 優(yōu)點: 隨便一臺linux服務(wù)器都可以搭建,成本非常低,構(gòu)建非常容易
? 缺點: 讀取速度有限,跟網(wǎng)絡(luò)質(zhì)量,磁盤IO,cpu,內(nèi)存等因素有關(guān),在傳統(tǒng)的tcp/ip網(wǎng)絡(luò)上傳輸?shù)?br /> ?
原理
?權(quán)限的選項
[root@nfs-server ~]# vim /etc/exports/web 192.168.0.0/24(rw,all_squash,sync)
/web 是我們共享的文件夾的路徑--》使用絕對路徑
192.168.0.0/24 允許過來訪問的客戶機的ip地址網(wǎng)段
(rw,all_squash,sync) 表示權(quán)限的限制 rw 表示可讀可寫 read and writero 表示只能讀 read-onlyall_squash :任何客戶機上的用戶過來訪問的時候,都把它認為是普通的用戶root_squash 當(dāng)NFS客戶端以root管理員訪問時,映射為NFS服務(wù)器匿名用戶no_root_squash 當(dāng)NFS客戶端以root管理員訪問時,映射為NFS服務(wù)器的root管理員sync 同時將數(shù)據(jù)寫入到內(nèi)存與硬盤中,保證不丟失數(shù)據(jù)async 優(yōu)先將數(shù)據(jù)保存到內(nèi)存,然后再寫入硬盤,效率更高,但可能丟失數(shù)據(jù)
搭建過程
1.安裝nfs的相關(guān)軟件
[root@nfs-server ~]# yum install nfs-utils -y
2.啟動nfs-server服務(wù)
[root@nfs-server ~]# service nfs-server stop
Redirecting to /bin/systemctl stop nfs-server.service
[root@nfs-server ~]# service nfs-server start
Redirecting to /bin/systemctl start nfs-server.service
[root@nfs-server ~]# service nfs-server restart
Redirecting to /bin/systemctl restart nfs-server.service
[root@nfs-server ~]#[root@nfs-server ~]# ps aux|grep nfs
root 431 0.0 0.0 0 0 ? I 8月01 0:01 [kworker/u128:4-nfsd4]
root 833 0.0 0.3 50304 2932 ? Ss 8月01 0:00 /usr/sbin/nfsdcld
root 5311 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5312 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5313 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5314 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5315 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5316 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5317 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5318 0.0 0.0 0 0 ? S 11:02 0:00 [nfsd]
root 5326 0.0 0.1 12320 992 pts/0 S+ 11:03 0:00 grep --color=auto nfs
[root@nfs-server ~]#3.原理部分:
nfs服務(wù)和rpc到底是如何實現(xiàn)的呢?工作原理ssh-->22
nginx -->80
mysql -->3306時我們就得需要遠程過程調(diào)用 (RPC) 的服務(wù)啦!RPC 最主要的功能就是在指定每個 NFS 功能所對應(yīng)的 port number ,并且回報給客戶端,讓客戶端可以連結(jié)到正確的端口上去。 那 RPC 又是如何知道每個 NFS 的端口呢?這是因為當(dāng)服務(wù)器在啟動 NFS 時會隨機取用數(shù)個端口,并主動的向 RPC 注冊,因此 RPC 可以知道每個端口對應(yīng)的 NFS 功能。nfs自己并沒有去對外監(jiān)聽某個端口號,而是外包給了rpc服務(wù),rpc幫助nfs去監(jiān)聽端口,然后告訴客戶機和本機的那個進程對應(yīng)的端口連續(xù)[root@nfs-server ~]# netstat -anplut|grep nfs
[root@nfs-server ~]# netstat -anplut|grep rpc 查看rpc服務(wù)相關(guān)的端口
tcp 0 0 0.0.0.0:35503 0.0.0.0:* LISTEN 960/rpc.statd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 5304/rpc.mountd
tcp6 0 0 :::20048 :::* LISTEN 5304/rpc.mountd
tcp6 0 0 :::42099 :::* LISTEN 960/rpc.statd
udp 0 0 0.0.0.0:20048 0.0.0.0:* 5304/rpc.mountd
udp 0 0 127.0.0.1:717 0.0.0.0:* 960/rpc.statd
udp 0 0 0.0.0.0:42974 0.0.0.0:* 960/rpc.statd
udp6 0 0 :::20048 :::* 5304/rpc.mountd
udp6 0 0 :::43399 :::* 960/rpc.statd
[root@nfs-server ~]# 4.共享文件,編輯/etc/exports文件,寫好具體的共享的目錄和權(quán)限
/etc/exports
[root@nfs-server ~]# vim /etc/exports/web 192.168.0.0/24(rw,all_squash,sync)
/web 是我們共享的文件夾的路徑--》使用絕對路徑 --》需要自己新建
192.168.0.0/24 允許過來訪問的客戶機的ip地址網(wǎng)段
(rw,all_squash,sync) 表示權(quán)限的限制 rw 表示可讀可寫 read and writero 表示只能讀 read-onlyall_squash :任何客戶機上的用戶過來訪問的時候,都把它認為是普通的用戶root_squash 當(dāng)NFS客戶端以root管理員訪問時,映射為NFS服務(wù)器匿名用戶no_root_squash 當(dāng)NFS客戶端以root管理員訪問時,映射為NFS服務(wù)器的root管理員sync 同時將數(shù)據(jù)寫入到內(nèi)存與硬盤中,保證不丟失數(shù)據(jù)async 優(yōu)先將數(shù)據(jù)保存到內(nèi)存,然后再寫入硬盤,效率更高,但可能丟失數(shù)據(jù)
[root@nfs-server ~]# mkdir /web
[root@nfs-server ~]# cd /web
[root@nfs-server web]#vim index.html 創(chuàng)建首頁文件
index.html [root@nfs-server web]# cat index.html
sanchuang
fengdeyong xuzizhen zhangrenjie
[root@nfs-server web]#
5.刷新輸出文件的列表
[root@nfs-server web]# exportfs -rv
exporting 192.168.0.0/24:/web
[root@nfs-server web]# [root@nfs-server web]# cat /etc/exports
/web 192.168.0.0/24(rw,all_squash,sync)
/download 192.168.0.0/24(rw,all_squash,sync)
/download 192.168.0.190(rw,all_squash,sync)
/download 192.168.0.192(rw,all_squash,sync)
/download 192.168.0.180(rw,all_squash,sync)
[root@nfs-server web]#
[root@nfs-server web]# mkdir /download 新建/download
[root@nfs-server web]# exportfs -rv
exporting 192.168.0.190:/download
exporting 192.168.0.192:/download
exporting 192.168.0.180:/download
exporting 192.168.0.0/24:/download
exporting 192.168.0.0/24:/web
[root@nfs-server web]#
復(fù)制一點點數(shù)據(jù)到/download目錄下
[root@nfs-server download]# cp /etc/hosts .
[root@nfs-server download]# tar czf boot.tar.gz /boot
tar: 從成員名中刪除開頭的“/”[root@nfs-server download]#
[root@nfs-server download]# ls
boot.tar.gz hosts
[root@nfs-server download]#5.建議關(guān)閉防火墻和selinux[root@nfs-server download]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@nfs-server download]# systemctl disable firewalld
[root@nfs-server download]# getenforce
Disabled
[root@nfs-server download]# 在客戶機上掛載nfs服務(wù)器上共享的/web和/download目錄
[root@web-server2 ~]# yum install nfs-utils -y 安裝nfs-utils軟件,方便客戶機上進行掛載,具有了相關(guān)命令了,例如:showmount
[root@web-server2 ~]# showmount -e 192.168.0.139 查看nfs服務(wù)器上共享輸出了哪些文件夾
Export list for 192.168.0.139:
/web 192.168.0.0/24
/download 192.168.0.0/24
[root@web-server2 ~]# 掛載nfs服務(wù)器上的目錄到本機上
[root@web-server2 ~]# mkdir /web 在客戶機的本地新建一個目錄/web
[root@web-server2 ~]# mount 192.168.0.139:/web /web 將nfs服務(wù)器上的/web目錄掛載到本地的/web目錄,今后訪問本地的/web目錄,就是訪問到nfs服務(wù)器上的/web目錄
mount 是掛載的命令,可以理解為一種映射語法: mount nfs服務(wù)器的目錄 本地的目錄[root@web-server2 ~]# cd /web
[root@web-server2 web]# ls
index.html
[root@web-server2 web]# ls
index.html sc.txt
[root@web-server2 web]#[root@web-server2 web]# mkdir /download
[root@web-server2 web]# mount 192.168.0.139:/download /download
[root@web-server2 web]# cd /download/
[root@web-server2 download]# ls
boot.tar.gz hosts
[root@web-server2 download]# 客戶機上能否有寫的權(quán)限要看2種權(quán)限:1.共享權(quán)限 --》/etc/exports文件里的權(quán)限,例如ro,rw2.文件系統(tǒng)里的權(quán)限 --》/web 在linux里的權(quán)限[root@nfs-server web]# ll -d /web
drwxrwxrwx. 3 root root 56 8月 2 11:55 /web
[root@nfs-server web]# ll -d /download
drwxr-xr-x 2 root root 38 8月 2 11:44 /download ---》nfs客戶機掛載后,沒有寫的權(quán)限,因為其他人沒有w權(quán)限
[root@nfs-server web]# 在nfs服務(wù)器上授權(quán)
[root@nfs-server web]# chmod a+w /download/
[root@nfs-server web]# ll -d /download
drwxrwxrwx 2 root root 38 8月 2 11:44 /download
[root@nfs-server web]# 在客戶機上驗證
[root@web-server2 web]# cd /download/
[root@web-server2 download]# mkdir fengdeyong
[root@web-server2 download]# ls
boot.tar.gz fengdeyong hosts
[root@web-server2 download]# 后端的real-server到底要把nfs服務(wù)器共享的目錄掛載到哪里?用戶才能看到一樣的數(shù)據(jù)nginx安裝目錄下的html --》編譯安裝的[root@web-server2 sczhengbo99]# mount 192.168.0.139:/web /usr/local/sczhengbo99/html/
[root@web-server2 sczhengbo99]# cd /usr/local/sczhengbo99/html/
[root@web-server2 html]# ls
fengdeyong index.html sc.txt
[root@web-server2 html]#
相關(guān)命令和文件
mount? ?掛載
exportfs -rv? ?相當(dāng)于重啟nfs服務(wù),讓修改的/etc/exports文件生效
/etc/exports? ? 共享目錄的配置文件
umount? ?卸載
開機自動掛載nfs文件系統(tǒng)
1. /etc/rc.local
mount ?192.168.0.139:/web ? /usr/local/sczhengbo/html?
chmod +x /etc/rc.d/rc.local?
2.修改/etc/fstab文件,也可以自動掛載
? /etc/fstab 是linux系統(tǒng)開機會自動根據(jù)這個文件里的內(nèi)容掛載磁盤分區(qū)
? fstab ?-->file ?system ?table
192.168.0.139:/web ? /usr/local/sczhengbo99/html ?nfs ? ?defaults ?0 0
192.168.0.139:/web? ?掛載的分區(qū)--》nfs的文件系統(tǒng)
?/usr/local/sczhengbo/html 在本地的掛載點
?nfs 文件系統(tǒng)的類型
?defaults ?掛載的選項,使用默認
?0 是否支持dump命令進行備份
?0 是否開機的時候進行分區(qū)的文件系統(tǒng)的檢查,分區(qū)的文件系統(tǒng)是否有問題