主机安装nfs
服务
先通过命令dpkg -l | grep nfs
查看系统中是否安装了nfs
服务,如果没有安装可以在线安装nfs
服务和客户端及端口映射程序,命令为sudo apt-get install nfs-kernel-server nfs-common portmap
。安装好后修改共享的配置文件/etc/exports
,内容如下:
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/opt/nfs *(rw,sync,no_root_squash)
*
:允许访问的网段,也可以是ip
地址、主机名(能够被服务器解析)、*
(所有人都能访问)rw
:读/写权限sync
:数据同步写入内存和硬盘no_root_squash
:服务器允许远程系统以root
特权存取该目录
保存exports
文件内容,回到shell
界面,启动端口映射服务rpcbind
,启动nfs
服务sudo /etc/init.d/nfs-kernel-server restart
。在调用sudo /etc/init.d/nfs-kernel-server restart
时,可能存在如下错误:
$ sudo /etc/init.d/nfs-kernel-server restart
[....] Restarting nfs-kernel-server (via systemctl): nfs-kernel-server.serviceJob for nfs-server.service failed because the control process exited with error code.
See "systemctl status nfs-server.service" and "journalctl -xe" for details.
failed!
原因是写配置文件中的/opt/nfs *(rw,sync,no_root_squash)
项时,rw
和sync
之间存在空格,去除掉空格保存,重新运行命令即可。再次查看下是否安装了服务:
$ dpkg -l | grep nfs
ii libnfsidmap2:amd64 0.25-5.1 amd64 NFS idmapping library
ii nfs-common 1:1.2.8-9.2ubuntu2 amd64 NFS support files common to client and server
ii nfs-kernel-server 1:1.2.8-9.2ubuntu2 amd64 support for NFS kernel server
设备端安装nfs
模块
在客户端,通过以下命令进行挂载:
# mount -t nfs -o nolock 192.168.0.103:/opt/nfs /mnt/nfs
mount: unknown filesystem type 'nfs'
出现以上错误,是因为系统没有加载nfs
模块,按照如下步骤进行配置:
Kernel modules --->
Filesystems --->
<M> kmod-fs-nfs....................................... NFS filesystem support
{M} kmod-fs-nfs-common......................... Common NFS filesystem modules
如果设备端已经联网,可以借助nc
命令来传输安装包,在PC
端输入以下命令:
$ nc -l -p 8888 < kmod-fs-nfs-common_3.18.29-1_ramips_24kec.ipk
在设备端输入以下命令:
# nc 192.168.0.103 8888 > kmod-fs-nfs-common_3.18.29-1_ramips_2
4kec.ipk
通过以下命令安装模块并加载:
# opkg install kmod-fs-nfs-common_3.18.29-1_mcs814x.ipk
# opkg install kmod-dnsresolver_3.18.29-1_ramips_24kec.ipk
# opkg install kmod-fs-nfs_3.18.29-1_mcs814x.ipk
安装时可能会出现如下的错误:
# opkg install kmod-fs-nfs-common_3.18.29-1_ramips_24kec.ipk
Installing kmod-fs-nfs-common (3.18.29-1) to root...
Collected errors:
* satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-fs-nfs-common:
* kernel (= 3.18.29-1-1d3698c5024a2e72757710ec3106cf17) *
* opkg_install_cmd: Cannot install package kmod-fs-nfs-common.
查看内核版本信息:
# opkg files kernel
Package kernel (3.18.29-1-d1781c74c51b6355c85968ac3e6c3eee) is installed on root and has the following files:
该问题由系统的版本与模块编译时依赖的版本不一致导致,具体的可以参考Opkg 内核不正确这篇文章。
出现以下错误,则先安装对应的模块:
# opkg install kmod-fs-nfs_3.18.29-1_ramips_24kec.ipk
Installing kmod-fs-nfs (3.18.29-1) to root...
Collected errors:
* satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-fs-nfs:
* kmod-fs-nfs-common * kmod-dnsresolver *
* opkg_install_cmd: Cannot install package kmod-fs-nfs.
参考文章
ubuntu下搭建nfs服务器
What does nfs-server.service code=exited
NFS Vagrant on Fedora 22
Opkg 内核不正确
nfs 挂载错误
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。