1.什么是NFS? NFS,全名叫Network File System,中文叫网络文件系统,是Linux、UNIX系统的分布式文件系统的一个组成部分,可实现在不同网络上共享远程文件系统。NFS由Sun公司开发,目前已经成为文件服务的一种标准之一。其最大的功能就是可以通过网络,让不同操作系统的计算机可以共享数据,所以可以把NFS看做是一个文件服务器。NFS缺点是其读写性能比本地硬盘要差一些。 2.使用yum安装nfs-utils、rpcbind 实验环境
centos 6.6
nfs-server 10.0.0.130 lamp-client 10.0.0.137 lnmp-client 10.0.0.138 3.nfs服务端软件安装 [iyunv@nfs-server ~]# yum -y install nfs-utils rpcbind
创建共享文件夹
[iyunv@nfs-server ~]# mkdir -p {/data/r_shared,/data/w_shared} 查看文件是否创建成功 [iyunv@nfs-server data]# ll
总用量 8
drwxr-xr-x 2 nfsnobody root 4096 4月 23 15:13 r_shared
drwxr-xr-x 2 nfsnobody root 4096 4月 23 15:24 w_shared
[iyunv@nfs-server data]#
给文件授权 [iyunv@nfs-server data]# chown -R nfsnobody r_shared w_shared [iyunv@nfs-server data]# ll
总用量 8
drwxr-xr-x 2 nfsnobody root 4096 4月 23 15:13 r_shared
drwxr-xr-x 2 nfsnobody root 4096 4月 23 15:24 w_shared
[iyunv@nfs-server data]# 4.启动rpcbind、nfs [iyunv@nfs-server ~]# /etc/init.d/rpcbind start
[iyunv@nfs-server ~]# /etc/init.d/nfs start
[iyunv@nfs-server ~]# /etc/init.d/nfs status
rpc.svcgssd 已停
rpc.mountd (pid 4759) 正在运行...
nfsd (pid 4775 4774 4773 4772 4771 4770 4769 4768) 正在运行...
rpc.rquotad (pid 4754) 正在运行...
[iyunv@nfs-server ~]# /etc/init.d/rpcbind status
rpcbind (pid 1656) 正在运行...
[iyunv@nfs-server ~]#
[iyunv@nfs ~]# lsof -i :111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 2664 rpc 6u IPv4 15806 0t0 UDP *:sunrpc
rpcbind 2664 rpc 8u IPv4 15809 0t0 TCP *:sunrpc (LISTEN)
rpcbind 2664 rpc 9u IPv6 15811 0t0 UDP *:sunrpc
rpcbind 2664 rpc 11u IPv6 15814 0t0 TCP *:sunrpc (LISTEN)
[iyunv@nfs ~]# netstat -tunpl|grep "111"
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2664/rpcbind
tcp 0 0 :::111 :::* LISTEN 2664/rpcbind
udp 0 0 0.0.0.0:111 0.0.0.0:* 2664/rpcbind
udp 0 0 :::111 :::* 2664/rpcbind
[iyunv@nfs ~]#
[iyunv@nfs ~]# chkconfig --list rpcbind 查看开机是否自启
rpcbind 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[iyunv@nfs ~]#
[iyunv@nfs ~]# /etc/init.d/nfs status
rpc.svcgssd 已停
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[iyunv@nfs ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
正在启动 RPC idmapd: [确定]
[iyunv@nfs ~]# netstat -tunpl |grep 2049
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 :::2049 :::* LISTEN -
udp 0 0 0.0.0.0:2049 0.0.0.0:* -
udp 0 0 :::2049 :::* -
[iyunv@nfs ~]# lsof -i:2049
[iyunv@nfs ~]# 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 48501 mountd
100005 1 tcp 36022 mountd
100005 2 udp 43391 mountd
100005 2 tcp 39405 mountd
100005 3 udp 49218 mountd
100005 3 tcp 41793 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 59606 nlockmgr
100021 3 udp 59606 nlockmgr
100021 4 udp 59606 nlockmgr
100021 1 tcp 56597 nlockmgr
100021 3 tcp 56597 nlockmgr
100021 4 tcp 56597 nlockmgr
[iyunv@nfs ~]#
5.修改nfs配置文件
[iyunv@nfs-server ~]# vi /etc/exports
/data/w_shared 10.0.0.0/24(rw,sync,all_squash)
/data/r_shared 10.0.0.0/24(ro) 注:下面介绍一些配置文件中常用的参数含义,以及客户端的IP地址的格式。
rw:可读写权限。
ro:只读权限。
no_root_squash:当登录NFS服务器主机使用共享目录的使用者是root时,其权限将被转换成为匿名使用者,通常它的UID与GID都会变成nobody身份。
root_squash;如果登录NFS主机使用共享目录的使用者是root,那么对于这个共享的目录来说,它具有root的权限,这样会涉及到安全性的问题。
all_squash:忽略登录NFS使用者的身份,其身份都会被转换为匿名使用者,通常即nobody。
anonuid:通常为nobody,也可以自行设定这个UID的值,UID必须存在于/etc/passwd中。
anongid:同anonuid,但是变为Group ID。
sync:同步写入资料到内存与硬盘中。
async:资料会先暂存于内存中,而非直接写入硬盘。 [iyunv@nfs-server ~]#exportfs -r 让其平滑生效
6.nfs客服端配置 [iyunv@lamp01 ~]# yum -y install nfs-utils rpcbind
创建挂载点目录
[iyunv@lamp01 ~]# mkdir -p {/data/b_r,/data/b_w} 查看文件是否创建成功 [iyunv@lamp01 ~]# ll /data
总用量 8
drwxr-xr-x 2 nfsnobody root 4096 4月 23 15:13 b_r
drwxr-xr-x 2 nfsnobody root 4096 4月 23 15:24 b_w 测试挂载 [iyunv@lamp01 ~]# showmount -e 10.0.0.130
Export list for 10.0.0.130:
/data/r_shared 10.0.0.0/24
/data/w_shared 10.0.0.0/24
[iyunv@lamp01 ~]# 挂载 [iyunv@lamp01 ~]#mount.nfs 10.0.0.130:/data/r_shared /data/b_r [iyunv@lamp01 ~]#mount -t nfs 10.0.0.130:/data/w_shared /data/b_w 查看是否挂载成功 [iyunv@lamp01 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 18244476 1582428 15728624 10% /
tmpfs 515244 0 515244 0% /dev/shm
/dev/sda1 194241 25657 158344 14% /boot
10.0.0.130:/data/r_shared
18244480 1582464 15728640 10% /data/b_r
10.0.0.130:/data/w_shared
18244480 1582464 15728640 10% /data/b_w
[iyunv@lamp01 ~]# 同理在另个客服端使用相同的方法进行挂载即可。 一、NFS服务常见故障排查: NFS服务出现了故障,主要从以下几个方面检查原因: (1)检查NFS客户机和服务器的负荷是否太高,Server和Client之间的网络是否正常; (2)检查/etc/exports文件的正确性; (3)必要时重启NFS和portmap服务; (4)运行下列命令重新启动portmap和NFS:
# /etc/init.d/portmap restart (先启动portmap或rpcbind)
# /etc/init.d/nfs restart
# /etc/init.d/rpcbind restart (在RHEL/CentOS 6.x里面)
# chkconfig portmap on
# chkconfig nfs on
# chkconfig rpcbind on (在RHEL/CentOS 6.x里面) 二、NFS常见故障解决方法: 1、The rpcbind failure error
故障现象:
nfs mount: server1:: RPC: Rpcbind failure
RPC: Timed Out
nfs mount: retrying: /mntpoint
原因:
第一,可能因为客户机的hosts文件中存在错误的ip地址、主机名或节点名组合;
第二,服务器因为过载而暂时停止服务。 2、The server not responding error
现象:
NFS server server2 not responding, still trying
原因:
第一,网络不通,用ping命令检测一下。
第二,服务器关机。 3、The NFS client fails a reboot error
现象:
启动客户机后停住了,不断显示如下提示信息:
Setting default interface for multicast: add net 224.0.0.0: gateway:
client_node_name.
原因:
在etc/vfstab的mount选项中使用了fg而又无法成功mount服务器上的资源,改成bg或将该行注释掉,直到服务器可用为止。 4、The service not responding error
现象:
nfs mount: dbserver: NFS: Service not responding
nfs mount: retrying: /mntpoint
原因:
第一,当前级别不是级别3,用who -r查看,用init 3切换。
第二,NFS Server守护进程不存在,用ps -ef | grep nfs检查,用/etc/init.d/nfs start启动。 5、The program not registered error
现象:
nfs mount: dbserver: RPC: Program not registered
nfs mount: retrying: /mntpoint
原因:
第一,当前级别不是级别3。
第二,mountd守护进程没有启动,用/etc/init.d/nfs脚本启动NFS守护进程。
第三,看/etc/dfs/dfstab中的条目是否正常。 6、The stale file handle error
现象:
stale NFS file handle
原因:
服务器上的共享资源移动位置了,在客户端使用umount和mount重新挂接就可以了。 7、The unknown host error
现象:
nfs mount: sserver1:: RPC: Unknown host
原因:
hosts文件中的内容不正确。 8、The mount point error
现象:
mount: mount-point /DS9 does not exist.
原因:
该挂接点在客户机上不存在,注意检查命令行或/etc/vfstab文件中相关条目的拼写。 9、The no such file error
现象:
No such file or directory.
原因:
该挂接点在服务器上不存在,注意检查命令行或/etc/vfstab文件中相关条目的拼写。 10、No route to host
错误现象:
# mount 10.10.11.211:/opt/data/xmldb /c2c-web1/data/xmldb -t nfs -o rw
mount: mount to NFS server ’10.10.11.211′ failed: System Error: No route to host. 原因:
防火墙被打开,关闭防火墙。
这个原因很多人都忽视了,如果开启了防火墙(包括iptables和硬件防火墙),NFS默认使用111端口,我们先要检测是否打开了这个端口,还要检查TCP_Wrappers的设定。 11、Not owner
现象:
# mount -F nfs -o rw 10.10.2.3:/mnt/c2c/data/resinfo2 /data/data/resinfo2
nfs mount: mount: /data/data/resinfo2: Not owner 原因:
这是Solaris 10版本挂载较低版本nfs时报的错误。 解决:
需要用-o vers=3参数 示例:
# mount -F nfs -o vers=3 10.10.2.3:/mnt/c2c/data/resinfo2 /data/data/resinfo2 12、RPC: Program not registered & retrying
现象:
nfs mount: 10.10.2.3: : RPC: Program not registered
nfs mount: retrying: /data/data/resinfo2 原因:
没有启动NFS共享端服务。 解决:需要重新启动share端的NFS服务,
Linux:
mount: RPC: Program not registered
# /etc/init.d/nfs restart Solaris:
mount: RPC: Program not registered
# /etc/rc.d/init.d/nfs restart 13、can’t contact portmapper: RPC: Remote system error – Connection refused
现象:
# exportfs -a
can’t contact portmapper: RPC: Remote system error – Connection refused 原因:
出现这个错误信息是由于server端的portmap没有启动。 解决:
# /etc/init.d/portmap start
|