Centos6.7下NFS的配置安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos6.7下NFS的配置安装相关的知识,希望对你有一定的参考价值。

NFS集群环境搭建准备

1.1        准备好NFS服务器

技术分享

开始安装NFS

2.1 环境信息确认

[[email protected] ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[[email protected] ~]# uname -r

2.6.32-573.el6.x86_64

[[email protected] ~]# uname -m

x86_64

2.2 NFS软件列表

技术分享

查看系统是否安装:

[[email protected] ~]# rpm -qa nfs-utils rpcbind

2.3 yum安装软件包

安装epel yum源:

rpm -Uvhhttp://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

安装nfs-utilsrpcbind

[[email protected] ~]# yum install nfs-utilsrpcbind

安装完毕后检查安装结果:

[[email protected] ~]# rpm -qa nfs-utils rpcbind

nfs-utils-1.2.3-64.el6.x86_64

rpcbind-0.2.0-11.el6_7.x86_64

TIPs:为什么所有客户端都安装nfs?因为客户端showmount命令在nfs里面,如果不安装找不到这条命令

启动NFS及相关知识讲解

3.1 服务的启动顺序

先把Rpcbind启用:

[[email protected] ~]# /etc/init.d/rpcbindstatus

rpcbind is stopped

[[email protected] ~]# /etc/init.d/rpcbindstart

Starting rpcbind:                                         [  OK  ]

[[email protected] ~]# lsof -i :111

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

rpcbind 25222  rpc   6u  IPv4  34655     0t0  UDP *:sunrpc

rpcbind 25222  rpc   8u  IPv4  34658     0t0  TCP *:sunrpc (LISTEN)

rpcbind 25222  rpc   9u  IPv6  34660     0t0  UDP *:sunrpc

rpcbind 25222  rpc  11u  IPv6  34663     0t0  TCP *:sunrpc (LISTEN)

[[email protected] ~]# netstat -lntup|greprpcbind|grep -v grep

tcp        0     0 0.0.0.0:111                0.0.0.0:*                   LISTEN      25222/rpcbind      

tcp        0     0 :::111                      :::*                        LISTEN      25222/rpcbind      

udp        0     0 0.0.0.0:805                0.0.0.0:*                              25222/rpcbind      

udp        0     0 0.0.0.0:111                0.0.0.0:*                               25222/rpcbind      

udp        0     0 :::805                     :::*                                   25222/rpcbind      

udp        0     0 :::111                     :::*                                   25222/rpcbind  

[[email protected] ~]# netstat -lntup|grep111

tcp        0     0 0.0.0.0:111                0.0.0.0:*                   LISTEN      25222/rpcbind      

tcp        0     0 :::111                     :::*                        LISTEN      25222/rpcbind      

udp        0     0 0.0.0.0:111                0.0.0.0:*                              25222/rpcbind      

udp        0     0 :::111                     :::*                                   25222/rpcbind      

[[email protected] ~]# chkconfig --list |greprpcbind

rpcbind         0:off  1:off   2:on    3:on   4:on    5:on    6:off

再次启用NFS服务

[[email protected] ~]# netstat -lntup|grep2049

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                    :::*                                    -  

3.2 rpcbind 查看NFS共享的信息

[[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 45070  mountd

   100005    1   tcp 51837  mountd

   100005    2   udp 37124  mountd

   100005    2   tcp 49654  mountd

   100005    3   udp 59899  mountd

   100005    3   tcp 59234  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 42632  nlockmgr

   100021    3   udp 42632  nlockmgr

   100021    4   udp 42632  nlockmgr

   100021    1   tcp 59242  nlockmgr

   100021    3   tcp 59242  nlockmgr

100021    4  tcp  59242  nlockmgr

[[email protected]-SER ~]# chkconfig --list nfs

nfs             0:off   1:off  2:off   3:off   4:off  5:off   6:off

[[email protected] ~]# chkconfig nfs on

从这里看出,NFS开启了很多的服务。

3.3 开机自启动顺序情况

Less /etc/init.d/rpcbind

技术分享

Less /etc/init.d/nfs

技术分享

3.4 配置开机自启动

技术分享

NFS服务常见进程详解说明

[[email protected] ~]# ps -ef |egrep"rpc|nfs"

rpc      25222      1  0 03:33 ?        00:00:00 rpcbind

root     25310      2  0 03:39 ?        00:00:00 [rpciod/0]

root      25319     1 0 03:39 ?        00:00:00rpc.rquotad        磁盘配额进程

root      25324     1  0 03:39 ?        00:00:00 rpc.mountd        权限管理验证等

root     25331      2  0 03:39 ?        00:00:00 [nfsd4]

root     25332      2  0 03:39 ?        00:00:00 [nfsd4_callbacks]

root      25333     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25334     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25335     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25336     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25337     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25338     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25339     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25340     2  0 03:39 ?        00:00:00 [nfsd]                  nfs主进程

root      25371     1  0 03:39 ?        00:00:00 rpc.idmapd          name maping daem

root     25403   2295  0 03:56 pts/0    00:00:00 grep -E rpc|nfs

NFS实战配置服务端

5.1 默认配置文件介绍

NFS默认配置文件/etc/exports是存在的,但是默认是没有内容的,需要配置。有些Linux版本不提供这个配置文件,需要手动创建。

Man exports 我们可以看到exports的书写格式

技术分享

5.2配置exports文件

vim /etc/exports

技术分享

[[email protected] ~]# /etc/init.d/nfs reload

exportfs: Failed to stat /nfs_data: Nosuch file or directory

 

[[email protected] ~]# mkdir /nfs_data

[[email protected] ~]# /etc/init.d/nfs reload

[[email protected] ~]# exportfs -rv

exporting 10.0.0.*:/nfs_data

[[email protected]~]# grep -A 1 "reload" /etc/init.d/nfs          exports –r 为什么等于reload

 reload | force-reload)

       /usr/sbin/exportfs -r

--

         echo $"reload"; exit 0

       fi

--

       echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"

       RETVAL=2

[[email protected] ~]#

5.3 NFS测试

[[email protected] ~]# showmount -e 127.0.0.1

Export list for 127.0.0.1:

/nfs_data 10.0.0.*

[[email protected] ~]#

[[email protected] ~]# mount -t nfs 10.0.0.100:/nfs_data/mnt

[[email protected] ~]# mount

/dev/sda3 on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts(rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs(rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs typerpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw)

10.0.0.100:/nfs_data on /mnt type nfs(rw,vers=4,addr=10.0.0.100,clientaddr=10.0.0.100)

[[email protected] ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             7.1G  1.5G 5.3G  21% /

tmpfs                 491M     0 491M   0% /dev/shm

/dev/sda1             190M   36M 145M  20% /boot

10.0.0.100:/nfs_data  7.1G 1.5G  5.3G  21% /mnt

客户端配置

#/etc/init.d/rpcbind start

#chkconfig rpcbind on

#vim /etc/rc.local

#setenforce 0

#getenforce

#etc/init.d/iptables status

#chkconfig --list|grep iptables

#etc/init.d/iptables stop

#chkconfig iptables off

[[email protected]~]# showmount -e 10.0.0.100                   这里可以看到NFS-SER端共享的目录

Export list for 10.0.0.100:

/nfs_data 10.0.0.*

[[email protected]~]# mount -t nfs 10.0.0.100:/nfs_data /mnt                       挂载到本地/mnt

[[email protected] ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             7.1G  1.5G 5.3G  21% /

tmpfs                 491M     0 491M   0% /dev/shm

/dev/sda1             190M   36M 145M  20% /boot

10.0.0.100:/nfs_data  7.1G 1.5G  5.3G  21% /mnt

[[email protected]]# ls                 这里可以看到服务端创建的文件

t1.txt

这个时候在客户端是不能给这个共享目录创建文件,没有写到权限,这个是nfs默认配置的:

[[email protected] ~]# cat /var/lib/nfs/etab

技术分享/nfs_data      10.0.0.*(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)

这里我们看到,默认是65534这个uidgid用户和组,所有我们要给nfs共享的这个目录修改权限:

[[email protected]~]# ll /nfs_data/    查看nfs_data目录权限

total 0

-rw-r--r--. 1 root root 0 Mar  1 04:22 t1.txt

[[email protected]~]# cat /var/lib/nfs/etab         nfs默认参数配置信息

/nfs_data      10.0.0.*(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)

[[email protected]~]# grep 65534 /etc/passwd            查看65534属于哪个用户

nfsnobody:x:65534:65534:Anonymous NFSUser:/var/lib/nfs:/sbin/nologin

[[email protected]~]# chown -R 65534 /nfs_data                修改nfs_data共享目录的权限

[[email protected] ~]# ll /nfs_data/

total 0

-rw-r--r--. 1 nfsnobody root 0 Mar  1 04:22 t1.txt

[[email protected] ~]#

[[email protected]]# touch Lamp.txt       测试客户端是可以写了

[[email protected] mnt]# ls

Lamp.txt t1.txt

[[email protected] mnt]#

最后,在客户端我们要把挂载命令写入到rc.loal配置文件里面。技术分享

NFS常见故障排查及解决方案

附加:NFS常见故障排除 
-------------------
1
Therpcbind failure error 
故障现象: 
nfs mount: server1:: RPC: Rpcbind failure 
RPC: Timed Out 
nfs mount: retrying: /mntpoint 
原因: 
第一,可能因为客户机的hosts文件中存在错误的ip地址、主机名或节点名组合; 
第二,服务器因为过载而暂时停止服务。

2Theserver not responding error 
现象: 
NFS server server2 not responding, still trying 
原因: 
第一,网络不通,用ping命令检测一下。 
第二,服务器关机。

3The NFSclient fails a reboot error 
现象: 
启动客户机后停住了,不断显示如下提示信息: 
Setting default interface for multicast: add net 224.0.0.0: gateway: 
client_node_name. 
原因: 
etc/vfstabmount选项中使用了fg而又无法成功mount服务器上的资源,改成bg或将该行注释掉,直到服务器可用为止。

4Theservice not responding error 
现象: 
nfs mount: dbserver: NFS: Service not responding 
nfs mount: retrying: /mntpoint 
原因: 
第一,当前级别不是级别3,用who –r查看,用init切换。 
第二,NFSServer守护进程不存在,用ps–ef | grep nfs检查,用/etc/init.d/nfs.serverstart启动。

5Theprogram not registered error 
现象: 
nfs mount: dbserver: RPC: Program not registered 
nfs mount: retrying: /mntpoint 
原因: 
第一,当前级别不是级别3 
第二,mountd守护进程没有启动,用/etc/init.d/nfs.server脚本启动NFS守护进程。 
第三,看/etc/dfs/dfstab中的条目是否正常。

6Thestale file handle error 
现象: 
stale NFS file handle 
原因: 
服务器上的共享资源移动位置了,在客户端使用umountmount重新挂接就可以了。

7The unknownhost error 
现象: 
nfs mount: sserver1:: RPC: Unknown host 
原因: 
hosts
文件中的内容不正确。

8Themount point error 
现象: 
mount: mount-point /DS9 does not exist. 
原因: 
该挂接点在客户机上不存在,注意检查命令行或/etc/vfstab文件中相关条目的拼写。

9The nosuch file error 
现象: 
No such file or directory. 
原因: 
该挂接点在服务器上不存在,注意检查命令行或/etc/vfstab文件中相关条目的拼写。

10Noroute to host 
错误现象:
[[email protected] sysconfig]# mount 10.10.11.211:/opt/b2b-data/xmldb /b2b-web1/b2b-data/xmldb  -t nfs  -o rw
mount: mount to NFS server ‘10.10.11.211‘ failed: System Error: No route tohost.

原因:
防火墙被打开,关闭防火墙。

11Notowner
现象:
[[email protected]:/founder/shell]# mount -F nfs -o rw10.10.2.3:/mnt/b2b/b2b-data/resinfo2 /data/b2b-data/resinfo2
nfs mount: mount: /data/b2b-data/resinfo2: Not owner

原因:
这是Solaris10版本挂载较低版本nfs时报的错误。

解决:
需要用-overs=3参数

示例:
[[email protected]:/founder/shell]# mount -F nfs -o vers=3 10.10.2.3:/mnt/b2b/b2b-data/resinfo2 /data/b2b-data/resinfo2

12RPC:Program not registered & retrying
现象:
nfs mount: 10.10.2.3: : RPC: Program not registered
nfs mount: retrying: /data/b2b-data/resinfo2

原因:
没有启动NFS共享端服务。

解决:需要重新启动share端的NFS服务,
Linux:
mount: RPC: Program not registered
#service nfs restart

Solaris:
mount: RPC: Program not registered
#/etc/rc.d/init.d/nfs restart

13can‘tcontact portmapper: RPC: Remote system error - Connection refused
现象:
#exportfs -a
can‘t contact portmapper: RPC: Remote system error - Connection refused

原因:
出现这个错误信息是由于SEVER端的PORTMAP没有启动。

解决:
#service portmap start
#service pcmcia start

NFS服务端的权限参数详解

Async 异步写入数据,先写入内存当中,缺点是延迟,丢数据

Sync  同步数据写入到硬盘中,数据安全,但是性能比不加这个参数差

no_root_squash,如果客户端是root权限,那么访问这个目录后也有root权限,用于无盘工作站

root_squash 把普通用户映射成root用户

all_squash 把所有客户端都压缩成指定的匿名用户。这个匿名用户就是/var/lib/nfs/etab 下默认的用户。工作中默认最好是加上。

NFS重点知识梳理

技术分享

     NFS 客户端mount 挂载深入

技术分享技术分享技术分享

十一 客户端优化

11.1 安全的挂载

技术分享

11.2 挂载性能优化

技术分享

11.3 挂载内核优化

技术分享

11.4 生产场景NFS共享优化[K1] 

技术分享

12 NFS效率不高如何解决:

优点:

简单:容易上手,容易掌握

NFS 文件系统内数据是在文件系统之上,是可以看见的

方便:部署快速,维护简单,可控且满足需求是最好的

稳定:  非常稳定

可靠:从软件层面上看,数据可靠性高经久耐用。

局限:

1.     存在单点故障,如果NFS-SERVER宕机,所有客户端都无法访问。

2.     大数据高并发的场合NFS 几千万的pv

3.     客户端认识时候基于IP和主机名,安全性一般。没有密码

4.     多台客户端挂一个服务端,维护麻烦。

Autofs 介绍

作用就是:客户端需要时候,我给你挂载。没有请求时候我就卸载掉。


 [K1]多块网卡BOND 如何操作??


本文出自 “krik2015” 博客,请务必保留此出处http://krik2015.blog.51cto.com/10524959/1747285

以上是关于Centos6.7下NFS的配置安装的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6.7系统下安装配置Oracle11G R2

centos6.7下安装pycharm及配置jdk环境

Centos6.7_KVM安装配置使用

虚拟机下linux(CentOS6.7)网络配置

CentOS 7 下 yum 安装和配置 NFS

SuSE 11 sp3 下安装配置nfs共享挂载