nfs:NFS是Network File System的缩写,网络文件系统NFS可以作为一个文件系统,在大环境中分布式,如:Moosefs,glusterfs,FastDFS等!
[root@NFS-WEB1 ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@NFS-WEB1 ~]# uname -r
2.6.32-504.el6.x86_64
在所有客户端都安装,但是只在nfs-server端启动服务和配置。客户端安装是因为有的命令依赖如showmount
[root@NFS-server ~]# yum install nfs-utils rpcbind -y
[root@NFS-WEB1 ~]# yum install nfs-utils rpcbind -y
[root@NFS-WEB2 ~]# yum install nfs-utils rpcbind -y
1,start rpcbind
[root@NFS-server ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@NFS-server ~]# /etc/init.d/rpcbind start
Starting rpcbind: [ OK ]
[root@NFS-server ~]# lsof -i :111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 2249 rpc 6u IPv4 14199 0t0 UDP *:sunrpc
rpcbind 2249 rpc 8u IPv4 14202 0t0 TCP *:sunrpc (LISTEN)
rpcbind 2249 rpc 9u IPv6 14204 0t0 UDP *:sunrpc
rpcbind 2249 rpc 11u IPv6 14207 0t0 TCP *:sunrpc (LISTEN)
[root@NFS-server ~]#
查看端口的其他命令!
[root@NFS-server ~]# netstat -utnpl |grep rpcbind
[root@NFS-server ~]# ss -lnp |grep :111
查看nfs状态
[root@NFS-server ~]# rpcinfo -p localhost
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
[root@NFS-server ~]#
2,启动nfs
[root@NFS-server ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@NFS-server ~]#
2049已经启动
[root@NFS-server ~]# ss -lnp |grep :2049
LISTEN 0 64 :::2049 :::*
LISTEN 0 64 *:2049 *:*
[root@NFS-server ~]#
当启动nfs后,其他端口也会随之启动
[root@NFS-server ~]# rpcinfo -p localhost
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 53312 mountd
100005 1 tcp 43596 mountd
100005 2 udp 56528 mountd
100005 2 tcp 43602 mountd
100005 3 udp 35406 mountd
100005 3 tcp 35567 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 34793 nlockmgr
100021 3 udp 34793 nlockmgr
100021 4 udp 34793 nlockmgr
100021 1 tcp 33076 nlockmgr
100021 3 tcp 33076 nlockmgr
100021 4 tcp 33076 nlockmgr
[root@NFS-server ~]#
当NFS启动是有启动顺序,在rpcbind和NFS的启动脚本中是有先后级别!在这里,使用rc.local
[root@NFS-server ~]# vim /etc/rc.local
/etc/init.d/rpcbind start
/etc/init.d/nfs start
nfs配置文件,默认为空
[root@NFS-server ~]# ls -l /etc/exports
-rw-r--r--. 1 root root 0 Jan 12 2010 /etc/exports
NFS配置文件常见写法NFS共享目录 NFS客户端地址(1,2,3)如下:
[root@NFS-server ~]# mkdir /data
[root@NFS-server ~]# cat /etc/exports
/data 10.0.0.0/24(rw,sync) ------------>10.0.0.*网段,读写,并且写入磁盘
[root@NFS-server ~]#
[root@NFS-server ~]# /etc/init.d/nfs reload
[root@NFS-server ~]# exportfs -rv
查看挂载
[root@NFS-server ~]# showmount -e 127.0.0.1
Export list for 127.0.0.1:
/data 10.0.0.0/24
3,NFS客户端写入权限现在的客户端是没有写权限。
[root@NFS-server ~]# cat /var/lib/nfs/etab
/data 10.0.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
[root@NFS-server ~]# cat /etc/exports
/data 10.0.0.0/24(rw,sync)
[root@NFS-server ~]#
要想有写入权限必须授权nfsnobody给data目录
[root@NFS-server ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@NFS-server ~]# chown -R nfsnobody /data/
[root@NFS-server ~]# ls -ld /data/
drwxr-xr-x 2 nfsnobody root 4096 Dec 21 07:49 /data/
[root@NFS-server ~]#
但是,在服务端创建文件,权限仍然是root,客户端仍然不可写入到创建的文件中
报错解决!1,如果服务端出现RPC:Program not registerred则是rpcbind启动顺序出错!先rpcbind,后nfs2,关闭防火墙3,授权服务端NFS文件夹nfsnobody4, /etc/exports是否读写5,The stale file handle errorstale NFS file handle服务器上的共享资源位置被移动,客户端重新挂载即可