检测是否安装nfs-utilsportmap软件包,portmap(rpcbind)服务的端口号为111,nfs的端口号由portmap(rpcbind)服务分配,所以开启nfs服务必须要先开启portmap(rpcbind)服务。

[root@localhost ~]# rpm -q nfs-utils
nfs-utils-1.0.9-66.el5
[root@localhost ~]# rpm -q portmap
portmap-4.0-65.2.2.1

编辑主配置文件

[root@localhost ~]# vim  /etc/exports
/root           172.16.10.0/24(rw,sync,no_root_squash)
共享的目录允    许访问的IP地址(参数,参数)
客户端地址
	IP地址:192.168.4.20
	网段地址:172.0.0.0/24 或 172.0.0.*
	所有主机:*
	单个域:*.tarena.com 
	主机名:pc110.tarena.com
参数,不同参数之间用逗号隔开
	rw、ro:可读可写、只读
	sync、async:同步写、异步写入
	no_root_squash:保留来自客户端的root权限
	all_squash:客户端权限都降为nfsnobody

重启服务设置服务开机自启动

[root@localhost ~]# service portmap restart
[root@localhost ~]# service nfs restart
[root@localhost ~]# chkconfig portmap on
[root@localhost ~]# chkconfig nfs on

客户端访问共享

[root@localhost ~]# showmount -e  172.16.10.1   查看
Export list for172.16.10.1:
/root172.16.10.0/24
[root@localhost ~]# mount 172.16.10.1:/root  /mnt  挂载共享目录到本地目录下
[root@localhost ~]# df -h
文件系统容量已用可用已用% 挂载点
/dev/sda2              95G  2.6G  88G   3% /
/dev/sda3              95G  188M  90G   1% /data
/dev/sda6              99M   12M  82M  13% /boot
tmpfs                 500M     0 500M   0% /dev/shm
172.16.10.1:/root      19G 2.7G   16G  15% /mnt

[root@localhost ~]# showmount -e 172.16.10.1

clnt_create: RPC: Program not registered

在查看nfs共享目录时可能会出现如上问题,检查iptables设置,检查portmap服务是否正常开启,重启portmap和nfs服务,要先重启portmap服务后启动nfs服务(6版本中为rpcbind服务)。

设置nfs为autoufs触发挂载

[root@localhost ly]# vim /etc/auto.master
/nfs    /etc/auto.nfs
[root@localhost ly]# vim /etc/auto.nfs
nfs      -fstype=nfs     172.16.10.1:/root/
[root@localhost ly]# /etc/init.d/autofs restart
停止 automount:                                           [确定]
正在启动 automount:                                       [确定]