ubuntu虚拟机安装NFS服务器

    xiaoxiao2021-03-25  140

    ------------------------------------ubuntu虚拟机安装NFS服务器--------------------------- 方法如下: 一、虚拟机设置(如果网络已经设置在桥接方式,跳过这步) 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; ------------------------------------NFS挂载--------------------------------------------------------------------------------------------------------- ARM开发板上挂载虚拟机中Ubuntu?12.10的网络文件系统NFS ? 1.设置IP地址 将主机IP设为192.168.1.111,子网掩码255.255.255.0,默认网关:192.168.1.1(主机网络共享中心中除了本地连接以外的连接全部禁用) 在VMware中设置网络为桥接方式,与ARM板进行通信,只能用Bridge方式,然后进入客户机Linux,关闭自动获取IP,改为手动设置:IP?192.168.1.110,子网掩码255.255.255.0,默认网关:192.168.1.1(可以用ARM板:192.168.1.230,子网掩码255.255.255.0 2.建立和配置NFS服务 (1)设置共享目录 sudo gedit /etc/exports 编辑nfs服务的配置文件(注意:第一次打开时该文件是空的),添加以下内容: /opt/FriendlyARM/mini 6410/linux/root_qtopia _qt4 -(rw,sync,no_root_squash) 其中: /opt/FriendlyARM/mini6410/linux/root_qtopia _qt4表示将要共享的的目录(可以根据自己的需要设置),它可以作为开发板的根文件系统通过nfs挂接; (2)通过命令启动,停止,重启nfs服务 /etc/init.d/nfs-kernel-server start/stop/restart (3)虚拟机连接开发板 Sudo Telnet 192.168.1.230 然后输入root,即进入开发板命令行界面 或者使用minicom(可参见minicom的博文) 4.?在arm开发板上挂载NFS文件系统 arm板启动后,在终端中输入命令: mount –t nfs –o nolock 192.168.1.110:/opt/FriendlyARM/mini6410/linux/root_qtopia_qt4 /mnt 挂载成功后,输入命令:ls /mnt,就可以看到ubuntu中/root_qtopia_qt4/共享的文件了。 若是可执行文件要运行的话,输入命令: cd ?/mnt ./codename
    转载请注明原文地址: https://ju.6miu.com/read-4390.html

    最新回复(0)