天天看點

搭建NFS共享服務vim /etc/exportsservice portmap restartservice nfs restartchkconfig portmap onchkconfig nfs onsetfacl -m u:nfsnobody:rwx /usr/src/showmount -e 192.168.10.10

搭建NFS共享服務

要求:

1将/root 共享給192.168.10.20,可寫、同步,允許客戶機以root權限通路

2将/usr/src 共享給192.168.10.0/24網段,可寫、異步,通路權限均降為nfsnobody使用者

思路:

首先伺服器上配置,確定伺服器上安裝nfs-utils服務和portmap/rpcbind 服務

安裝完成後進入nfs配置檔案/etc/exports

編寫格式

共享檔案目錄 客戶機(共享主機)ip位址(權限,同步/異步,是否保留管理者權限/全部降級為nfsnobody使用者)

使用通路控制acl配置權限(chmod權限更改使本地主機上使用者對該目錄下的檔案有權利操作)

setfacl -m u:nfsnobady:rwx 共享目錄

開啟服務(先開啟portmap/rpcbind服務,然後在開啟服務nfs) 并確定開機加載客戶機上配置

首先確定portmad/rpcbind服務的開啟

(1)建立目錄 mkdir /挂載

使用mount指令進行挂載
然後進入共享目錄中進行驗證           

(2)設定開機自動挂載(首先确定伺服器主機開機在相同網段)

把挂載指令寫到開機自動切腳本裡面,不要寫在/etc/fstab中,因為nfs是網絡共享服務,作業系統開 機先執行自啟動腳本後啟動網絡服務

reboot重新開機客戶機進行驗證           

(3)觸發挂載(首先確定伺服器與主機在相同的網段)

确認autofs服務開啟
進入觸發配置挂載檔案/etc/autofs.master 
觸發挂載配置檔案格式
挂載檔案的父目錄    建立一個檔案/etc/auto.的挂載配置檔案
挂載配置檔案的配置/etc/auto.
挂載檔案的子目錄   -fstype=nfs(指定檔案類型,這裡是NFS) 指定ip加上檔案路徑   
重新開機autofs服務           

1、安裝軟體包

yum –y install nfs-utils portmap

2、修改主配置檔案

vim /etc/exports

/root 192.168.10.20(rw,sync,no_root_squash)

/usr/src 192.168.10.0/24(rw,async,all_squash)

3、啟動服務

service portmap restart

service nfs restart

chkconfig portmap on

chkconfig nfs on

4、設定目錄權限

setfacl -m u:nfsnobody:rwx /usr/src/

用戶端測試:

showmount -e 192.168.10.10

Export list for 192.168.10.10:

/root 192.168.10.20

/usr/src 192.168.10.0/24

[root@ser2 ~]# mkdir -p /data/{src,root}

[root@ser2 ~]# mount -t nfs 192.168.10.10:/root/ /data/root/

[root@ser2 ~]# mount -t nfs 192.168.10.10:/usr/src/ /data/src/

[root@ser2 ~]# touch /data/root/file1.txt

[root@ser2 ~]# touch /data/src/file1.txt

[root@ser2 ~]# ls -l /data/{root,src}/file1.txt

-rw-r--r-- 1 root root 0 11-19 17:36 /data/root/file1.txt

-rw-r--r-- 1 nfsnobody nfsnobody 0 11-19 17:36 /data/src/file1.txt