歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> VMware中為Ubuntu安裝配置nfs服務

VMware中為Ubuntu安裝配置nfs服務

日期:2017/2/28 16:23:24   编辑:Linux教程
配置:vmware中安裝Ubuntu10.04 系統:windows XP 連接:開發板通過RS232和交叉網線與PC相連
方法如下: 一、虛擬機設置(如果網絡已經設置在橋接方式,跳過這步) 1、在啟動ubuntu前,將其Ethernet(網絡)連接方式設為Bridge(橋接方式) 2、啟動ubuntu,設置靜態ip地址(必須與開發板處於同一網段) lingd@ubuntu:~$ sudo ifconfig eth0 192.168.0.26 netmask 255.255.255.0
二、為ubuntu安裝NFS 1、安裝NFS lingd@ubuntu:~$ sudo apt-get install nfs-kernel-server 同時會有兩個軟件包nfs-common和portmap被安裝上 2.修改NFS配置文件 lingd@ubuntu:~$ vi /etc/exports 內容為: /home/lingd/arm 192.168.0.*(rw,sync,no_root_squash,no_subtree_check)
/home/lingd/arm---要共享的目錄 192.168.0.*---允許訪問的網段,也可以是ip地址、主機名(能夠被服務器解析)、*(所有人都能訪問) (rw,sync,no_root_squash,no_subtree_check)---rw:讀/寫權限 sync:數據同步寫入內存和硬盤 no_root_squash:服務器允許遠程系統以root特權存取該目錄 no_subtree_check:關閉子樹檢查 其他選項可以通過man exports查閱man文檔
3、啟動服務 重啟portmapper(端口映射)服務 lingd@ubuntu:~$ sudo service portmap restart portmap start/running, process 550 重啟NFS服務 lingd@ubuntu:~$ sudo service nfs-kernel-server restart * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon... [ OK ] * Starting NFS kernel daemon [ OK ]

三、測試 1、本機掛載 lingd@ubuntu:~$ ls /mnt/nfs/ lingd@ubuntu:~$ sudo mount -t nfs -o nolock localhost:/home/lingd/arm/ /mnt/nfs/ lingd@ubuntu:~$ ls /mnt/nfs/ cross-3.4.1.tar.bz2 linux-2.6.12 upload download msap VMwareTools-8.1.3-203739.tar.gz DSDT_2[1].8b.zip ntp vmware-tools-distrib DSDT_2.8b protocol-converter 安裝包 lingd@ubuntu:~$ sudo umount /mnt/nfs lingd@ubuntu:~$ ls /mnt/nfs/
2、開發板掛載 lingd@ubuntu:~$ telnet 192.168.0.25 2009 Trying 192.168.0.25... Connected to 192.168.0.25. Escape character is '^]'.
(none) login: root Password: ~ # ls /mnt ext1 ext2 ~ # mount -t nfs -o nolock 192.168.0.26:/home/lingd/arm /mnt ~ # ls /mnt DSDT_2.8b msap DSDT_2[1].8b.zip ntp VMwareTools-8.1.3-203739.tar.gz protocol-converter cross-3.4.1.tar.bz2 upload download vmware-tools-distrib linux-2.6.12 安裝包 ~ # umount /mnt ~ # ls /mnt ext1 ext2 ~ #
四、掛載nfs文件系統失敗的原因 1、nfs錯誤信息 Too many levels of remote in path:試圖掛載一個存在的文件系統 Permission denied:NFS服務器不讓客戶機掛接,也可能是因為用戶在服務器上不存在 No such host:通常是DNS配置錯誤 No such file or directory:通常是訪問的目錄不存在 NFS server is not responding:通常是NFS已經超過負載或者NFS已經停止工作 Stale file handle:在NFS客戶端關閉之前客戶端訪問的文件被刪除 Fake hostname:Forward和reverse的DNS記錄在NFS客戶端下不存在 2、掛載nfs文件系統失敗的原因 (1)主機和網絡不通:看看網線連接、主機和開發板ip是否在同一網段、防火牆有沒有關閉等。不僅vmware中linux的防火牆要關閉,vmware外xp的防火牆也要關閉,我就因為xp中的eset殺毒軟件的防火牆使nfs無法掛載(可以掛本機,無法掛遠程),折騰了一天,後來才發現是xp中的防火牆搞的鬼!
(2)使用的mount命令不正確。可以參照上面的例子改一下;或者man nfs查閱一下nfs的man文檔,裡面有nfs中mount的使用介紹和選項解釋
(3)nfs配置文件/etc/exports配置不正確。可以參照上面的例子改一下;或者man exports查閱一下/etc/exports的man文檔
(4)必要時重新啟動NFS和portmap服務。 sudo service portmap restart sudo service nfs-kernel-server restart
(5)內核不支持NFS和RPC服務(可能需要重新配置、編譯、燒寫內核)。 普通的內核應有的選項為CONFIG_NFS_FS=m、CONFIG_NFS_V3=y、CONFIG_ NFSD=m、CONFIG_NFSD_V3=y和CONFIG_SUNRPC=m。 rpcinfo命令用於顯示系統的RPC信息,一般使用-p參數列出某台主機的RPC服務。rpcinfo -p命令檢查服務器時,應該能看到portmapper、status、mountd、nfs和nlockmgr。用該命令檢查客戶端時,應該至少能看到portmapper服務(開發板可能不帶該命令)。由rpcinfo -p可知,nfs使用的port為2049,portmapper使用111port。
五、nfs相關的配置文件與命令 1、/etc/exports NFS的主要配置文件,不過系統並沒有默認值,所以這個文件不一定會存在(需要自己建立)。
2、/usr/sbin/exportfs 用於維護NFS共享資源的命令,用在nfs server端。修改/etc/exports後,只要使用exportfs重新掃瞄一次 /etc/exports,重新將設定加載即可,並不一定要重啟nfs服務 命令格式: exportfs [-aruv] 參數說明如下。 (1)-a:全部掛載或卸載(export or unexpect)/etc/exports文件內的目錄。 (2)-r:重新掛載(reexport)/etc/exports中的目錄,並將/var/lib/nfs/etab中的內容與/etc/exports同步。 (3)-u:卸載某些目錄。 (4)-v:顯示exportfs處理信息。
3、/usr/sbin/showmount 用於查看指定主機NFS共享出來的目錄資源,主要用在Client端。 命令格式: showmount [-ade] hostname/服務器ip地址 參數說明如下。 (1)-a或-all:以host:dir格式顯示客戶主機名和掛載的目錄。 (2)-d或-directories:僅顯示被客戶掛載的目錄名。 (3)-e或-exports:顯示指定NFS服務器的nfs共享目錄。
4、/var/lib/nfs/etab /etc/exports裡列舉的是用戶希望nfs共享的目錄,而/var/lib/nfs/etab裡面是ubuntu實際共享的目錄。它記錄了NFS所共享出來的目錄的完整權限設定值。/var/lib/nfs/etab由exportfs維護,每次exportfs都會掃描/etc/exports以建立新的/var/lib/nfs/etab,每當nfs客戶請求掛載共享目錄時mountd都會讀取該文件以檢測客戶和目錄的權限。同時/var/lib/nfs/etab中共享的目錄會保存在內核nfs共享表(export table)中
5、其他nfs相關文件的解析 /var/lib/nfs/etab contains information about what filesystems should be exported to whom at the moment. /var/lib/nfs/rmtab contains a list of which filesystems actually are mounted by certain clients at the moment. /proc/fs/nfs/exports contains information about what filesystems are exported to actual client (individual, not subnet or whatever) at the moment. /var/lib/nfs/xtab is the same information as /proc/fs/nfs/exports but is maintained by nfs-utils instead of directly by the kernel. It is only used if /proc isn't mounted. * /var/lib/nfs/etab: the /etc/exports file only contains a wish list. etab is created by exportfs. It contains on each line detailed information about the options used when exporting a file system towards a single client. It's the reference file used by rpc.mountd when started * /proc/fs/nfs/exports contains the clients list as known by the kernel * /var/lib/nfs/xtab: Use for accuracy when etab holds client names and machines groups with wildcards. This file only contains explicit machine names. * /var/lib/nfs/rmtab : each line shows the client's name and the file system imported from this server;
Copyright © Linux教程網 All Rights Reserved