美文网首页
2018-12-08 nfs

2018-12-08 nfs

作者: XZG_0be8 | 来源:发表于2018-12-08 11:22 被阅读0次

    第1章 NFS简介

    1.1 什么是NFS

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

    NFS网络文件系统很像Windows系统的网络共享、安全功能、网络驱动器映射,这也和linux的samba服务类似,只不过一般情况下,Windows网络共享服务或samba服务用户办公局域网共享,而互联网中小型网站集群架构后端常用NFS进行数据共享,若是大型网站,那么有可能还会用到更复杂的分布式文件系统Moosefs(mfs)、GlusterFS。

    1.2 NFS历史介绍

    第一个网络文件系统被称为File Access Listener,由DEC在1976年开发。

    NFS是第一个构建在IP协议之上的现代网络文件系统,在20世纪80年代,首先作为实验文件系统,由Sun Microsystems在内部开发完成,NFS协议归属与RFC标准,在随后演化为NFSv2,作为一个标准,由于NFS与其他客户端和服务器的互操作能力很好而发展迅速。

    1.3 NFS发展时间表

    1.4 NFS企业在企业中的应用场景

    在企业集群架构的工作场景中,NFS网络文件系统一般被用来存储共享视频、图片、附件等静态资源文件,通常网站用户上传的文件都会放到NFS共享中,例如BBS产品的图片、附件、头像(网站BBS的程序不要放在NFS共享中),然后前端所有节点在访问这些静态资源时都会读取NFS存储上的资源。

    NFS是当前互联网系统架构中最常用的数据存储服务之一,特别是中小型网站应用频率更高。

    1.5 NFS工作流程图

    1.6 NFS原理图

    注意:NFS的rpc服务,在Centos5系列下名称为portmap,在Centos6系列下名称为rpcbind

    第2章 NFS服务的搭建

    2.1 部署服务器前的准备

    操作系统服务器角色IP地址

    CentOS release 6.9 x86_64NFS服务端(nfs-server)内网:172.16.1.31/24 外网:10.0.0.31/24

    CentOS release 6.9 x86_64NFS客户端(nfs-client1)内网:172.16.1.41/24 外网:10.0.0.41/24

    CentOS release 6.9 x86_64NFS客户端(nfs-client2)内网:172.16.1.8/24 外网:10.0.0.8/24

    2.2 NFS服务端的配置

    2.2.1 检查操作系统的环境

    [root@nfs01 ~]# cat /etc/redhat-release 

    CentOS release 6.9 (Final)

    [root@nfs01 ~]# uname -r

    2.6.32-696.el6.x86_64

    [root@nfs01 ~]# uname -m 

    x86_64

    2.2.2 NFS服务端需要安装的软件包

    nfs-utils:nfs服务的主程序,包括rpc.nfsd、rpc.mountd两个daemons和相关的文档说明及执行命令文件等

    rpcbind:centos6下面的rpc主程序(centos5下的是portmap)

    2.2.3 安装相应的软件包及检查

    安装:

    [root@nfs01 ~]# yum install nfs-utils rpcbind -y

    检查:

    [root@nfs01 ~]# rpm -qa nfs-utils rpcbind

    rpcbind-0.2.0-13.el6_9.1.x86_64

    nfs-utils-1.2.3-75.el6_9.x86_64

    注意:在安装完该软件包后会自动创建nfsnobody用户

    [root@nfs01 ~]# id nfsnobody

    uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody)

    2.2.4 启动NFS相关的服务

    2.2.4.1 启动rpcbind服务并进行检查

    启动:

    [root@nfs01 ~]# /etc/init.d/rpcbind start

    Starting rpcbind: [ OK ]

    检查:

    [root@nfs01 ~]# /etc/init.d/rpcbind status 

    rpcbind (pid 2309) is running...

    查看rpc的端口:

    [root@nfs01 ~]# netstat -tnulp|grep rpc 端口为111

    tcp 0 0 0.0.0.0:111 0.0.0.0: LISTEN 2309/rpcbind 

    tcp 0 0 0.0.0.0:35957 0.0.0.0:

     LISTEN 1221/rpc.statd 

    tcp 0 0 :::14282 ::: LISTEN 1221/rpc.statd 

    tcp 0 0 :::111 :::

     LISTEN 2309/rpcbind 

    udp 0 0 0.0.0.0:49347 0.0.0.0: 1221/rpc.statd 

    udp 0 0 127.0.0.1:973 0.0.0.0:

     1221/rpc.statd 

    udp 0 0 0.0.0.0:111 0.0.0.0: 2309/rpcbind 

    udp 0 0 0.0.0.0:788 0.0.0.0:

     2309/rpcbind 

    udp 0 0 :::111 ::: 2309/rpcbind 

    udp 0 0 :::10354 :::

     1221/rpc.statd 

    udp 0 0 :::788 :::* 2309/rpcbind

    查看端口映射情况:

    [root@nfs01 ~]# 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

    注意:在未启动nfs服务时,不能看到nfs端口的映射情况

    2.2.4.2 启动nfs服务并进行检查

    启动:

    [root@nfs01 ~]# /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@nfs01 ~]# /etc/init.d/nfs status 

    rpc.svcgssd is stopped

    rpc.mountd (pid 2432) is running...

    nfsd (pid 2448 2447 2446 2445 2444 2443 2442 2441) is running...

    rpc.rquotad (pid 2427) is running...

    查看端口映射情况:

    [root@nfs01 ~]# 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 28839 mountd

    100005 1 tcp 34541 mountd

    100005 2 udp 12297 mountd

    100005 2 tcp 38042 mountd

    100005 3 udp 54557 mountd

    100005 3 tcp 11471 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 9683 nlockmgr

    100021 3 udp 9683 nlockmgr

    100021 4 udp 9683 nlockmgr

    100021 1 tcp 4166 nlockmgr

    100021 3 tcp 4166 nlockmgr

    100021 4 tcp 4166 nlockmgr

    注意:此时有了端口映射

     【特别注意】必须先启动rpcbind服务之后,才能启动nfs服务

    原因:nfs可以视为一个rpc程序,在启动任何一个rpc程序之前,需要做好端口和功能的映射工作,这个映射工作就是由rpcbind服务来完成的,因此在提供nfs服务之前,必须要先启动rpcbind服务

    2.2.4.3 检查nfs和rpc进程

    [root@nfs01 ~]# ps -ef |grep nfs 

    root 2900 2 0 19:05 ? 00:00:00 [nfsiod]

    root 3133 2 0 19:40 ? 00:00:00 [nfsd4]

    root 3134 2 0 19:40 ? 00:00:00 [nfsd4_callbacks]

    root 3135 2 0 19:40 ? 00:00:00 [nfsd]

    root 3136 2 0 19:40 ? 00:00:00 [nfsd]

    root 3137 2 0 19:40 ? 00:00:00 [nfsd]

    root 3138 2 0 19:40 ? 00:00:00 [nfsd]

    root 3139 2 0 19:40 ? 00:00:00 [nfsd]

    root 3140 2 0 19:40 ? 00:00:00 [nfsd]

    root 3141 2 0 19:40 ? 00:00:00 [nfsd]

    root 3142 2 0 19:40 ? 00:00:00 [nfsd]

    root 3221 2130 0 19:41 pts/0 00:00:00 grep nfs

    [root@nfs01 ~]# ps -ef |grep rpc 

    rpcuser 1221 1 0 10:37 ? 00:00:00 rpc.statd

    root 1270 2 0 10:37 ? 00:00:00 [rpciod/0]

    rpc 2309 1 0 14:27 ? 00:00:00 rpcbind

    root 3121 1 0 19:40 ? 00:00:00 rpc.rquotad

    root 3126 1 0 19:40 ? 00:00:00 rpc.mountd

    root 3173 1 0 19:40 ? 00:00:00 rpc.idmapd

    root 3223 2130 0 19:42 pts/0 00:00:00 grep rpc

    2.2.5 将相关的服务添加到开机自启动中

    【方法1】

    将nfs服务加入并检查:

    [root@nfs01 ~]# chkconfig nfs on 

    [root@nfs01 ~]# chkconfig --list nfs 

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

    将rpcbind服务加入并检查:

    [root@nfs01 ~]# chkconfig rpcbind on 

    [root@nfs01 ~]# chkconfig --list rpcbind 

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

    【方法2】

    加入:

    [root@nfs01 ~]# echo "/etc/init.d/rpcbind start" >>/etc/rc.local

    [root@nfs01 ~]# echo "/etc/init.d/nfs start" >>/etc/rc.local

    查看:

    [root@nfs01 ~]# tail -2 /etc/rc.local 

    /etc/init.d/rpcbind start

    /etc/init.d/nfs start

    【注意】

    在实际的生产环境中用方法2而不用方法1,因为可以方便运维人员的管理

    2.2.6 配置nfs服务的配置文件/etc/exports

    默认情况下该配置文件是空的:

    [root@nfs01 ~]# ll -h /etc/exports 

    -rw-r--r--. 1 root root 0 Jan 12 2010 /etc/exports

    编辑该配置文件:

    [root@nfs01 ~]# vim /etc/exports

    查看:

    [root@nfs01 ~]# cat /etc/exports 

    #share /data by oldboy for bingbing at 2018-3-12

    /data 172.16.1.0/24(rw,sync)

    【注意】

     该配置文件默认是存在,只不过是空文件而已,在172.16.1.0/24(rw,sync)中24和(之间不能有空格

     查看NFS服务器配置的参数(包含默认的参数)的文件/var/lib/nfs/etab

    2.2.6.1 nfs配置文件的格式

    NFS共享的目录 NFS客户端地址(参1,参2,……) NFS客户端地址2(参1,参2,……)或者

    NFS共享的目录 NFS客户端地址(参1,参2,……)

    上述各列参数的含义:

     NFS共享的目录:为NFS服务端要共享的实际目录,要用绝对路径如(/data)。注意共享目录的本地权限,如果需要读写共享,一定要让本地目录可以被NFS客户端的用户(nfsnobody)读写。/etc/exports配置文件格式书写详细如下表

     NFS 客户端地址:为NFS服务端授权的可访问共享目录的NFS客户端地址,可以为单独的IP地址或主机名、域名等,也可以为整个网段的地址,还可以用”*”来匹配所有的客户端服务器,这里所谓的客户端一般为前端的业务服务器,例如web服务。详细说明如下表

     NFS配置参数权限,具体如下表

    2.2.7 创建共享目录

    [root@nfs01 ~]# mkdir /data -p

    [root@nfs01 ~]# ll -d /data/

    drwxr-xr-x. 2 root root 4096 Nov 19 10:45 /data/

    2.2.8 更改共享目录的权限

    [root@nfs01 ~]# chown -R nfsnodoby.nfsnodoby /data

    [root@nfs01 ~]# ll -d /data

    drwxr-xr-x 2 nfsnobody nfsnobody 4096 Mar 12 19:27 /data

    2.2.9 重新加载NFS服务

    [root@nfs01 ~]# /etc/init.d/nfs reload

    【注意】

     /etc/init.d/nfs reload<==>fexportfs -rv

     修改完/etc/exports配置后,需要重新加载NFS服务

     用yum/rpm包安装的软件,用service和/etc/init.d/服务名启动是一样的

    2.2.10 检查有权限挂载的服务器是否能够挂载

    【方法1】利用showmount来进行检查

    [root@nfs01 ~]# showmount -e 172.16.1.31

    Export list for 172.16.1.31:

    /data 172.16.1.0/24

    或者

    [root@nfs01 ~]# showmount -e localhost 

    Export list for localhost:

    /data 172.16.1.0/24

    【注意】

     出现上面信息是,说明服务器可以挂载

     测试的IP地址为NFS服务器的IP地址

    【方法2】可以在把NFS服务器当做客户端来进行挂载测试

    [root@nfs01 ~]# mount -t nfs 172.16.1.31:/data /mnt 挂载

    [root@nfs01 ~]# df -h 查看

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 8.8G 1.5G 6.9G 18% /

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

    /dev/sda1 190M 35M 146M 19% /boot

    172.16.1.31:/data 8.8G 1.5G 6.9G 18% /mnt

    [root@nfs01 ~]# umount /mnt 测试完后取消挂载

    [root@nfs01 ~]# df -h 

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 8.8G 1.5G 6.9G 18% /

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

    /dev/sda1 190M 35M 146M 19% /boot

    2.3 NFS客户端的配置

    2.3.1 检查操作系统的环境

    [root@ client1 ~]# cat /etc/redhat-release 

    CentOS release 6.9 (Final)

    [root@ client1 ~]# uname -r

    2.6.32-696.el6.x86_64

    [root@ client1 ~]# uname -m 

    x86_64

    2.3.2 安装客户端软件rpcbind和nfs-utils

    安装:

    [root@client1 ~]# yum install nfs-utils rpcbind -y

    检查:

    [root@ client1 ~]# rpm -qa nfs-utils rpcbind

    rpcbind-0.2.0-13.el6_9.1.x86_64

    nfs-utils-1.2.3-75.el6_9.x86_64

    【注意】

     安装nfs-utils软件的目的是为了使用showmount等功能,所以客户端最好也装上,但是不启动NFS服务

    2.3.3 启动RPC服务并进行查看

    启动:

    [root@client1 ~]# /etc/init.d/rpcbind start 

    Starting rpcbind: [ OK ]

    检查:

    [root@ client1 ~]# /etc/init.d/rpcbind status 

    rpcbind (pid 2370) is running...

    2.3.4 检查能否访问服务端

    【方法1】

    [root@ client1 ~]# showmount -e 172.16.1.31 此ip地址为服务器端的ip地址

    Export list for 172.16.1.31:

    /data 172.16.1.0/24

    出现上面的情况说明可以访问服务端

    【方法2】

    [root@ client1 ~]# telnet 172.16.1.31 111 111为rpc服务的端口

    Trying 172.16.1.31...

    Connected to 172.16.1.31.

    Escape character is '^]'.

    出现上面的情况说明可以访问服务端

    2.3.5 挂载NFS共享目录

    挂载:

    [root@ client1 ~]# mount -t nfs 172.16.1.31:/data /mnt

    查看:

    [root@ client1 ~]# df -h 

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 8.8G 1.5G 6.9G 18% /

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

    /dev/sda1 190M 35M 146M 19% /boot

    172.16.1.31:/data 8.8G 1.5G 6.9G 18% /mnt

    查看:

    [root@ client1 ~]# 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)

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

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

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

    172.16.1.31:/data on /mnt type nfs (rw,vers=4,addr=172.16.1.31,clientaddr=172.16.1.8)

    2.3.6 测试读写数据

    2.3.6.1 在/mnt目录下创建测试文件

    [root@ client1 ~]# cd /mnt/

    [root@ client1 mnt]# touch test.txt

    [root@ client1 mnt]# ls

    test.txt

    2.3.6.2 在NFS服务端/data目录下进行查看

    [root@nfs01 ~]# cd /data

    [root@nfs01 data]# ls

    test.txt

    至此NFS客户端挂载成功

    2.3.7 将挂载命令加入开机自启动

    [root@client1 ~]# echo "mount -t nfs 172.16.1.31:/data /mnt" >>/etc/rc.local

    [root@client1 ~]# tail -1 /etc/rc.local

    mount -t nfs 172.16.1.31:/data /mnt

    第3章 NFS重点知识总结

    3.1 NFS常见进程详解

    3.1.1 查看NFS进程

    [root@nfs01 ~]# ps -ef|grep -E "rpc|nfs"

    rpcuser 1221 1 0 10:37 ? 00:00:00 rpc.statd 检查文件的一致性

    root 1270 2 0 10:37 ? 00:00:00 [rpciod/0]

    rpc 2309 1 0 14:27 ? 00:00:00 rpcbind

    root 2900 2 0 19:05 ? 00:00:00 [nfsiod]

    root 3121 1 0 19:40 ? 00:00:00 rpc.rquotad 磁盘配额进程

    root 3126 1 0 19:40 ? 00:00:00 rpc.mountd 权限管理验证

    root 3133 2 0 19:40 ? 00:00:00 [nfsd4]

    root 3134 2 0 19:40 ? 00:00:00 [nfsd4_callbacks]

    root 3135 2 0 19:40 ? 00:00:00 [nfsd] nfs主进程管理登入ID身份 认证等

    root 3136 2 0 19:40 ? 00:00:00 [nfsd]

    root 3137 2 0 19:40 ? 00:00:00 [nfsd]

    root 3138 2 0 19:40 ? 00:00:00 [nfsd]

    root 3139 2 0 19:40 ? 00:00:00 [nfsd]

    root 3140 2 0 19:40 ? 00:00:00 [nfsd]

    root 3141 2 0 19:40 ? 00:00:00 [nfsd]

    root 3142 2 0 19:40 ? 00:00:00 [nfsd]

    root 3173 1 0 19:40 ? 00:00:00 rpc.idmapd name mapping daemon

    root 3271 2130 0 20:15 pts/0 00:00:00 grep -E rpc|nfs

    3.1.2 NFS服务启动的进程说明


    3.4 多个NFS客户端访问服务器的读写文件时必须要有的权限

     NFS服务器/etc/exports设置需要开放可写入的权限,即服务端的共享权限

     NFS服务器实际要共享的NFS目录权限具有可写入w的权限,即服务端本地目录的安全权限

     每台服务器都对应存在和NFS默认配置UID的相同UID的账户nfsnodoby(确保所有所有客户端的访问权限统一,否则每台机器都需要同时建立相同UID用户,并覆盖NFS的默认用户配置)

    只有满足上述三个条件,多个NFS客户端才能具有查看、修改、删除其他任意NFS客户端上传文件的权限,这在大规模的集群环境中最为集群共享存储时尤为重要

    第4章 错误重现及客户端排错思路

    4.1 错误重现

    4.1.1 服务端的防火墙未关闭

     【错误实例】

    [root@web01 ~]# showmount -e 172.16.1.31

    clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

    并且再出现这种错误时,在客户端不能用df -h命令

     【解决方法】

    只需关掉NFS服务端的防火墙即可

    [root@nfs01 ~]# /etc/init.d/iptables stop

    iptables: Setting chains to policy ACCEPT: filter [ OK ]

    iptables: Flushing firewall rules: [ OK ]

    iptables: Unloading modules: [ OK ]

    [root@nfs01 ~]# /etc/init.d/iptables status 

    iptables: Firewall is not running.

     【测试】

    在NFS客户端在进行测试

    [root@client1 ~]# showmount -e 172.16.1.31

    Export list for 172.16.1.31:

    /data 172.16.1.0/24

    4.1.2 NFS服务端的共享目录权限不够

     【错误实例】

    在NFS客户端挂载目录下创建文件被拒绝出现下面的错误

    [root@client1 ~]# cd /mnt/

    [root@client1 mnt]# touch oldboy.txt

    touch: cannot touch `oldboy.txt': Permission denied

     【解决方法】

    在客户端修改共享目录的权限

    [root@nfs01 ~]# ll -d /data

    drwxr-xr-x 2 root root 4096 Mar 13 20:07 /data

    [root@nfs01 ~]# chown -R nfsnobody.nfsnobody /data

    [root@nfs01 ~]# ll -d /data

    drwxr-xr-x 2 nfsnobody nfsnobody 4096 Mar 13 20:07 /data

     【测试】

    在NFS客户端挂载目录下创建文件

    [root@client1 ~]# cd /mnt/

    [root@client1 mnt]# touch oldboy.txt

    在NFS服务端共享目录下查看

    [root@nfs01 ~]# cd /data

    [root@nfs01 data]# ls

    oldboy.txt test.txt

    4.1.3 NFS服务端启动顺序有问题

     【错误实例】

    [root@client1 ~]# showmount -e 172.16.1.31

    clnt_create: RPC: Program not registered

     【解决方法】

    在NFS端重新启动服务,先启动rpcbind服务,在启动nfs服务

    [root@nfs01 ~]# /etc/init.d/rpcbind start 

    Starting rpcbind: [ OK ]

    [root@nfs01 ~]# /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@client1 ~]# showmount -e 172.16.1.31

    Export list for 172.16.1.31:

    /data 172.16.1.0/24

    4.1.4 NFS服务端的nfs服务未开启

     【错误实例】

    [root@client1 ~]# showmount -e 172.16.1.31

    clnt_create: RPC: Program not registered

     【解决方法】

    在NFS服务端开启nfs服务器

    [root@nfs01 ~]# /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@client1 ~]# showmount -e 172.16.1.31

    Export list for 172.16.1.31:

    /data 172.16.1.0/24

    4.2 排错思路

    4.2.1 首先确认NFS服务器端的服务或配置是否OK

    [root@nfs01 ~]# showmount -e localhost 

    Export list for localhost:

    /data 172.16.1.0/24

    4.2.2 在NFS服务器端测试能否挂载

    [root@nfs01 ~]# mount -t nfs 172.16.1.31:/data /mnt 

    [root@nfs01 ~]# df -h 

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 8.8G 1.5G 6.9G 18% /

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

    /dev/sda1 190M 35M 146M 19% /boot

    172.16.1.31:/data 8.8G 1.5G 6.9G 18% /mnt

    4.2.3 从客户端pingNFS服务端的ip

    [root@client1 ~]# ping 172.16.1.31

    PING 172.16.1.31 (172.16.1.31) 56(84) bytes of data.

    64 bytes from 172.16.1.31: icmp_seq=1 ttl=64 time=2.39 ms

    64 bytes from 172.16.1.31: icmp_seq=2 ttl=64 time=0.528 ms

    这是通的情况

     执行这步的主要目的是看物理链路是否通

    4.2.4 从客户端telnet服务器端IP端口检查

    [root@client1 ~]# telnet 172.16.1.31 111

    Trying 172.16.1.31...

    Connected to 172.16.1.31.

    Escape character is '^]'

    这是通的情况

     执行这步的主要目的是用于测试NFS服务或RPC服务是否通

    第5章 生产环境高级案例配置实战

    5.1 NFS服务端的配置

    5.1.1 建立用户组zuma,并指定GID为888,所有的客户端也执行同样的操作

    [root@nfs01 ~]# groupadd zuma -g 888

    5.1.2 建立用户zuma,指定UID为888,并加入zuma组,所有的客户端也执行同样的操作

    [root@nfs01 ~]# useradd zuma -u zuma -g 888

    [root@nfs01 ~]# id zuma 查看建立的用户及用户组

    uid=888(zuma) gid=888(zuma) groups=888(zuma)

    5.1.3 配置/etc/exports配置文件并检查

    [root@nfs01 ~]# vim /etc/exports

    [root@nfs01 ~]# cat /etc/exports 

    #share /data by oldboy for bingbing at 2018-3-12

    /data 172.16.1.0/24(rw,sync)

    #####

    /data1 172.16.1.0/24(rw,sync,all_squash,anonuid=888,anongid=888)

    5.1.4 创建共享目录并检查

    [root@nfs01 ~]# mkdir -p /data1

    [root@nfs01 ~]# ll -d /data1

    drwxr-xr-x 2 root root 4096 Mar 12 20:00 /data1

    5.1.5 给共享目录服务权限并检查

    [root@nfs01 ~]# chown -R zuma.zuma /data1

    [root@nfs01 ~]# ll -d /data1

    drwxr-xr-x 2 zuma zuma 4096 Mar 12 20:00 /data1

    5.1.6 重新加载NFS服务器

    [root@nfs01 ~]# /etc/init.d/nfs reload

    5.1.7确认NFS服务端的服务或配置是否OK

    [root@nfs01 ~]# showmount -e localhost 

    Export list for localhost:

    /data1 172.16.1.0/24

    /data 172.16.1.0/24

    至此NFS服务端配置完成

    5.2 NFS客户端的配置

    5.2.1 建立用户组zuma,并指定GID为888,同服务端的操作步骤

    [root@client1 ~]# groupadd zuma -g 888

    5.2.2 建立用户zuma,指定UID为888,并加入zuma组,同服务端的操作步骤

    [root@client1 ~]# useradd zuma -u 888 -g zuma 

    [root@client1 ~]# id zuma 查看

    uid=888(zuma) gid=888(zuma) groups=888(zuma)

    5.2.3 创建挂载目录并检查

    [root@client1 ~]# mkdir /test

    [root@client1 ~]# ll -d /test 

    drwxr-xr-x 2 root root 4096 Mar 14 10:18 /test

    5.2.3 检查是否启动rpcbind服务

    [root@client1 ~]# /etc/init.d/rpcbind status 

    rpcbind (pid 1204) is running... 说明正在运行

    5.2.4 测试NFS服务端是否可以挂载

    [root@client1 ~]# showmount -e 172.16.1.31

    Export list for 172.16.1.31:

    /data1 172.16.1.0/24

    /data 172.16.1.0/24 说明可以挂载

    5.2.5 挂载并进行查看

    [root@client1 ~]# mount -t nfs 172.16.1.31:/data1 /test 挂载

    [root@client1 ~]# df -h 查看

    Filesystem Size Used Avail Use% Mounted on

    /dev/sda3 8.8G 1.5G 6.9G 18% /

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

    /dev/sda1 190M 35M 146M 19% /boot

    172.16.1.31:/data 8.8G 1.5G 6.9G 18% /mnt

    172.16.1.31:/data1 8.8G 1.5G 6.9G 18% /test

    5.2.6 在挂载目录下创建测试文件

    [root@client1 ~]# cd /test/

    [root@client1 test]# touch test.txt 

    [root@client1 test]# ls

    test.txt

    5.2.7 在服务端共享目录下进行查看

    [root@nfs01 ~]# cd /data1

    [root@nfs01 data1]# ls

    test.txt

    至此指定NFS共享用户zuma共享/data1目录的配置完成

    相关文章

      网友评论

          本文标题:2018-12-08 nfs

          本文链接:https://www.haomeiwen.com/subject/acxqhqtx.html