1. 程式人生 > >14.1 NFS介紹;14.2 NFS服務端安裝配置;14.3 NFS配置選項

14.1 NFS介紹;14.2 NFS服務端安裝配置;14.3 NFS配置選項

NFS服務端安裝配置

14.1 NFS介紹

1. NFS是Network File System的縮寫

2. NFS最早由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新為4.1版本

3. NFS數據傳輸基於RPC協議,RPC為Remote Procedure Call的簡寫。

4. NFS應用場景是:A,B,C三臺機器上需要保證被訪問到的文件是一樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致

技術分享圖片技術分享圖片

NFS原理圖

技術分享圖片技術分享圖片

14.2 NFS服務端安裝配置

準備兩個centos 7版本服務器:hao1服務端 hao2客戶端

1. hao1服務端

安裝

[root@hao-01 ~]# yum install -y nfs-utils rpcbind

2. 編輯添加內容

[root@hao-01 ~]# vim /etc/exports

添加內容:

[ 共享目錄 ip段.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) ]

/home/nfstestdir 192.168.211.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

3. 創建共享目錄

[root@hao-01 ~]# mkdir /home/nfstestdir

4. 共享目錄設置777權限

[root@hao-01 ~]#

chmod 777 /home/nfstestdir

5. 啟動rpcbind服務:

[root@hao-01 ~]# systemctl start rpcbind

6. 搜索rpcbind是否啟動?

[root@hao-01 ~]# ps aux |grep rpcbind

技術分享圖片技術分享圖片

7. 查看rpcbind監聽端口(顯示systemd也是正常的):

[root@hao-01 ~]# netstat -lnpt

技術分享圖片

8. 啟動nfs

[root@hao-01 ~]# systemctl start nfs

9. 搜索nfs是否啟動?

[root@hao-01 ~]# ps aux |grep nfs

技術分享圖片技術分享圖片

10. 設置nfs開機啟動

[root@hao-01 ~]#

systemctl enable nfs

技術分享圖片

14.3 NFS配置選項

NFS配置選項:

rw 讀寫

ro 只讀

sync 同步模式,內存數據實時寫入磁盤

async 非同步模式

no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大

root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶

all_squash 客戶端上所有用戶在使用NFS共享目錄時都被限定為一個普通用戶

anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid

1. hao2客戶端上安裝:

[root@hao-02 ~]# yum install -y nfs-utils rpcbind

2. 關閉hao1服務端防火墻

[root@hao-01 ~]# systemctl stop firewalld

[root@hao-01 ~]# getenforce

[root@hao-01 ~]# setenforce 0

3. 關閉hao2客戶端防火墻

[root@hao-02 ~]# systemctl stop firewalld

[root@hao-02 ~]# getenforce

[root@hao-02 ~]# setenforce 0

4. 訪問hao1服務端ip,查看服務端共享目錄ip段

[root@hao-02 ~]# showmount -e 192.168.211.128

技術分享圖片技術分享圖片

5. hao2客戶端 nfs掛載

mount -t nfs 服務端ip:共享目錄 掛載點

mount -t nfs 192.168.211.128:/home/nfstestdir /mnt

6. 查看掛載

[root@hao-02 ~]# df -h

技術分享圖片技術分享圖片

7. 掛載點mnt下,創建一個文件:

[root@hao-02 ~]# touch /mnt/hao.txt

8. hao2客戶端查看掛載點hao.txt文件 屬主 屬組

[root@hao-02 ~]# ls -l /mnt/hao.txt

技術分享圖片技術分享圖片

9. hao2客戶端查看mysql的id:

[root@hao-02 ~]# id mysql

技術分享圖片技術分享圖片

10. hao1服務端查看共享目錄下的hao.txt文件 屬主 屬組

[root@hao-01 ~]# ls -l /home/nfstestdir/hao.txt

技術分享圖片技術分享圖片

11. hao1服務端查看mysql的id:

[root@hao-01 ~]# id mysql

技術分享圖片技術分享圖片

12. 因為/etc/exports裏設置了anonuid=1000,anongid=1000

所以屬主屬組就顯示的機器對應的1000id用戶


14.1 NFS介紹;14.2 NFS服務端安裝配置;14.3 NFS配置選項