Server IP: 192.168.2.128
nfs, rpcbind(portmap) installed
Client IP: 192.168.2.254
nfs, rpcbind(portmap) installed
<pre style="background-color: rgb(255,250,233);">
[root@rhel6 tmp]# rpm -qa rpcbind
rpcbind-0.2.0-13.el6.x86_64
[root@rhel6 tmp]# rpm -qa nfs*
nfsometer-1.6-1.el6.noarch
nfs-ganesha-proxy-2.3.2-1.el6.x86_64
nfs-ganesha-mount-9P-2.3.2-1.el6.x86_64
nfs4-acl-tools-0.3.3-8.el6.x86_64
nfs-ganesha-utils-2.3.2-1.el6.x86_64
nfs-utils-lib-1.1.5-13.el6.x86_64
nfs-ganesha-vfs-2.3.2-1.el6.x86_64
nfs-ganesha-2.3.2-1.el6.x86_64
nfs-ganesha-nullfs-2.3.2-1.el6.x86_64
nfs-utils-1.2.3-75.el6.x86_64
</pre>
## 啟動服務
service rpcbind start
service nfs start
## 可以查看NFS服務端服務狀態
service rpcbind status
service nfs status
## Edit shared configuration on Server
[Filname: /etc/exports]
add line as below:
/path/to/shared/dir client-ip(option)
* 訪問權限選項
設置輸出目錄只讀:ro
設置輸出目錄讀寫:rw
* 用戶映射選項
all_squash:將遠程訪問的所有普通用戶及所屬組都映射為匿名用戶或用戶組(nfsnobody);
no_all_squash:與all_squash取反(默認設置);
root_squash:將root用戶及所屬組都映射為匿名用戶或用戶組(默認設置);
no_root_squash:與rootsquash取反;
anonuid=xxx:將遠程訪問的所有用戶都映射為匿名用戶,並指定該用戶為本地用戶(UID=xxx);
anongid=xxx:將遠程訪問的所有用戶組都映射為匿名用戶組賬戶,並指定該匿名用戶組賬戶為本地用戶組賬戶(GID=xxx);
* 其它選項
secure:限制客戶端只能從小於1024的tcp/ip端口連接nfs服務器(默認設置);
insecure:允許客戶端從大於1024的tcp/ip端口連接服務器;
sync:將數據同步寫入內存緩沖區與磁盤中,效率低,但可以保證數據的一致性;
async:將數據先保存在內存緩沖區中,必要時才寫入磁盤;
wdelay:檢查是否有相關的寫操作,如果有則將這些寫操作一起執行,這樣可以提高效率(默認設置);
no_wdelay:若有寫操作則立即執行,應與sync配合使用;
subtree:若輸出目錄是一個子目錄,則nfs服務器將檢查其父目錄的權限(默認設置);
no_subtree:即使輸出目錄是一個子目錄,nfs服務器也不檢查其父目錄的權限,這樣可以提高效率;
## Check out shared directory on Server
<pre style="background-color: rgb(255,250,233);">
[root@rhel6 tmp]# exportfs
/tmp/shared 192.168.2.254
[root@rhel6 tmp]# showmount -e
clnt_create: RPC: Unknown host
</pre>
but #1 problem occurs, and then edit the "/etc/hosts" file to specific the sever-ip pointing to itself's hostname, like
[Filename: /etc/hosts]
add line as below
server-ip server's hostname
<pre style="background-color: rgb(255,250,233);">
[root@rhel6 tmp]# showmount -e
Export list for rhel6.9.1:
/tmp/shared 192.168.2.254
[root@rhel6 tmp]# exportfs
/tmp/shared 192.168.2.254
</pre>
# Client
mount -t nfs server-ip:/path/to/share /mnt/specific-dir
客戶端在掛載的時候遇到的一個問題如下,可能是網絡不太穩定,NFS默認是用UDP協議,換成TCP協議即可:
mount -t nfs 192.168.2.128:/usr/local/test /usr/local/test -o proto=tcp -o nolock
---
Related Blog
[linux系統之間共享文件](https://blog.csdn.net/lizhou828/article/details/79197848)
[NFS掛載時出現"access denied by server while mounting"的解決方法](http://www.heminjie.com/system/linux/2998.html)