NFS(根據鳥哥私房菜整理)php
參數值
|
內容說明
|
rw
ro |
該目錄分享的權限是可讀寫
(read-write) 或惟讀 (read-only),但最終能不能讀寫,還是與檔案系統的 rwx 及身份有關。
|
sync
async |
sync 表明資料會同步寫入到記憶體與硬碟中,
async 則表明資料會先暫存於記憶體當中,而非直接寫入硬碟!
|
no_root_squash
root_squash |
用戶端使用
NFS 檔案系統的帳號若為 root 時,系統該如何判斷這個帳號的身份?預設的情況下,用戶端 root 的身份會由 root_squash 的設定壓縮成 nfsnobody, 如此對伺服器的系統會較有保障。但若是你想要開放用戶端使用 root 身份來操做伺服器的檔案系統,那麼這裡就得要開 no_root_squash 才行!
|
all_squash
|
不論登入
NFS 的使用者身份為何, 他的身份都會被壓縮成為匿名使用者,一般也就是 nobody(nfsnobody) 啦!
|
anonuid
anongid |
anon 意指
anonymous (匿名者) 前面關於 *_squash 提到的匿名使用者的 UID 設定值,一般為 nobody(nfsnobody),可是你能夠自行設定這個 UID 的值!當然,這個 UID 必須要存在於你的 /etc/passwd 當中! anonuid 指的是 UID 而 anongid 則是羣組的 GID 囉。
|
# /etc/init.d/rpcbind start
#/etc/init.d/nfs start
#/etc/rc.d/init.d/portmap start
二exportfs:
當修改了/etc/exports以後不須要重啓,只要使用exportfs從新掃描一次/etc/exports就能夠
#exportfs –rv(從新引導)
三showmount 先是主機共享的目錄。
[root@www ~]# netstat -tulnp| grep -E '(rpc|nfs)'
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
PID/Program name
tcp
0 0 0.0.0.0:875 0.0.0.0:* LISTEN 3631/rpc.rquotad
tcp
0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3601/rpcbind
tcp
0 0 0.0.0.0:48470 0.0.0.0:* LISTEN 3647/rpc.mountd
tcp
0 0 0.0.0.0:59967 0.0.0.0:* LISTEN 3689/rpc.statd
tcp
0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
udp
0 0 0.0.0.0:875 0.0.0.0:* 3631/rpc.rquotad
udp
0 0 0.0.0.0:111 0.0.0.0:* 3601/rpcbind
udp
0 0 0.0.0.0:897 0.0.0.0:* 3689/rpc.statd
udp
0 0 0.0.0.0:46611 0.0.0.0:* 3647/rpc.mountd
udp
0 0 0.0.0.0:808 0.0.0.0:* 3601/rpcbind
udp
0 0 0.0.0.0:46011 0.0.0.0:* 3689/rpc.statd
|
[root@www ~]# rpcinfo -p [IP|hostname]
|
|
Client端的操做:
無法掛載的緣由分析:
1. 用戶端的主機名稱或 IP 網段不被允許使用:
2. 伺服器或用戶端某些服務未啟動:
3. 被防火牆檔掉了:
[root@clientlinux ~]# vim /etc/auto.master
/home/nfsfile /etc/auto.nfs
|
[本地端次目錄
] [-掛載參數] [伺服器所提供的目錄]
選項與參數:
[本地端次目錄
] :指的就是在 /etc/auto.master 內指定的目錄之次目錄
[-掛載參數
] :就是前一小節提到的 rw,bg,soft 等等的參數啦!可有可無;
[伺服器所提供的目錄
] :例如 192.168.100.254:/home/public 等
[root@clientlinux ~]# vim /etc/auto.nfs
public
-rw,bg,soft,rsize=32768,wsize=32768 192.168.100.254:/home/public
testing -rw,bg,soft,rsize=32768,wsize=32768 192.168.100.254:/home/test
temp
-rw,bg,soft,rsize=32768,wsize=32768 192.168.100.254:/tmp
# 參數部分,只要最前面加個
- 符號便可!
|
[root@clientlinux ~]# /etc/init.d/autofs stop
[root@clientlinux ~]# /etc/init.d/autofs start
# 很奇怪!很是怪!
CentOS 6.x 的 autofs 使用 restart 會失效!因此鳥哥才進行兩次
|
[root@clientlinux ~]# ll -d /home/nfsfile
drwxr-xr-x. 2 root root 0 2011-07-28 00:07 /home/nfsfile
# 仔細看,妳會發現
/home/nfsfile 容量是 0 喔!那是正常的!因為是 autofs 創建的
[root@clientlinux ~]# cd /home/nfsfile/public
[root@clientlinux public]# mount | grep nfsfile
192.168.100.254:/home/public on /home/nfsfile/public type nfs (rw,soft,rsize=32768,
wsize=32768,sloppy,vers=4,addr=192.168.100.254,clientaddr=192.168.100.10)
# 上面的輸出是同一行!瞧!忽然出現這個玩意兒!因為是自動掛載的嘛!
[root@clientlinux public]# df /home/nfsfile/public
檔案系統
1K-區段 已用 可用 已用% 掛載點
192.168.100.254:/home/public
7104640 143104 6607040 3% /home/nfsfile/public
# 檔案的掛載也出現沒錯!
|
案例演練:
[root@www ~]# vim /etc/exports
/tmp
192.168.100.0/24(rw,no_root_squash)
/home/nfs
192.168.100.0/24(ro) *(ro,all_squash)
/home/upload 192.168.100.0/24(rw,all_squash,anonuid=210,anongid=210)
/home/andy
192.168.100.10(rw)
|
# 1. /tmp
[root@www ~]# ll -d /tmp
drwxrwxrwt. 12 root root 4096 2011-07-27 23:49 /tmp
# 2. /home/nfs
[root@www ~]# mkdir -p /home/nfs
[root@www ~]# chmod 755 -R /home/nfs
# 修改較為嚴格的檔案權限將目錄與檔案設定成惟讀!不能寫入的狀態,會更保險一點!
# 3. /home/upload
[root@www ~]# groupadd -g 210 nfs-upload
[root@www ~]# useradd -g 210 -u 210 -M nfs-upload
# 先創建對應的帳號與羣組名稱及
UID 喔!
[root@www ~]# mkdir -p /home/upload
[root@www ~]# chown -R nfs-upload:nfs-upload /home/upload
# 修改擁有者!如此,則使用者與目錄的權限都設定妥當囉!
# 4. /home/andy
[root@www ~]# useradd andy
[root@www ~]# ll -d /home/andy
drwx------. 4 andy andy 4096 2011-07-28 00:15 /home/andy
|
[root@www ~]# /etc/init.d/nfs restart
|
# 1. 確認遠端伺服器的可用目錄:
[root@clientlinux ~]# showmount -e 192.168.100.254
Export list for 192.168.100.254:
/home/andy
192.168.100.10
/home/upload 192.168.100.0/24
/home/nfs
(everyone)
/tmp
192.168.100.0/24
# 2. 創建掛載點:
[root@clientlinux ~]# mkdir -p /mnt/{tmp,nfs,upload,andy}
# 3. 實際掛載:
[root@clientlinux ~]# mount -t nfs 192.168.100.254:/tmp
/mnt/tmp
[root@clientlinux ~]# mount -t nfs 192.168.100.254:/home/nfs
/mnt/nfs
[root@clientlinux ~]# mount -t nfs 192.168.100.254:/home/upload /mnt/upload
[root@clientlinux ~]# mount -t nfs 192.168.100.254:/home/andy
/mnt/andy
|