1. 程式人生 > >Centos7.4 搭建NFS網路檔案系統服務

Centos7.4 搭建NFS網路檔案系統服務

1.將伺服器端和客戶端,檢視防火牆狀態並關閉防火牆

systemctl status firewalld
systemctl disable firewalld
systemctl stop  firewalld

2.將伺服器端和客戶端安裝元件(nfs-utils,rpcbind)

 yum install -y  nfs-utils rpcbind 

3.在伺服器端和客戶端啟動以上兩個服務 

systemctl status rpcbind
systenctl enable rpcbind
systemctl start rpcbind
systemctl status nfs
systemctl enable nfs
systemctl start nfs

4. 在伺服器端建立共享目錄,並設定共享目錄 

mkdir -p /cloud/nfs/data 
chmod 777 /cloud/nfs/data
vim /etc/exports

新增以下內容:

/cloud/nfs/data/  *(rw,sync,no_root_squash)

 如果出現許可權拒絕 mount  改成以下設定

mount.nfs: access denied by server while mounting 10.21.111.12:/cloud/persistence/files

/cloud/persistence/files  *(insecure,rw,sync,no_root_squash)

引數說明:

eg: /usr/nfsShare 192.111.134.*(rw,sync,no_root_squash) 【可將IP設定為*】
格式 : NFS共享的目錄 NFS客戶端地址1(引數1,引數2,...) 客戶端地址2(引數1,引數2,...)
/cloud/nfs/data  :共享目錄
ro:目錄只讀
rw:目錄讀寫
sync:將資料同步寫入記憶體緩衝區與磁碟中,效率低,但可以保證資料的一致性,資料會先暫存於記憶體中,而非直接寫入硬碟
async:將資料先儲存在記憶體緩衝區中,必要時才寫入磁碟
all_squash:將遠端訪問的所有普通使用者及所屬組都對映為匿名使用者或使用者組(nfsnobody)
no_all_squash:與all_squash取反(預設設定)
root_squash:將root使用者及所屬組都對映為匿名使用者或使用者組(預設設定)
no_root_squash:當登入NFS主機使用共享目錄的使用者是root時,其許可權將被轉換成為匿名使用者,通常它的UID與GID 都會變成nobody身份
anonuid=xxx:將遠端訪問的所有使用者都對映為匿名使用者,並指定該使用者為本地使用者(UID=xxx)
anongid=xxx:將遠端訪問的所有使用者組都對映為匿名使用者組賬戶
/cloud/nfs/data :共享目錄 ro:目錄只讀 rw:目錄讀寫 sync:將資料同步寫入記憶體緩衝區與磁碟中,效率低,但可以保證資料的一致性,資料會先暫存於記憶體中,而非直接寫入硬碟 async:將資料先儲存在記憶體緩衝區中,必要時才寫入磁碟 all_squash:將遠端訪問的所有普通使用者及所屬組都對映為匿名使用者或使用者組(nfsnobody) no_all_squash:與all_squash取反(預設設定) root_squash:將root使用者及所屬組都對映為匿名使用者或使用者組(預設設定) no_root_squash:當登入NFS主機使用共享目錄的使用者是root時,其許可權將被轉換成為匿名使用者,通常它的UID與GID 都會變成nobody身份 anonuid=xxx:將遠端訪問的所有使用者都對映為匿名使用者,並指定該使用者為本地使用者(UID=xxx) anongid=xxx:將遠端訪問的所有使用者組都對映為匿名使用者組賬戶

        1.    /cloud/nfs/data  共享的目錄

        2.    * :任何人

        3.   rw :讀寫許可權

        4.  sync:資料會先暫存於記憶體中,而非直接寫入硬碟。

        5.   no_root_squash:當登入NFS主機使用共享目錄的使用者是root時,其許可權將被轉換成為匿名使用者,通常它的UID與GID                                             都會變成nobody身份。

5.重啟服務

systemctl restart nfs
systemctl restart rpcbind

6.在客戶端安裝好nfs-utils,rpcbind後,啟動服務,建立需要掛載到伺服器上的目錄

mkdir -p /cloud/log

7.掛載目錄 

 mount -t nfs 172.20.3.163:/cloud/nfs/data/log  /cloud/log

8.測試

    在客戶端/cloud/log 下建立一個檔案 touch test.log, 在伺服器上的共享目錄/cloud/nfs/data/log 下就會看到建立的檔案

9.分享一個項中的真例項子

 192.168.1.9 是nfs伺服器端,

  192.168.1.10 上傳檔案系統例項1 

 192.168.1.11 上傳檔案系統例項2

上傳檔案系統部署了兩個例項,上傳的目錄為:/cloud/data/uploadfiles 

 所以步驟如下:

  9.1.  分別在以上三臺上安裝nfs-utils,rpcbind,啟動 ,在192.168.1.9上的/etc/exports配置檔案中加上以下:

/cloud/data/uploadfiles  *(rw,sync,no_root_squash)

以上先要建立目錄 

mkdir -p   /cloud/data/uploadfiles

 9.2 重啟nfs ,rpcbind服務

在10 和11檔案伺服器上分別建立目錄

mkdir -p   /cloud/data/uploadfiles

再在10,11上都執行以下命令,如下:

 mount -t nfs 192.168.1.9:/cloud/data/uploadfiles  /cloud/data/uploadfiles

這個時候,在一個機器上的/cloud/data/uploadfiles下新增檔案,其他兩臺的同一個目錄 下都會同步存在檔案