NFS网络文件共享服务的配置和排错总结

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服务端软件安装

[[email protected] ~]# yum -y install nfs-utils rpcbind  
创建共享文件夹
[[email protected] ~]# mkdir -p {/data/r_shared,/data/w_shared}

查看文件是否创建成功

[[email protected] 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
[[email protected] data]#
给文件授权

[[email protected] data]# chown -R nfsnobody  r_shared w_shared

[[email protected] 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
[[email protected] data]#

4.启动rpcbind、nfs

[[email protected] ~]# /etc/init.d/rpcbind start
[[email protected] ~]# /etc/init.d/nfs start        
[[email protected] ~]# /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) 正在运行...
[[email protected] ~]# /etc/init.d/rpcbind status
rpcbind (pid  1656) 正在运行...
[[email protected] ~]#

[[email protected] ~]# 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)
[[email protected] ~]# 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        
[[email protected] ~]#
[[email protected] ~]#  chkconfig --list rpcbind  查看开机是否自启
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[[email protected] ~]#
[[email protected] ~]# /etc/init.d/nfs status
rpc.svcgssd 已停
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[[email protected] ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
正在启动 RPC idmapd:                                      [确定]
[[email protected] ~]# 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                     :::*                                    -                   
[[email protected] ~]# lsof -i:2049
[[email protected] ~]# 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
[[email protected] ~]#

5.修改nfs配置文件
[[email protected] ~]# 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:资料会先暂存于内存中,而非直接写入硬盘。

[[email protected] ~]#exportfs -r   让其平滑生效

6.nfs客服端配置

[[email protected] ~]# yum -y install nfs-utils rpcbind  
创建挂载点目录
[[email protected] ~]# mkdir -p {/data/b_r,/data/b_w}

查看文件是否创建成功

[[email protected] ~]# 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

测试挂载

[[email protected] ~]# 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
[[email protected] ~]#

挂载

[[email protected] ~]#mount.nfs 10.0.0.130:/data/r_shared  /data/b_r

[[email protected] ~]#mount -t nfs 10.0.0.130:/data/w_shared /data/b_w

查看是否挂载成功

[[email protected] ~]# 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
[[email protected] ~]#

同理在另个客服端使用相同的方法进行挂载即可。

一、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

时间: 2024-08-07 21:18:08

NFS网络文件共享服务的配置和排错总结的相关文章

企业级NFS网络文件共享服务

虚拟实验: 操作系统:CentOS release 6.8 (Final) 虚拟机:VMware 任务:NFS网络文件共享服务 默认是没有安装NFS软件包,NFS主要功能是通过网络让不同的主机系统之间可以共享文件或目录.NFS网络文件系统很像Windows系统的网络共享.安全功能.网络驱动映射,而互联网中小型网站集群架构后端常用NFS进行数据共享. NFS服务器IP: 192.168.222.130 NFS客户端IP1: 192.168.222.138 NFS客户端IP2:192.168.222

NFS网络文件共享服务介绍及案例

1.NFS介绍 1.1.NFS概念描述 什么是NFS?NFS是Network File System的缩写,它的主要功能是通过网络让不同的主机系统之间可以彼此共享文件或者目.NFS客户端(一般为应用服务器,如Web)可以通过挂载(mount)的方式将NFS服务器端共享的数据文件目录挂载到NFS客户端本地系统中(就是某一个挂载点下).从NFS客户端的机器本地上看,NFS服务器端共享的目录就好像是客户端自己的磁盘分区或者目录一样,而实际上确是远端的服务器目录. 1.2.NFS历史 第一个网络文件系统

NFS网络文件共享服务

NFS-网络文件系统,它的主要功能是通过网络让不同的主机系统之间可以彼此共享文件或目录. NFS在企业中得应用场景 在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频.图片.附件等静态资源文件(一般把网站用户上传的文件都放到NFS共享里,例如:BBS产品的图片.附件.头像,注意网站BBS程序不要放NFS共享里),NFS是当前互联网系统架构中最常用的数据存储服务之一,特别是中小型网站公司应用频率很高.大公司或门户除了使用NFS外,还可能会使用MFS.GFS.FASTFS,TFS等

搭建NFS网络文件共享服务(干货)

先上干货: 以下是配置全过程(客户端和服务端对比)查看NFS软件包[[email protected] ~]# rpm -aq nfs-utils portmap rpcbind#这个命令比(yum grouplist)的更有效率 安装法一:[[email protected] ~]#yum groupinstall "NFS file server"也可以使用法二:[[email protected] ~]# yum install nfs-utils rpcbind -y来安装 客

【集群实战】NFS网络文件共享服务

1. NFS介绍 1.1 什么是NFS? NFS是Network File System的缩写,中文意思是网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端(一般为应用服务器,例如web)可以通过挂载(mount)的方式将NFS服务器端共享的数据目录挂载到NFS客户端本地系统中(就是某一个挂载点下).从客户端本地看,NFS服务器端共享的目录就好像是客户端自己的磁盘分区或者目录一样,而实际上却是远端的NFS服务器的目录. NFS网络文件系统很像

NFS网络文件共享存储服务器

NFS网络文件共享存储服务器 什么是NFS NFS(Network File System)即网络文件系统,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样. 在企业集群架构的工作场景中,NFS网络文件系统一般被用来共享存储视频.图片.附件等静态资源文件,通常网站用户上的文件都会存放到NFS共享里.例如bbs产品的图片.附件头像等.然后前段所有的节点访问这些静态资源时都会读取NFS存储上

Samba网络文件共享服务介绍

Samba网络文件共享服务 一.samba简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Message Block的缩写,即为服务器消息块,SMB主要是作为Microsoft的网络通讯协议,后来Samba将SMB通信协议应用到了Linux系统上,就形成了现在的Samba软件.后来微软又把 SMB 改名为 CIFS(Common Internet File System),即公共 Internet 文件系统,并且加入了许多新的功能,这样一

第十章 网络文件共享服务之ftp

10.1 ftp介绍 网络文件共享服务主流的主要有三种,分别是ftp.nfs.samba.在上一章中我们已经了解了nfs,本章我们将来说说ftp. FTP是File Transfer Protocol(文件传输协议)的简称,用于internet上的控制文件的双向传输. FTP也是一个应用程序,基于不同的操作系统有不同的FTP应用程序,而所有这些应用程序都遵守同一种协议以传输文件. 在FTP的使用当中,用户经常遇到两种概念:下载和上传 下载(Download)文件就是从远程主机拷贝文件至自己的计算

2-7.访问网络文件共享服务

##访问网络文件共享服务## ##学习目标 挂载网络共享 自动挂载网络共享 1.1##挂载网络文件系统 网络文件系统是由网络附加存储服务器通过网络向多个主机提供的一种文件系统,而不是由块设备(例如硬盘驱动器)提供的.客户端通过特殊的文件系统协议和格式访问远程存储 Linux 中有两种主要协议可用访问网络文件系统 : NFS 和CIFS . NFS ( Network File System ) 可看作是 Linux .UNIX 及其它类似操作系统的标准文件系统. CIFS( Comon Inte