防火墙都是关闭的 服务端

[root@localhost ~]# yum -y install rpcbind nfs-utils

编辑/etc/exportsp配置文件配置共享目录(配置文件默认可能没有) root@ubuntu:~# cat /etc/exports #共享目录 允许访问的IP或网段(参数) /nfs 192.168.6.0/24(rw,sync,no_root_squash

先启动rpcbind再启动nfs
[root@localhost ~]# systemctl enable --now rpcbind.service
[root@localhost ~]# systemctl enable --now nfs.service


用于配置NFS服务程序配置文件的参数:

参数1 作用 2
ro 只读
rw (常用参数) 读写
root_squash 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户nfsnobody
no_root_squash(常用参数) **当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员 **
all_squash 无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户nfsnobody
sync(常用参数) ** 同时将数据写入到内存与硬盘中,保证不丢失数据 **
async 优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据

[root@NFS ~]# exportfs -arv #重载配置文件导出信息 exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.6.0/24:/nfs". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x

exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.6.0/24:/nfs123". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x

exporting 192.168.6.0/24:/nfs123 exporting 192.168.6.0/24:/nfs

查看NFS服务是否向rpc注册端口信息,rpc端口号:111 nfs主程序端口号:2049,客户端也可以执行此命令

root@ubuntu:~# rpcinfo -p 192.168.6.240
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100005    1   udp  51536  mountd
    100005    1   tcp  38605  mountd
    100005    2   udp  36598  mountd
    100005    2   tcp  51885  mountd
    100005    3   udp  46768  mountd
    100005    3   tcp  43378  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049
    100021    1   udp  58186  nlockmgr
    100021    3   udp  58186  nlockmgr
    100021    4   udp  58186  nlockmgr
    100021    1   tcp  46484  nlockmgr
    100021    3   tcp  46484  nlockmgr
    100021    4   tcp  46484  nlockmgr

nfs向rpc注册的端口是随机的防火墙不容易管理端口,通过配置文件固定端口的方式可以解决 cat /etc/sysconfig/nfs #固定nfs的端口 RQUOTAD_PORT=30001 LOCKD_TCPPORT=30002 LOCKD_UDPPORT=30002 MOUNTD_PORT=30003 STATD_PORT=30004 然后重启rpc和nfs服务 service rpcbind restart service nfs restart

[root@Ubuntu ~]#rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  30004  status
    100024    1   tcp  30004  status
    100005    1   udp  30003  mountd
    100005    1   tcp  30003  mountd
    100005    2   udp  30003  mountd
    100005    2   tcp  30003  mountd
    100005    3   udp  30003  mountd
    100005    3   tcp  30003  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  30002  nlockmgr
    100021    3   udp  30002  nlockmgr
    100021    4   udp  30002  nlockmgr
    100021    1   tcp  30002  nlockmgr
    100021    3   tcp  30002  nlockmgr
    100021    4   tcp  30002  nlockmgr

客户端 客户端仅仅安装rpcbind和nfs-utils软件包即可,不用启动 [root@localhost ~]# yum -y install rpcbind nfs-utils 查看服务端共享的路径(服务端也可以执行此命令)

root@ubuntu:~# showmount -e 192.168.6.240
Export list for 192.168.6.240:
/nfs 192.168.6.0/24

挂载服务端目录到本地

root@ubuntu:~# mount 192.168.6.240:/nfs /root/shou
root@ubuntu:~# df -h |grep 192.168.6.240
192.168.6.240:/nfs  184G  5.4G  169G   4% /root/shou

排查错误: 示例1:卸载挂载设备时显示device is busy。

[root@nfs-client mnt]# umount /mnt
umount.nfs: /mnt: device is busy
umount.nfs: /mnt: device is busy

解答:有可能是当前目录就是挂载的NFS目录(/mnt),也有可能是NFS Server挂了。对于第一种情况,解决办法为退出挂载目录/mnt,再执行umount /mnt卸载。对于第二种情况,NFS Server挂了,NFS Client就会出现问题(df -h窗口会死掉),这时只能强制卸载,方法为: umount -lf /mnt 其中的参数-f为强制卸载,参数-l为懒惰的卸载。

示例2:CentOS 6.6客户端NFS挂载时遇到问题。

[root@nfs-client ~]# mount -t nfs 172.16.1.9:/data /mnt
mount:wrong fs type,bad option,bad option,bad superblock on 10.0.0.7:/data,
   missing codepage or helper program,or other error
   (for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program )
In some cases useful info is found in syslog - try
meg | tail or so

排查思路:同样的机器,NFS服务器本地可以挂载,但是客户端挂载时wrong fs type,因此尝试所有客户端安装nfs-utils。CentOS6.5及以前的NFS没有遇到这个问题。 解决方法:执行yum install nfs-utils -y,客户端安装NFS软件,但不启动服务。