本博文議程以下:node |
1、生產狀況應用案例vim |
2、NFS客戶端可掛載的參數安全 |
3、人爲模擬錯誤的學習方法bash |
4、NFS在網站架構中的位置服務器 |
5、NFS的優缺點架構 |
議程1、生產狀況實際案例概述:併發
實現當多臺客戶端同時掛載一臺NFS Server時,不管從哪一個客戶端寫入數據,其餘客戶端一樣能夠讀寫,即讓全部NFS客戶端寫入到NFS Server的文件或目錄在NFS Server上的用戶和組都是同一個名稱nfsnobody 。請給出操做步驟,並加以說明。app
實現NFS服務端的/data目錄共享,指定主機(本身設置),要求在NFS客戶端可讀可寫入數據,寫入的數據能夠在NFS Server端看到,請給出操做步驟或配置方法?tcp
解答:ide
要點:不管什麼版本的操做系統,NFS服務默認的配置裏匿名uid和gid都爲65534
查看3臺機器上查看nfsnobody用戶的uid和gid分別是多少?是否是相同?
[root@nfs-server ~]# grep nfsnobody /etc/passwd nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin [root@nfs-client1 ~]# grep nfsnobody /etc/passwd nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin [root@nfs-client2 ~]# grep nfsnobody /etc/passwd nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
首先讓服務端的portmap啓動起來
[root@nfs-server ~]# /etc/init.d/portmap status portmap (pid 3658) is running...
其次讓服務端的NFS啓動起來,NFS必定要確保在portmap服務啓動以後再啓動
[root@nfs-server ~]# /etc/init.d/nfs status rpc.mountd (pid 3748) is running... nfsd (pid 3745 3744 3743 3742 3741 3740 3739 3738) is running...
爲了確保NFS在portmap以後啓動的,讓NFS服務從新啓動一下便可
[root@nfs-server ~]# /etc/init.d/nfs restart Shutting down NFS mountd: [ OK ] Shutting down NFS daemon: [ OK ] Shutting down NFS services: [ OK ] Starting NFS services: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ]
分別把portmap和NFS設置爲開機自啓動
[root@nfs-server ~]# chkconfig portmap on [root@nfs-server ~]# chkconfig nfs on [root@nfs-server ~]# chkconfig --list|egrep"portmap|nfs" nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off portmap 0:off 1:off 2:on 3:on 4:on 5:on 6:off
小細節:上面把portmap和NFS都設置成開機自啓動了,那麼開機的時候究竟是哪一個先啓呢?咱們來對比二者的啓動腳原本進行深度剖析
[root@nfs-server ~]# more /etc/init.d/nfs #查看NFS服務的啓動腳本
接下來就能夠共享本地的/data目錄給NFS客戶端了
[root@nfs-server ~]# vim /etc/exports [root@nfs-server ~]# cat /etc/exports /data/ 192.168.1.0/24(rw,sync) #<==rw表示讓客戶端可讀寫,sync表示當客戶端把數據寫入到服務端的時候,同時寫入到硬盤裏面。
配置好以後從新加載NFS服務便可
[root@nfs-server ~]# /etc/init.d/nfs reload 注意:這樣配置的前提是要確保NFS服務端和客戶端的nfsnobody所對應的uid和gid都是65534,這樣就可以保證,NFS全部的客戶端在往服務端寫數據的時候,都會寫同一個uid和gid,A服務寫一個文件和B服務寫一個文件他倆所對應的用戶是相同的,此時A寫,B能夠刪,那麼這種機制具體是在哪裏控制的呢? [root@nfs-server ~]# cat /var/lib/nfs/etab /data 192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534) #<==紅色部分爲手動配置部分,其餘均爲系統默認附加上去的配置
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
開始測試
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
開啓客戶端portmap服務並加入開機自啓動
[root@nfs-client1 ~]# /etc/init.d/portmap restart Stopping portmap: [ OK ] Starting portmap: [ OK ] [root@nfs-client1 ~]# chkconfig portmap on [root@nfs-client1 ~]# chkconfig --list portmap portmap 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@nfs-client2 ~]# /etc/init.d/portmap restart Stopping portmap: [ OK ] Starting portmap: [ OK ] [root@nfs-client2 ~]# chkconfig portmap on [root@nfs-client2 ~]# chkconfig --list portmap portmap 0:off 1:off 2:on 3:on 4:on 5:on 6:off
客戶端mount服務端共享的目錄
首先檢查服務端是否已經提供了共享目錄 [root@nfs-client1 ~]# showmount -e 192.168.1.50 Export list for 192.168.1.50: /data 192.168.1.0/24 [root@nfs-client2 ~]# showmount -e 192.168.1.50 Export list for 192.168.1.50: /data 192.168.1.0/24 NFS客戶端掛載測試 [root@nfs-client1 ~]# mount -t nfs 192.168.1.50:/data /mnt/ [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/data nfs 9.5G 151M 8.9G 2% /mnt [root@nfs-client2 ~]# mount -t nfs 192.168.1.50:/data/ /mnt/ [root@nfs-client2 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/data/ nfs 9.5G 151M 8.9G 2% /mnt
[root@nfs-client1 ~]# cd /mnt/ [root@nfs-client1 mnt]# touch {6..8}.txt touch: cannot touch `6.txt': Permission denied touch: cannot touch `7.txt': Permission denied touch: cannot touch `8.txt': Permission denied [root@nfs-client2 ~]# cd /mnt/ [root@nfs-client2 mnt]# touch {7..10}.txt touch: 沒法觸碰 「7.txt」: 權限不夠 touch: 沒法觸碰 「8.txt」: 權限不夠 touch: 沒法觸碰 「9.txt」: 權限不夠 touch: 沒法觸碰 「10.txt」: 權限不夠 [root@nfs-client2 mnt]# export LANG=c [root@nfs-client2 mnt]# touch {7..10}.txt touch: cannot touch `7.txt': Permission denied touch: cannot touch `8.txt': Permission denied touch: cannot touch `9.txt': Permission denied touch: cannot touch `10.txt': Permission denied
爲何不容許NFS的客戶端來讀寫呢?
應爲客戶端過來確定要被映射成65534這個用戶的uid,65534就是nfsnobody的uid,對於nfsnobody這個用戶來說,它只能去讀取這個文件,沒法寫入;因此能讀取到該文件,可是寫不了?
有兩種方法能夠解決上述客戶端讀寫的問題?
第一種就是使用上面的把NFS服務端的共享的/data目錄受權爲777權限,此種方法從操做系統安全的角度來考慮是不合適的,對權限的控制不夠精細,容易形成系統漏洞,好比提權等不安全的事件發生;第二種方法是受權NFS服務端的共享目錄/data爲nfsnobody用戶;
推薦採用第二種方法。
[root@nfs-server ~]# chown -R nfsnobody /data/ [root@nfs-server ~]# ls -ld /data/ drwxr-xr-x 2 nfsnobody root 4096 05-01 15:08 /data/ 客戶端再次進行測試:
實際生產環境的配置參數以下: [root@nfs-server ~]# vim /etc/exports [root@nfs-server ~]# /etc/init.d/nfs reload [root@nfs-server ~]# cat /etc/exports #/data/ 192.168.1.0/24(rw,sync) /data/ 192.168.1.0/24(rw,sync,all_squash) # all_squash不管客戶端是什麼用戶都壓縮爲nfsnobody用戶來讀寫文件。 固然了這樣作的前提是全部的客戶端都擁有同一個uid的用戶 [root@nfs-client1 ~]# groupadd nfstest1 -g 1668 [root@nfs-client1 ~]# useradd nfstest1 -u 1668 -g nfstest1 [root@nfs-client1 ~]# tail -1 /etc/passwd nfstest1:x:1668:1668::/home/nfstest1:/bin/bash [root@nfs-client1 ~]# id nfstest1 uid=1668(nfstest1) gid=1668(nfstest1) groups=1668(nfstest1) context=root:system_r:unconfined_t:SystemLow-SystemHigh [root@nfs-client2 ~]# groupadd nfstest1 -g 1668 [root@nfs-client2 ~]# useradd nfstest1 -u 1668 -g nfstest1 [root@nfs-client2 ~]# tail -1 /etc/passwd nfstest1:x:1668:1668::/home/nfstest1:/bin/bash [root@nfs-client2 ~]# id nfstest1 uid=1668(nfstest1) gid=1668(nfstest1) groups=1668(nfstest1) context=root:system_r:unconfined_t:SystemLow-SystemHigh
關於NFS服務端認證的萬能終極的方法詳解:
1、全部的NFS客戶端和服務端都創建nfstest1用戶及nfstest1組
創建nfstest1組並指定nfstest1的GID爲1668客戶端也要用一樣命令建立 [root@nfs-server ~]# groupadd nfstest1 -g 1668 創建用戶nfstest1,指定UID爲1668並加入nfstest1組,客戶端也用一樣命令建立 [root@nfs-server ~]# useradd nfstest1 -u 1668 -g nfstest1 [root@nfs-server ~]# tail -n1 /etc/passwd nfstest1:x:1668:1668::/home/nfstest1:/bin/bash [root@nfs-server ~]# id nfstest1 uid=1668(nfstest1) gid=1668(nfstest1) groups=1668(nfstest1) context=root:system_r:unconfined_t:SystemLow-SystemHigh 不要忘記NFS Server本地的文件權限: /data目錄權限 chown -R nfstest1 /data,儘可能不要使用chmod -R 777 /data
2、修改/etc/exports文件
/data 192168.1.0/24(rw,sync,all_squash,anonuid=1668,anongid=1668)
3、/etc/init.d/nfsreload
4、客戶端主機上,掛載NFS目錄
mount -t nfs 192.138.1.50:/data /mnt
5、完整演示
NFS客戶端先卸載以前掛載上去的目錄 [root@nfs-client1 ~]# umount /mnt/ [root@nfs-client2 ~]# umount /mnt/ NFS服務端操做 [root@nfs-server ~]# vim /etc/exports [root@nfs-server ~]# cat /etc/exports #/data/ 192.168.1.0/24(rw,sync) /nfstest1 192.168.1.0/24(rw,sync,all_squash,anonuid=1668,anongid=1668) [root@nfs-server ~]# chown -R nfstest1 /nfstest1/ [root@nfs-server ~]# ls -ld /nfstest1 192.168.1.0/24(rw,sync,all_squash,anonuid=1668,anongid=1668) drwxr-xr-x 2 nfstest1 root 4096 05-01 22:21 /nfstest1/ [root@nfs-server ~]# /etc/init.d/nfs reload #<===服務端從新讀取配置文件 客戶端掛載 [root@nfs-client1 ~]# showmount -e 192.168.1.50 Export list for 192.168.1.50: /nfstest1 192.168.1.0/24 [root@nfs-client1 ~]# mount -t nfs 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client2 ~]# showmount -e 192.168.1.50 Export list for 192.168.1.50: /nfstest1 192.168.1.0/24 [root@nfs-client2 ~]# mount -t nfs 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client2 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt
[root@nfs-server ~]# nl /var/lib/nfs/rmtab 1 192.168.1.52:/data:0x00000003 2 192.168.1.51:/data:0x00000001 3 192.168.1.51:/nfstest1:0x00000001 4 192.168.1.52:/nfstest1:0x00000001
此文件記錄了哪些客戶端來訪問過NFS服務端共享的哪些目錄,通常來說經過此文件就就能夠知道有哪些客戶端在掛載咱們的NFS服務的共享目錄。
設置客戶端開機啓動掛載 [root@nfs-client1 ~]# which mount /bin/mount [root@nfs-client1 ~]# /bin/mount -t nfs 192.168.1.50:/nfstest1 /mnt/ mount.nfs: /mnt is already mounted or busy [root@nfs-client1 ~]# vim /etc/rc.local [root@nfs-client1 ~]# tail -n1 /etc/rc.local /bin/mount -t nfs 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client2 ~]# which mount /bin/mount [root@nfs-client2 ~]# vim /etc/rc.local [root@nfs-client2 ~]# tail -n1 /etc/rc.local /bin/mount -t nfs 192.168.1.50:/nfstest1 /mnt/
議程2、NFS客戶端可掛載的參數
NFS客戶端mount掛載參數
通常來講,當NFS服務器提供的只是普通數據(圖片,HTML,CSS,js,視頻,附件等),應該不須要執行suid,exec等權限,所以在掛載的時候,能夠這樣執行命令: mount -t nfs -o nosuid,noexec,rw,192.168.1.50:/data /mnt 這樣一來,掛載的這個文件夾系統就只能做爲數據存取之用,相對來講,對於客戶端比較安全一些。 [root@nfs-client1 ~]# umount /mnt/ [root@nfs-client1 ~]# mount -t nfs -o nosuid,noexec,nodev,rw,sync 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client1 ~]# mkdir /mnt/test`data +%F` -bash: data: command not found [root@nfs-client1 ~]# mkdir /mnt/`date +%F` [root@nfs-client2 ~]# mount -t nfs -o nosuid,noexec,nodev,rw,sync 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client2 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client2 ~]# ll /mnt/ total 40 -rw-r--r-- 1 nfstest1 nfstest1 0 May 1 23:22 1.txt -rw-r--r-- 1 nfstest1 nfstest1 0 May 1 23:23 2.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 May 1 23:48 2014-05-01 -rw-r--r-- 1 root root 0 May 1 23:22 3.txt -rw-r--r-- 1 root root 0 May 1 23:22 4.txt -rw-r--r-- 1 root root 0 May 1 23:22 5.txt -rw-r--r-- 1 root root 0 May 1 23:22 6.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 May 1 23:47 test
mount -t nfs -o nosuid,noexec,nodev,rw,hard,intr,rsize=32768,wsize=32768 192.168.1.50:/nfstest1 /mnt [root@nfs-client1 ~]# mount -t nfs -o nosuid,noexec,nodev,rw,hard,intr,rsize=32768,wsize=32768 192.168.1.50:/nfstest1 /mnt [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client2 ~]# mount -t nfs -o nosuid,noexec,nodev,rw,hard,intr,rsize=32768,wsize=32768 192.168.1.50:/nfstest1 /mnt [root@nfs-client2 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client2 ~]# mount -a [root@nfs-client2 ~]# mount /dev/sda2 on / type ext3 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda6 on /data type ext3 (rw) /dev/sda5 on /app type ext3 (rw) /dev/sda3 on /tools type ext3 (rw) /dev/sda1 on /boot type ext3 (rw) tmpfs on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 192.168.1.50:/nfstest1 on /mnt type nfs (rw,noexec,nosuid,nodev,hard,intr,rsize=32768,wsize=32768,addr=192.168.1.50)
lips:NFS後續優化1、
NFS後續優化2、修改內核參數
echo 262144>/proc/sys/net/core/rmem_default echo 262144>/proc/sys/net/core/rmem_max [root@nfs-client1 ~]# cat /proc/sys/net/core/rmem_default 129024 [root@nfs-client1 ~]# echo 262144 >/proc/sys/net/core/rmem_default [root@nfs-client1 ~]# cat /proc/sys/net/core/rmem_default 262144 [root@nfs-client1 ~]# cat /proc/sys/net/core/rmem_max 131071 [root@nfs-client1 ~]# echo 262144 >/proc/sys/net/core/rmem_max [root@nfs-client1 ~]# cat /proc/sys/net/core/rmem_max 262144 [root@nfs-client2 ~]# echo 262144 >/proc/sys/net/core/rmem_default [root@nfs-client2 ~]# cat /proc/sys/net/core/rmem_default 262144 [root@nfs-client2 ~]# echo 262144 >/proc/sys/net/core/rmem_max [root@nfs-client2 ~]# cat /proc/sys/net/core/rmem_max 262144
NFS問題:umount: /mnt: device is busy解決辦法
當沒法卸載NFS掛載目錄時,以下: [root@nfs-client1 mnt]# umount /mnt/ umount: /mnt: device is busy umount: /mnt: device is busy 緣由及解決方法: 一、可能當前目錄就是掛載的NFS目錄(/mnt) 解決方法:退出掛載的目錄/mnt,再執行umount /mnt卸載 二、好比NFS Server掛了,NFS client會出問題(df -Th 窗口會死掉) 解決方法:採用強制卸載方法umount -lf /mnt
議程3:人爲模擬錯誤的學習方法(重中之重)
模擬錯誤(1)、:把NFS client1的portmap服務停掉,而後再client1上,往裏面寫數據,能夠寫入嗎?若是能夠寫入數據,那麼client2上還能夠看到嗎?
[root@nfs-client1 ~]# /etc/init.d/portmap stop Stopping portmap: [ OK ] [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client1 ~]# cd /mnt/ [root@nfs-client1 mnt]# mkdir test`date +%F` [root@nfs-client1 mnt]# ll total 48 -rw-r--r-- 1 nfstest1 nfstest1 0 May 1 23:22 1.txt -rw-r--r-- 1 nfstest1 nfstest1 0 May 1 23:23 2.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 May 1 23:48 2014-05-01 -rw-r--r-- 1 root root 0 May 1 23:22 3.txt -rw-r--r-- 1 root root 0 May 1 23:22 4.txt -rw-r--r-- 1 root root 0 May 1 23:22 5.txt -rw-r--r-- 1 root root 0 May 1 23:22 6.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 May 1 23:47 test drwxr-xr-x 2 nfstest1 nfstest1 4096 May 2 00:28 test2014-05-02 [root@nfs-client2 ~]# cd /mnt/ [root@nfs-client2 mnt]# ll total 48 -rw-r--r-- 1 nfstest1 nfstest1 0 May 1 23:22 1.txt -rw-r--r-- 1 nfstest1 nfstest1 0 May 1 23:23 2.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 May 1 23:48 2014-05-01 -rw-r--r-- 1 root root 0 May 1 23:22 3.txt -rw-r--r-- 1 root root 0 May 1 23:22 4.txt -rw-r--r-- 1 root root 0 May 1 23:22 5.txt -rw-r--r-- 1 root root 0 May 1 23:22 6.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 May 1 23:47 test drwxr-xr-x 2 nfstest1 nfstest1 4096 May 2 00:28 test2014-05-02 [root@nfs-server ~]# ll /nfstest1/ 總計 48 -rw-r--r-- 1 nfstest1 nfstest1 0 05-01 23:22 1.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 05-01 23:48 2014-05-01 -rw-r--r-- 1 nfstest1 nfstest1 0 05-01 23:23 2.txt -rw-r--r-- 1 root root 0 05-01 23:22 3.txt -rw-r--r-- 1 root root 0 05-01 23:22 4.txt -rw-r--r-- 1 root root 0 05-01 23:22 5.txt -rw-r--r-- 1 root root 0 05-01 23:22 6.txt drwxr-xr-x 2 nfstest1 nfstest1 4096 05-01 23:47 test drwxr-xr-x 2 nfstest1 nfstest1 4096 05-02 00:28 test2014-05-02 總結:把NFS client1的portmap服務停掉了,可是已有的服務通訊仍是正常的呢,這是爲何呢? 當服務端啓動完畢以後,客戶端的portmap先和服務端的portmap溝通,溝通以後由portmap向我彙報NFS的端口,此時客戶端會直接和NFS打交道;此時客戶端沒有portmap服務也能夠,由於在portmap服務在啓動的一瞬間它的任務就已經完成了;因此說它可以進行溝通。 可是會有一個問題,放你把NFS卸載以後,[root@nfs-client1 ~]# umount /mnt/ 從新掛載,由於portmap服務已經中止運行了,這個時候從新掛載,
當portmap服務開啓以後很快就能夠掛載了 [root@nfs-client1 ~]# /etc/init.d/portmap start Starting portmap: [ OK ] [root@nfs-client1 ~]# /bin/mount -t nfs 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client1 ~]# mount -a [root@nfs-client1 ~]# mount /dev/sda2 on / type ext3 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda6 on /data type ext3 (rw) /dev/sda5 on /app type ext3 (rw) /dev/sda3 on /tools type ext3 (rw) /dev/sda1 on /boot type ext3 (rw) tmpfs on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 192.168.1.50:/nfstest1 on /mnt type nfs (rw,addr=192.168.1.50)
模擬錯誤(2)、把NFS Server端的portmap服務停掉
客戶端採用mount默認卸載參數卸載不掉,需強制卸載才能夠哦! [root@nfs-client1 ~]# umount /mnt/ [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt [root@nfs-client1 ~]# umount -lf /mnt/ [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm
通常出現鏈接拒絕的緣由不外乎是對方的防火牆策略設置、對方的端口和服務沒有開啓等致使的問題。 [root@nfs-server ~]# /etc/init.d/portmap start 啓動 portmap: [肯定] [root@nfs-client1 ~]# /bin/mount -t nfs 192.168.1.50:/nfstest1 /mnt/ mount: mount to NFS server '192.168.1.50' failed: RPC Error: Program not registered. 雖然portmap服務已經起來了,可是NFS 向portmap註冊的端口信息已經丟失了 [root@nfs-server ~]# rpcinfo -p localhost program vers proto port 100000 2 tcp 111 portmapper 100000 2 udp 111 portmapper 當NFS Server 端沒註冊端口了,NFS client 向NFS Server 要端口的時候,服務端就告訴你,你沒向它註冊,哈哈!出現這種狀況,咱們可能就大概知道是服務端的NFS 沒向portmap註冊。 [root@nfs-server ~]# /etc/init.d/nfs restart Shutting down NFS mountd: [ OK ] Shutting down NFS daemon: [ OK ] Shutting down NFS services: [ OK ] Starting NFS services: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] [root@nfs-server ~]# rpcinfo -p localhost program vers proto port 100000 2 tcp 111 portmapper 100000 2 udp 111 portmapper 100003 2 udp 2049 nfs 100003 3 udp 2049 nfs 100003 4 udp 2049 nfs 100021 1 udp 45436 nlockmgr 100021 3 udp 45436 nlockmgr 100021 4 udp 45436 nlockmgr 100003 2 tcp 2049 nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100021 1 tcp 49972 nlockmgr 100021 3 tcp 49972 nlockmgr 100021 4 tcp 49972 nlockmgr 100005 1 udp 771 mountd 100005 1 tcp 774 mountd 100005 2 udp 771 mountd 100005 2 tcp 774 mountd 100005 3 udp 771 mountd 100005 3 tcp 774 mountd OK,已經能夠成功掛載了 [root@nfs-client1 ~]# /bin/mount -t nfs 192.168.1.50:/nfstest1 /mnt/ [root@nfs-client1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 ext3 15G 2.3G 12G 17% / /dev/sda6 ext3 9.5G 151M 8.9G 2% /data /dev/sda5 ext3 9.5G 151M 8.9G 2% /app /dev/sda3 ext3 9.5G 151M 8.9G 2% /tools /dev/sda1 ext3 190M 12M 169M 7% /boot tmpfs tmpfs 502M 0 502M 0% /dev/shm 192.168.1.50:/nfstest1 nfs 15G 2.3G 12G 17% /mnt
模擬錯誤3、把NFS Server端的NFS服務停掉
由於NFS Server端的NFS服務中止了以後,客戶端經過portmap跟NFS服務端的portmap進行溝通以後,服務端的portmap告訴客戶端NFS端口,而後客戶端跟NFS Server端進行聯機交換數據,那麼,如今的狀況是NFS 掛掉了,天然也就無法交換數據了; 解決方法:另開啓一終端,使用下列命令強制卸載 [root@nfs-client1 ~]# umount -lf /mnt
議程4、NFS在網站架構生產環境中的位置
議程5、NFS的優缺點
NFS的優勢:
1、簡單-->容易上手掌握
2、方便-->部署快速,維護簡單
3、可靠-->從軟件層面上看,數據可靠性高,經久耐用
NFS的侷限:
1、侷限性是存在單點故障,若是NFS Server宕機了,全部客戶端都不能訪問共享目錄。
2、在高併發的場合,NFS效率性能有限(通常幾千萬一下PV的網站不是瓶頸,處分是網站架構太差)
3、客戶端認證時基於ip和主機名的,安全性通常(用於內網問題不大)
4、NFS數據是明文的,對數據安全性不做驗證
5、多機掛載服務器時,鏈接管理麻煩。尤爲NFS服務端出項問題後,全部客戶端都掛掉狀態(可以使用autofs自動掛載解決)
生產應用場景:
中小型網站(2000W-2500WPV如下)線上使用,都有用武之地。門戶網站也會有其餘方面的應用,固然未必是線上存儲使用。