12月7日任務
14.1 NFS介紹
14.2 NFS服務端安裝配置
14.3 NFS配置選項linux
一.NFS介紹vim
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
- NFS是Network File System的縮寫
- NFS最先由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新爲4.1版本
- NFS數據傳輸基於RPC協議,RPC爲Remote Procedure Call的簡寫。
- NFS應用場景是:A,B,C三臺機器上須要保證被訪問到的文件是同樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致
- RPC服務會自動生成RPC協議,RPC協議會監聽111端口
二.NFS服務端安裝配置app
![](http://static.javashuo.com/static/loading.gif)
示例一:async
- 準備兩臺機器,一個作服務端,一個作客戶端。
- yum install -y nfs-utils 客戶端安裝
- yum install -y nfs-utils rpcbind 服務端安裝
- vim /etc/exports //加入以下內容
/home/nfstestdir 選擇一個目錄,保證這兩個機器的目錄是同樣的測試
192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000) 定義給那個機器共享你的目錄ui
![](http://static.javashuo.com/static/loading.gif)
- 保存配置文件後,執行以下準備操做
- mkdir /home/nfstestdir 建立共享的目錄
- chmod 777 /home/nfstestdir 設置權限
- 安裝完就會自動啓動rpcbind服務,能夠用netstat -lnpt 查看一下
![](http://static.javashuo.com/static/loading.gif)
- systemctl start rpcbind 這一步就能夠省略了
- systemctl start nfs 再啓動nfs服務
- systemctl enable rpcbind 設置rpcbind服務開機啓動
- systemctl enable nfs 設置nfs服務開機啓動
- systemctl disable nfs 能夠取消開機啓動
三.NFS配置選項spa
![](http://static.javashuo.com/static/loading.gif)
- rw 讀寫
- ro 只讀
- sync 同步模式,內存數據實時寫入磁盤 ,能夠很快的把數據寫入到磁盤裏去,可是會相對的下降磁盤的效率
- async 非同步模式 ,每隔一段時間,會把數據寫入到磁盤裏去, 若是忽然斷電等狀況出現,可能會丟失一部分數據
- no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大
- root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶
- all_squash 客戶端上全部用戶在使用NFS共享目錄時都被限定爲一個普通用戶
- anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid
示例一:在客戶端掛載操做blog
![](http://static.javashuo.com/static/loading.gif)
- yum install -y nfs-utils
- showmount -e 192.168.133.130 //該ip爲NFS服務端ip ,測試一下,是否有權限跟服務端連統統信,若是不能通訊,有多是防火牆,服務端未開啓RPC服務,未監聽111端口等問題。
- 以下則是正常能夠通訊
![](http://static.javashuo.com/static/loading.gif)
- mount -t nfs 192.168.133.130:/home/nfstestdir /mnt 掛載目錄
- df -h 查看一下是否掛載
![](http://static.javashuo.com/static/loading.gif)
- cd /mnt/ 進入目錄下
- touch /mnt/aminglinux.txt 建立一個文件
- ls -l /mnt/aminglinux.txt //能夠看到文件的屬主和屬組都爲1000,由於配置文件裏限定了uid爲1000
- 服務端
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)