20、NFS配置详解

1、NFS介绍

NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。


NFS支持的功能特别多,不同功能通过不同的程序来实现,不同的程序使用不同的端口,为此需要RPC(远程调用服务)协议来实现客户端的协调。

当NFS服务启动时会随机取用数个端口,并主动向RPC服务注册取用的相关端口信息,RPC服务就可以知道每个端口所对应的NFS功能了,然后RPC服务使用固定的端口号111来监听NFS客户端提交的请求,并将正确的NFS端口答应给NFS客户端,这样一来,就可以让NFS客户端与服务端进行数据传输了


/etc/exports文件格式

文件系统  客户端1(文件系统导出属性) 客户端2(文件系统导出属性) 


客户端

   IP 192.168.130.212

   Hostname *.test.com

   IP networks 192.168.130.0/24


文件系统导出属性  

   rw 读写

   async sync 则代表数据会先暂存于内存当中,而非直接写入硬盘!

   sync sync表示同步更新到磁盘,同步将内存内的文件写入到磁盘空间,保证数据不丢失,但会影响性能

   root_squash 压缩root用户,基于imapd,将root通过网络访问时转换为nfsnobody用户

   no_root_squash 不压缩用户

   all_squash 压缩所有用户,身份都会被压缩成为匿名用户

   anonuid,anongid 指定匿名用户的用户ID和组ID,必须存在于/etc/passwd中。结合all_squash使用。


常见配置

/data 192.168.130.0/24(ro)                                           

/data 192.168.130.0/24(rw,sync)                                     

/data 192.168.130.0/24(rw,sync,all_squash,anonuid=2000,anongid=2000)



2、NFS配置

服务器端

yum -y install nfs-utils rpcbind

mkdir /data

groupadd -g 2000 nfsuser

useradd -s /sbin/nologin -u 2000 -g 2000 nfsuser

chown nfsuser:nfsuser /data/


cat /etc/exports 

/data 192.168.130.0/24(rw,sync,all_squash,anonuid=2000,anongid=2000)


service rpcbind restart

service nfs restart

chkconfig rpcbind on

chkconfig nfs on


客户端

showmount -e 192.168.130.61

mount -t nfs 192.168.130.61:/data /mnt


3、nfs的辅助进程mountd等监听在固定端口上,可以通过在编辑/etc/sysconfig/nfs等参数来实现

RQUOTAD_PORT=30001

LOCKD_TCPPORT=30002

LOCKD_UDPPORT=30002

MOUNTD_PORT=30003

STATD_PORT=30004 


[root@localhost build]# rpcinfo -p 192.168.130.61

   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

    100011    1   udp    875  rquotad

    100011    2   udp    875  rquotad

    100011    1   tcp    875  rquotad

    100011    2   tcp    875  rquotad

    100005    1   udp  37081  mountd

    100005    1   tcp  47329  mountd

    100005    2   udp  53366  mountd

    100005    2   tcp  35697  mountd

    100005    3   udp  40155  mountd

    100005    3   tcp  46134  mountd

    100003    2   tcp   2049  nfs

    100003    3   tcp   2049  nfs

    100003    4   tcp   2049  nfs

    100227    2   tcp   2049  nfs_acl

    100227    3   tcp   2049  nfs_acl

    100003    2   udp   2049  nfs

    100003    3   udp   2049  nfs

    100003    4   udp   2049  nfs

    100227    2   udp   2049  nfs_acl

    100227    3   udp   2049  nfs_acl

    100021    1   udp  41317  nlockmgr

    100021    3   udp  41317  nlockmgr

    100021    4   udp  41317  nlockmgr

    100021    1   tcp  36015  nlockmgr

    100021    3   tcp  36015  nlockmgr

    100021    4   tcp  36015  nlockmgr


[root@localhost build]# rpcinfo -p 192.168.130.61

   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

    100011    1   udp  30001  rquotad

    100011    2   udp  30001  rquotad

    100011    1   tcp  30001  rquotad

    100011    2   tcp  30001  rquotad

    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    2   tcp   2049  nfs

    100003    3   tcp   2049  nfs

    100003    4   tcp   2049  nfs

    100227    2   tcp   2049  nfs_acl

    100227    3   tcp   2049  nfs_acl

    100003    2   udp   2049  nfs

    100003    3   udp   2049  nfs

    100003    4   udp   2049  nfs

    100227    2   udp   2049  nfs_acl

    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


猜你喜欢

转载自blog.51cto.com/kaiyuandiantang/2299256