天天看點

[RHEL5企業級Linux服務攻略]--第10季 NFS服務全攻略

企業NFS伺服器拓撲圖:

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268552xDHr.png"></a>

需求:

1、/media目錄

共享/media目錄,允許所有用戶端通路該目錄并隻有隻讀權限。

2、/nfs/public目錄

共享/nfs/public目錄,允許192.168.8.0/24和192.168.9.0/24網段的用戶端通路,并且對此目錄隻有隻讀權限。

3、/nfs/team1、/nfs/team2、/nfs/team3目錄

共享/nfs/team1、/nfs/team2、/nfs/team3目錄,并/nfs/team1隻有team1.michael.com域成員可以通路并有讀寫權限,/nfs/team2、/nfs/team3目錄同理哈~

4、/nfs/works目錄

共享/nfs/works目錄,192.168.8.0/24網段的用戶端具有隻讀權限,并且将root使用者映射成匿名使用者。

5、/nfs/test目錄

共享/nfs/test目錄,所有人都具有讀寫權限,但當使用者使用該共享目錄時都将帳号映射成匿名使用者,并且指定匿名使用者的UID和GID都為65534。

6、/nfs/security目錄

共享/nfs/security目錄,僅允許192.168.8.88用戶端通路并具有讀寫權限。

解決方案:

1、建立相應目錄

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_12392685540soq.png"></a>

2、安裝nfs-utils及portmap軟體包

沒有就用rpm或yum安裝一下哈~

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268555pPWr.png"></a>

nfs-utils-1.0.9-24.el5:nfs服務的主程式包,它提供rpc.nfsd及rpc.mountd這兩個daemons以及相關的說明檔案。

portmap-4.0-65.2.2.1:rpc主程式,記錄服務的端口映射資訊。

3、編輯/etc/exports配置檔案

/etc/exports:nfs服務的主配置檔案

vim /etc/exports

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268556iAwB.png"></a>

配置後

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268557vzhS.png"></a>

注意:在釋出共享目錄的格式中除了共享目錄是必跟參數外,其他參數都是可選的。并且共享目錄與用戶端之間及用戶端與用戶端之間需要使用空格符号,但是用戶端與參數之間是不能有空格的哈~

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268559qcGK.png"></a>

4、配置nfs固定端口

vim /etc/sysconfig/nfs

自定義以下端口,然而不能和其他端口沖突

RQUOTAD_PORT=5001 

LOCKD_TCPPORT=5002 

LOCKD_UDPPORT=5002 

MOUNTD_PORT=5003 

STATD_PORT=5004

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268561Emzu.png"></a>

5、配置iptables政策

iptables -P INPUT -j DROP 

iptables -A INPUT -i lo -j ACCEPT 

iptables -A INPUT -p tcp -m multiport --dport 111,2049 -j ACCEPT 

iptables -A INPUT -p udp -m multiport --dport 111,2049 -j ACCEPT 

iptables -A INPUT -p tcp --dport 5001:5004 -j ACCEPT 

iptables -A INPUT -p udp --dport 5001:5004 -j ACCEPT 

service iptables save

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268562G1Fk.png"></a>

6、啟動portmap和nfs服務

由于NFS服務是基于portmap服務的,是以我們需要先啟動portmap服務:service portmap restart ,然後 service nfs restart

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268564aLnu.png"></a>

7、測試

NFS伺服器本機測試

1)使用rpcinfo指令檢測nfs是否使用了固定端口

rpcinfo -p

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268565evQz.png"></a>

2)檢測nfs的rpc注冊狀态

rpcinfo -u 主機名或IP位址 程序

rpcinfo -u 192.168.8.188 nfs

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268566hahR.png"></a>

3)檢視共享目錄和參數設定

cat /var/lib/nfs/etab

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268567rUnw.png"></a>

4)使用showmount指令檢視共享目錄釋出及使用情況

showmount -e或showmount -e IP位址

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_12392685680F2G.png"></a>

showmount -d或者showmount -d IP位址

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268569FGlq.png"></a>

Linux用戶端測試

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268570BwxR.png"></a>

1)檢視nfs伺服器共享目錄

showmount -e 192.168.8.188

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268574Booa.png"></a>

2)挂載及解除安裝NFS檔案系統

mount -t nfs NFS伺服器IP位址或主機名:共享名 本地挂載點

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268574zUGB.png"></a>

如果想挂載一個沒有權限通路的NFS共享目錄就會報錯哈~

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268575lBWz.png"></a>

3)啟動自動挂載nfs檔案系統

vim /etc/fstab

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268575A7U8.png"></a>

儲存退出并重新開機系統

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268577Ou0b.png"></a>

我們在nfs伺服器/nfs/test目錄中建立個檔案測試一下

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268578zsia.png"></a>

linux用戶端系統啟動了

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_1239268579hOtO.png"></a>

我們來看下/nfs/test有沒挂載成功了哈~

<a href="http://redking.blog.51cto.com/attachment/200904/9/27212_12392685809cIt.png"></a>

###############Michael分割線##################

本文轉自redking51CTO部落格,原文連結:http://blog.51cto.com/redking/147887,如需轉載請自行聯系原作者

繼續閱讀