OpenWrt:构建nfs服务

主机安装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)项时,rwsync之间存在空格,去除掉空格保存,重新运行命令即可。再次查看下是否安装了服务:

$ 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 挂载错误

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值