ubuntu12.04的NFS配置


安裝nfs:

#sudo apt-get install nfs-kernel-server

ubuntu12.04中的已經是最新版本了,無需安裝

打開/etc/exports文件,在末尾加入:

/home/kevin *(rw,sync,no_root_squash)

注:nfs允許掛載的目錄及權限,在文件/etc/exports中進行定義,各字段含義如下:

/home/kevin:要共享的目錄

* :允許所有的網段訪問

rw :讀寫權限

sync:資料同步寫入內在和硬盤

no_root_squash:nfs客戶端共享目錄使用者權限

重啟服務:
#sudo /etc/init.d/portmap restart                  <---重啟portmap,
#sudo /etc/init.d/nfs-kernel-server restart      <---重啟nfs服務
#showmount -e                                          <---顯示共享出的目錄

注:nfs是一個RPC程序,使用它前,需要映射好端口,通過portmap設定

命令執行情況如下:

kevin@ubuntu:~$sudo /etc/init.d/portmap restart
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service portmap restart

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the restart(8) utility, e.g. restart portmap
portmap start/running, process 474


kevin@ubuntu:~$sudo /etc/init.d/nfs-kernel-server restart
 * Stopping NFS kernel daemon                                              [ OK ]
 * Unexporting directories for NFS kernel daemon...                   [ OK ]
 * Exporting directories for NFS kernel daemon...     

  exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home/xgc".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x
                                                                                 [ OK ]
 * Starting NFS kernel daemon                                       [ OK ]

kevin@ubuntu:~$showmount -e
Export list for xgc-VirtualBox:
/home/kevin *

 

現在可以在本機上試一下:
#sudo mount -t nfs localhost:/home/kevin /mnt

注:localhost為本機linux的IP地址

這樣就把共享目錄掛到了/mnt目錄,取消掛載用:
#sudo umount /mnt

如果用在嵌入式設備上掛載,要加上參數-o nolock

我在開發板上使用的掛載命令:

mount -t nfs -o nolock 192.168.1.8:/home/kevin /mnt


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM