NFS(Network File System)即網絡文件系統,是FreeBSD支持的文件系統中的一種,它容許網絡中的計算機之間經過TCP/IP網絡共享資源。在NFS的應用中,本地NFS的客戶端應用能夠透明地讀寫位於遠端NFS服務器上的文件,就像訪問本地文件同樣。linux
如下是NFS最顯而易見的好處:ubuntu
NFS體系至少有兩個主要部分:bash
一臺NFS服務器和若干臺客戶機,如右圖所示。
客戶機經過TCP/IP網絡遠程訪問存放在NFS服務器上的數據。
在NFS服務器正式啓用前,須要根據實際環境和需求,配置一些NFS參數。服務器
NFS 有不少實際應用。下面是比較常見的一些:網絡
NFS是運行在應用層的協議。隨着NFS多年的發展和改進,NFS既能夠用於局域網也能夠用於廣域網,且與操做系統和硬件無關,能夠在不一樣的計算機或系統上運行。this
$ sudo apt-get install nfs-kernel-server
打開/etc/exports文件,在末尾加入:操作系統
/home/kevin *(rw,sync,no_root_squash) 注:nfs容許掛載的目錄及權限,在文件/etc/exports中進行定義,各字段含義以下: /home/kevin:要共享的目錄 * :容許全部的網段訪問 rw :讀寫權限 sync:資料同步寫入內在和硬盤 no_root_squash:nfs客戶端共享目錄使用者權限
重啓服務:rest
$sudo /etc/init.d/portmap restart <---重啓portmap, 1604更名爲rpcbind $sudo /etc/init.d/nfs-kernel-server restart <---重啓nfs服務 $showmount -e <---顯示共享出的目錄
注:nfs是一個RPC程序,使用它前,須要映射好端口,經過portmap設定
命令執行狀況以下:code
$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
$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 ]
$showmount -e Export list for xgc-VirtualBox: /home/kevin *
如今能夠在本機上試一下:server
$sudo mount -t nfs localhost:/home/kevin /mnt sudo mount –t nfs 共享主機ip:/rootfs 掛載點 注:localhost爲本機linux的IP地址
這樣就把共享目錄掛到了/mnt目錄,取消掛載用:
$sudo umount /mnt 卸載 : umount -e 掛載點 // 注意卸載時命令的執行路徑不可以是掛載點
若是用在嵌入式設備上掛載,要加上參數-o nolock
我在開發板上使用的掛載命令:
#mount -t nfs -o nolock 192.168.1.8:/home/kevin /mnt