码迷,mamicode.com
首页 > 其他好文 > 详细

NFS网络文件共享服务

时间:2015-07-19 06:45:12      阅读:469      评论:0      收藏:0      [点我收藏+]

标签:nfs网络文件共享服务

NFS-网络文件系统,它的主要功能是通过网络让不同的主机系统之间可以彼此共享文件或目录。


NFS在企业中得应用场景

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


[root@LAMP ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             7.6G  2.0G  5.2G  28% /

tmpfs                 495M     0  495M   0% /dev/shm

/dev/sda1             190M   27M  153M  15% /boot

192.168.0.113:/data/cms

                      7.6G  4.2G  3.1G  59% /data/cms/uploads/allimg

192.168.0.113:/data/blog

                      7.6G  4.2G  3.1G  59% /data/blog/wp-content/uploads

192.168.0.113:/data/bbs

                      7.6G  4.2G  3.1G  59% /data/bbs/data/attachment/forum

提示:mount 源 目标

      mount 192.168.0.113:/data/bbs(远端NFS server IP地址及共享目录) /data/bbs/data/attachment/forum(本地目录)


Centos5.X随机端口为小于1024的,而Centos6.X随机端口都是较大的.

    RPC-远程过程调用服务,最主要的功能就是记录每个NFS功能所对应的端口号,并且在NFS客户端请求时将该端口和功能对应的信息传递给请求数据的NFS客户端,从而可以确保客户端可以连接到正确的NFS端口上去,达到实现数据传输交互数据的目的.


一、NFS工作原理


1.先开启RPC服务(C5:portmap,C6:rpcbind)

2.向RPC服务注册启动的端口

3.客户端请求NFS服务

4.返回端口给客户端

5.拿着地址端口请求传输数据


二、NFS实战

NFS服务端:

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

CentOS release 6.6 (Final)

[root@backup ~]# uname -r Centos当前系统内核版本号

2.6.32-504.el6.x86_64

[root@backup ~]# uname -m

x86_64

[root@backup ~]# uname -n 机器名

backup

[root@backup ~]# rpm -qa "nfs-utils|rpcbind|portmap"

[root@backup ~]# yum grouplist

Loaded plugins: fastestmirror, security

Setting up Group Process

Determining fastest mirrors

 * base: mirrors.sina.cn

 * extras: mirrors.sina.cn

 * updates: mirrors.sina.cn

base                        | 3.7 kB     00:00     

extras                      | 3.4 kB     00:00     

extras/primary_db           |  31 kB     00:00     

updates                     | 3.4 kB     00:00     

updates/primary_db          | 3.9 MB     00:11     

base/group_gz               | 216 kB     00:00     

Installed Groups:

   Base

   Compatibility libraries

   Development tools

   E-mail server

   Graphical Administration Tools

   Hardware monitoring utilities

   Legacy UNIX compatibility

   Networking Tools

   Performance Tools

   Perl Support

   Scientific support

   Security Tools

   System administration tools

Available Groups:

   Additional Development

   Backup Client

   Backup Server

   CIFS file server

   Client management tools

   Console internet tools

   Debugging Tools

   Desktop

   Desktop Debugging and Performance Tools

   Desktop Platform

   Desktop Platform Development

   Dial-up Networking Support

   Directory Client

   Directory Server

   Eclipse

   Emacs

   FCoE Storage Client

   FTP server

   Fonts

   General Purpose Desktop

   Graphics Creation Tools

   Guest Agents

   High Availability

   High Availability Management

   Identity Management Server

   Infiniband Support

   Input Methods

   Internet Applications

   Internet Browser

   Java Platform

   KDE Desktop

   Large Systems Performance

   Legacy X Window System compatibility

   Load Balancer

   Mainframe Access

   Messaging Client Support

   MySQL Database client

   MySQL Database server

   NFS file server

   Network Infrastructure Server

   Network Storage Server

   Network file system client

   Office Suite and Productivity

   PHP Support

   PostgreSQL Database client

   PostgreSQL Database server

   Print Server

   Printing client

   Remote Desktop Clients

   Resilient Storage

   Ruby Support

   SNMP Support

   Scalable Filesystems

   Server Platform

   Server Platform Development

   Smart card support

   Storage Availability Tools

   System Management

   TeX support

   Technical Writing

   TurboGears application framework

   Virtualization

   Virtualization Client

   Virtualization Platform

   Virtualization Tools

   Web Server

   Web Servlet Engine

   Web-Based Enterprise Management

   X Window System

   iSCSI Storage Client

Available Language Groups:

   Afrikaans Support [af]

   Albanian Support [sq]

   Amazigh Support [ber]

   Arabic Support [ar]

   Armenian Support [hy]

   Assamese Support [as]

   Azerbaijani Support [az]

   Basque Support [eu]

   Belarusian Support [be]

   Bengali Support [bn]

   Bhutanese Support [dz]

   Brazilian Portuguese Support [pt_BR]

   Breton Support [br]

   Bulgarian Support [bg]

   Catalan Support [ca]

   Chhattisgarhi Support [hne]

   Chichewa Support [ny]

   Chinese Support [zh]

   Coptic Support [cop]

   Croatian Support [hr]

   Czech Support [cs]

   Danish Support [da]

   Dutch Support [nl]

   English (UK) Support [en_GB]

   Esperanto Support [eo]

   Estonian Support [et]

   Ethiopic Support [am]

   Faroese Support [fo]

   Fijian Support [fj]

   Filipino Support [fil]

   Finnish Support [fi]

   French Support [fr]

   Frisian Support [fy]

   Friulian Support [fur]

   Gaelic Support [gd]

   Galician Support [gl]

   Georgian Support [ka]

   German Support [de]

   Greek Support [el]

   Gujarati Support [gu]

   Hebrew Support [he]

   Hiligaynon Support [hil]

   Hindi Support [hi]

   Hungarian Support [hu]

   Icelandic Support [is]

   Indonesian Support [id]

   Interlingua Support [ia]

   Inuktitut Support [iu]

   Irish Support [ga]

   Italian Support [it]

   Japanese Support [ja]

   Kannada Support [kn]

   Kashmiri Support [ks]

   Kashubian Support [csb]

   Kazakh Support [kk]

   Khmer Support [km]

   Kinyarwanda Support [rw]

   Konkani Support [kok]

   Korean Support [ko]

   Kurdish Support [ku]

   Lao Support [lo]

   Latin Support [la]

   Latvian Support [lv]

   Lithuanian Support [lt]

   Low Saxon Support [nds]

   Luxembourgish Support [lb]

   Macedonian Support [mk]

   Maithili Support [mai]

   Malagasy Support [mg]

   Malay Support [ms]

   Malayalam Support [ml]

   Maltese Support [mt]

   Manx Support [gv]

   Maori Support [mi]

   Marathi Support [mr]

   Mongolian Support [mn]

   Myanmar (Burmese) Support [my]

   Nepali Support [ne]

   Northern Sotho Support [nso]

   Norwegian Support [nb]

   Occitan Support [oc]

   Oriya Support [or]

   Persian Support [fa]

   Polish Support [pl]

   Portuguese Support [pt]

   Punjabi Support [pa]

   Romanian Support [ro]

   Russian Support [ru]

   Sanskrit Support [sa]

   Sardinian Support [sc]

   Serbian Support [sr]

   Sindhi Support [sd]

   Sinhala Support [si]

   Slovak Support [sk]

   Slovenian Support [sl]

   Somali Support [so]

   Southern Ndebele Support [nr]

   Southern Sotho Support [st]

   Spanish Support [es]

   Swahili Support [sw]

   Swati Support [ss]

   Swedish Support [sv]

   Tagalog Support [tl]

   Tajik Support [tg]

   Tamil Support [ta]

   Telugu Support [te]

   Tetum Support [tet]

   Thai Support [th]

   Tibetan Support [bo]

   Tsonga Support [ts]

   Tswana Support [tn]

   Turkish Support [tr]

   Turkmen Support [tk]

   Ukrainian Support [uk]

   Upper Sorbian Support [hsb]

   Urdu Support [ur]

   Uzbek Support [uz]

   Venda Support [ve]

   Vietnamese Support [vi]

   Walloon Support [wa]

   Welsh Support [cy]

   Xhosa Support [xh]

   Zulu Support [zu]

Done

[root@backup ~]# yum groupinstall "NFS file server" -y  NFS服务端

Loaded plugins: fastestmirror, security

Setting up Group Process

Loading mirror speeds from cached hostfile

 * base: mirrors.sina.cn

 * extras: mirrors.sina.cn

 * updates: mirrors.sina.cn

Resolving Dependencies

--> Running transaction check

---> Package nfs-utils.x86_64 1:1.2.3-54.el6 will be installed

--> Processing Dependency: nfs-utils-lib >= 1.1.0-3 for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: keyutils >= 1.4-4 for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: rpcbind for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libtirpc for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libgssglue.so.1(libgssapi_CITI_2)(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libgssglue for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libevent for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libgssglue.so.1()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libevent-1.4.so.2()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

---> Package nfs4-acl-tools.x86_64 0:0.3.3-6.el6 will be installed

--> Running transaction check

---> Package keyutils.x86_64 0:1.4-5.el6 will be installed

---> Package libevent.x86_64 0:1.4.13-4.el6 will be installed

---> Package libgssglue.x86_64 0:0.1-11.el6 will be installed

---> Package libtirpc.x86_64 0:0.2.1-10.el6 will be installed

---> Package nfs-utils-lib.x86_64 0:1.1.5-9.el6_6 will be installed

---> Package rpcbind.x86_64 0:0.2.0-11.el6 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


===================================================

 Package       Arch   Version        Repository

                                              Size

===================================================

Installing:

 nfs-utils     x86_64 1:1.2.3-54.el6 base    326 k

 nfs4-acl-tools

               x86_64 0.3.3-6.el6    base     43 k

Installing for dependencies:

 keyutils      x86_64 1.4-5.el6      base     39 k

 libevent      x86_64 1.4.13-4.el6   base     66 k

 libgssglue    x86_64 0.1-11.el6     base     23 k

 libtirpc      x86_64 0.2.1-10.el6   base     79 k

 nfs-utils-lib x86_64 1.1.5-9.el6_6  updates  68 k

 rpcbind       x86_64 0.2.0-11.el6   base     51 k


Transaction Summary

===================================================

Install       8 Package(s)


Total download size: 695 k

Installed size: 1.8 M

Is this ok [y/N]: y

Downloading Packages:

(1/8): keyutils-1.4-5.el6.x |  39 kB     00:00     

(2/8): libevent-1.4.13-4.el |  66 kB     00:00     

(3/8): libgssglue-0.1-11.el |  23 kB     00:00     

(4/8): libtirpc-0.2.1-10.el |  79 kB     00:00     

(5/8): nfs-utils-1.2.3-54.e | 326 kB     00:00     

(6/8): nfs-utils-lib-1.1.5- |  68 kB     00:00     

(7/8): nfs4-acl-tools-0.3.3 |  43 kB     00:00     

(8/8): rpcbind-0.2.0-11.el6 |  51 kB     00:00     

---------------------------------------------------

Total              283 kB/s | 695 kB     00:02     

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : libgssglue-0.1-11.el6.x86_64    1/8 

  Installing : libtirpc-0.2.1-10.el6.x86_64    2/8 

  Installing : rpcbind-0.2.0-11.el6.x86_64     3/8 

  Installing : keyutils-1.4-5.el6.x86_64       4/8 

  Installing : libevent-1.4.13-4.el6.x86_64    5/8 

  Installing : nfs-utils-lib-1.1.5-9.el6_6.x   6/8 

  Installing : 1:nfs-utils-1.2.3-54.el6.x86_   7/8 

  Installing : nfs4-acl-tools-0.3.3-6.el6.x8   8/8 

  Verifying  : libevent-1.4.13-4.el6.x86_64    1/8 

  Verifying  : rpcbind-0.2.0-11.el6.x86_64     2/8 

  Verifying  : keyutils-1.4-5.el6.x86_64       3/8 

  Verifying  : 1:nfs-utils-1.2.3-54.el6.x86_   4/8 

  Verifying  : nfs-utils-lib-1.1.5-9.el6_6.x   5/8 

  Verifying  : libtirpc-0.2.1-10.el6.x86_64    6/8 

  Verifying  : libgssglue-0.1-11.el6.x86_64    7/8 

  Verifying  : nfs4-acl-tools-0.3.3-6.el6.x8   8/8 


Installed:

  nfs-utils.x86_64 1:1.2.3-54.el6                  

  nfs4-acl-tools.x86_64 0:0.3.3-6.el6              


Dependency Installed:

  keyutils.x86_64 0:1.4-5.el6                      

  libevent.x86_64 0:1.4.13-4.el6                   

  libgssglue.x86_64 0:0.1-11.el6                   

  libtirpc.x86_64 0:0.2.1-10.el6                   

  nfs-utils-lib.x86_64 0:1.1.5-9.el6_6             

  rpcbind.x86_64 0:0.2.0-11.el6                    


Complete!


NFS客户端:

[root@oldboy ~]#yum install nfs-utils rpcbind -y  NFS客户端

Failed to set locale, defaulting to C

Loaded plugins: fastestmirror, security

Setting up Install Process

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

Resolving Dependencies

--> Running transaction check

---> Package nfs-utils.x86_64 1:1.2.3-54.el6 will be installed

--> Processing Dependency: nfs-utils-lib >= 1.1.0-3 for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: keyutils >= 1.4-4 for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libtirpc for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libgssglue.so.1(libgssapi_CITI_2)(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libgssglue for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libevent for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libgssglue.so.1()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

--> Processing Dependency: libevent-1.4.so.2()(64bit) for package: 1:nfs-utils-1.2.3-54.el6.x86_64

---> Package rpcbind.x86_64 0:0.2.0-11.el6 will be installed

--> Running transaction check

---> Package keyutils.x86_64 0:1.4-5.el6 will be installed

---> Package libevent.x86_64 0:1.4.13-4.el6 will be installed

---> Package libgssglue.x86_64 0:0.1-11.el6 will be installed

---> Package libtirpc.x86_64 0:0.2.1-10.el6 will be installed

---> Package nfs-utils-lib.x86_64 0:1.1.5-9.el6_6 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


===================================================

 Package       Arch   Version        Repository

                                              Size

===================================================

Installing:

 nfs-utils     x86_64 1:1.2.3-54.el6 base    326 k

 rpcbind       x86_64 0.2.0-11.el6   base     51 k

Installing for dependencies:

 keyutils      x86_64 1.4-5.el6      base     39 k

 libevent      x86_64 1.4.13-4.el6   base     66 k

 libgssglue    x86_64 0.1-11.el6     base     23 k

 libtirpc      x86_64 0.2.1-10.el6   base     79 k

 nfs-utils-lib x86_64 1.1.5-9.el6_6  updates  68 k


Transaction Summary

===================================================

Install       7 Package(s)


Total download size: 652 k

Installed size: 1.7 M

Is this ok [y/N]: y

Downloading Packages:

(1/7): keyutils-1.4-5.el6.x |  39 kB     00:00     

(2/7): libevent-1.4.13-4.el |  66 kB     00:00     

(3/7): libgssglue-0.1-11.el |  23 kB     00:00     

(4/7): libtirpc-0.2.1-10.el |  79 kB     00:00     

(5/7): nfs-utils-1.2.3-54.e | 326 kB     00:01     

(6/7): nfs-utils-lib-1.1.5- |  68 kB     00:00     

(7/7): rpcbind-0.2.0-11.el6 |  51 kB     00:00     

---------------------------------------------------

Total              147 kB/s | 652 kB     00:04     

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : libgssglue-0.1-11.el6.x86_64    1/7 

  Installing : libtirpc-0.2.1-10.el6.x86_64    2/7 

  Installing : rpcbind-0.2.0-11.el6.x86_64     3/7 

  Installing : keyutils-1.4-5.el6.x86_64       4/7 

  Installing : libevent-1.4.13-4.el6.x86_64    5/7 

  Installing : nfs-utils-lib-1.1.5-9.el6_6.x   6/7 

  Installing : 1:nfs-utils-1.2.3-54.el6.x86_   7/7 

  Verifying  : libevent-1.4.13-4.el6.x86_64    1/7 

  Verifying  : rpcbind-0.2.0-11.el6.x86_64     2/7 

  Verifying  : keyutils-1.4-5.el6.x86_64       3/7 

  Verifying  : 1:nfs-utils-1.2.3-54.el6.x86_   4/7 

  Verifying  : nfs-utils-lib-1.1.5-9.el6_6.x   5/7 

  Verifying  : libtirpc-0.2.1-10.el6.x86_64    6/7 

  Verifying  : libgssglue-0.1-11.el6.x86_64    7/7 


Installed:

  nfs-utils.x86_64 1:1.2.3-54.el6                  

  rpcbind.x86_64 0:0.2.0-11.el6                    


Dependency Installed:

  keyutils.x86_64 0:1.4-5.el6                      

  libevent.x86_64 0:1.4.13-4.el6                   

  libgssglue.x86_64 0:0.1-11.el6                   

  libtirpc.x86_64 0:0.2.1-10.el6                   

  nfs-utils-lib.x86_64 0:1.1.5-9.el6_6             


Complete!


[root@backup ~]# rpm -qa "nfs-utils|rpcbind|portmap" NFS服务端

nfs-utils-1.2.3-54.el6.x86_64

nfs-utils-lib-1.1.5-9.el6_6.x86_64

rpcbind-0.2.0-11.el6.x86_64

[root@oldboy ~]#rpm -qa "nfs-utils|rpcbind|portmap"  NFS客户端

nfs-utils-lib-1.1.5-9.el6_6.x86_64

rpcbind-0.2.0-11.el6.x86_64

nfs-utils-1.2.3-54.el6.x86_64


NFS服务端:

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

Starting rpcbind:                                 [  OK  ]

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

rpc       3169     1  0 08:58 ?        00:00:00 rpcbind

root      3173  2900  0 08:58 pts/0    00:00:00 grep rpc

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

rpcbind (pid  3169) is running...

[root@backup ~]# 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@backup ~]# /etc/init.d/rpcbind stop

Stopping rpcbind:                                 [  OK  ]

[root@backup ~]# rpcinfo -p localhost    

rpcinfo: can‘t contact portmapper: RPC: Remote system error - Connection refused


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

Starting rpcbind:                                 [  OK  ]

[root@backup ~]# 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@backup ~]# /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@backup ~]# 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  32923  mountd

    100005    1   tcp  38492  mountd

    100005    2   udp  44186  mountd

    100005    2   tcp  52464  mountd

    100005    3   udp  42052  mountd

    100005    3   tcp  37846  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  58384  nlockmgr

    100021    3   udp  58384  nlockmgr

    100021    4   udp  58384  nlockmgr

    100021    1   tcp  49852  nlockmgr

    100021    3   tcp  49852  nlockmgr

    100021    4   tcp  49852  nlockmgr


[root@backup ~]# chkconfig rpcbind on

[root@backup ~]# chkconfig nfs on

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

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

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

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


[root@backup ~]# more /etc/init.d/rpcbind

#! /bin/sh

#

# rpcbind       Start/Stop RPCbind

#

# chkconfig: 2345 13 87

# description: The rpcbind utility is a server that

 converts RPC program \

#              numbers into universal addresses. It

 must be running on the \

#              host to be able to make RPC calls on

 a server on that machine.

#

[root@backup ~]# more /etc/init.d/nfs

#!/bin/sh

#

# nfs           This shell script takes care of sta

rting and stopping

#               the NFS services.

#

# chkconfig: - 30 60

# description: NFS is a popular protocol for file s

haring across networks.

#              This service provides NFS server fun

ctionality, which is \

#              configured via the /etc/exports file

    通过查看以上两个服务的启动脚本,得出,启动时先启动rpcbind,然后是nfs;关闭时先关闭NFS,然后关闭rpcbind.


NFS客户端:

[root@oldboy ~]#/etc/init.d/rpcbind start  客户端只需要启动rpcbind

Starting rpcbind:                                 [  OK  ]

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

rpcbind (pid  2924) is running...

[root@oldboy ~]#chkconfig rpcbind on

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

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


NFS服务端:

[root@backup ~]# ll /etc/exports

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

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

[root@backup ~]# vi /etc/exports 

#shared backup for bbs by oldboy at 20150711

/backup/NFS 192.168.0.0/24(rw,sync)

~                                                  

~                                                  

~                                                  

~                                                                                          

"/etc/exports" 2L, 81C written

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

#shared backup for bbs by oldboy at 20150711

/backup/NFS 192.168.0.0/24(rw,sync)

[root@backup ~]# /etc/init.d/nfs reload和exportfs -r是等价的  优雅平滑重启NFS服务,不影响服务使用,提升客户体验

[root@backup ~]# showmount -e localhost 服务端查看共享

Export list for localhost:

/backup/NFS 192.168.0.0/24


[root@oldboy ~]#showmount -e 192.168.0.114 客户端查看共享

Export list for 192.168.0.114:

/backup/NFS 192.168.0.0/24


客户端查看不到NFS服务端共享的解决方法:

1.ping 服务端IP

2.telnet 服务端IP 111(rpcbind服务监听端口)


[root@oldboy ~]#df -h      

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       7.6G  2.2G  5.1G  31% /

tmpfs           495M     0  495M   0% /dev/shm

/dev/sda1       190M   27M  153M  15% /boot

[root@oldboy ~]#mount -t nfs 192.168.0.114:/backup/NFS /mnt

[root@oldboy ~]#df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             7.6G  2.2G  5.1G  31% /

tmpfs                 495M     0  495M   0% /dev/shm

/dev/sda1             190M   27M  153M  15% /boot

192.168.0.114:/backup/NFS

                      7.6G  4.7G  2.6G  65% /mnt


[root@backup ~]# ll /backup/NFS  NFS服务端共享的目录要给其他用户给“写权限”,以免客户端写数据时出现“无权限”的错误

total 4

drwxrwxrwx 5 nobody nobody 4096 Apr 13 00:00 data


[root@oldboy ~]#ll /mnt  NFS客户端

total 4

drwxrwxrwx 5 nobody nobody 4096 Apr 13 00:00 data


[root@backup ~]# cat /var/lib/nfs/etab

/backup/NFS     192.168.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)


[root@backup ~]# grep 65534 /etc/passwd

nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin


提高NFS服务端共享目录的安全性操作

[root@backup ~]# chmod 755 /backup

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


NFS客户端:

[root@oldboy mnt]#pwd

/mnt

[root@oldboy mnt]#ll

total 4

drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data

[root@oldboy mnt]#touch oldboy.log

[root@oldboy mnt]#ll

total 4

drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data

-rw-r--r-- 1 nfsnobody nfsnobody    0 Jul 11 10:32 oldboy.log

[root@oldboy mnt]#rm -f oldboy.log

[root@oldboy mnt]#ll

total 4

drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data


NFS服务端:

[root@backup ~]# chmod 755 /backup/NFS

[root@backup ~]# ll /backup

total 16

drwxrwxrwx 3 nfsnobody nfsnobody 4096 Apr  7 00:41 LAMP

drwxrwxrwx 3 nfsnobody nfsnobody 4096 Apr  7 00:39 LNMP

drwxrwxrwx 3 nfsnobody nfsnobody 4096 Apr  7 00:35 mysql

drwxr-xr-x 3 nfsnobody nfsnobody 4096 Jul 11 10:32 NFS


NFS客户端:

[root@oldboy mnt]#ll   

total 4

drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data

[root@oldboy mnt]#touch dd.log

[root@oldboy mnt]#ll

total 4

drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data

-rw-r--r-- 1 nfsnobody nfsnobody    0 Jul 11 10:37 dd.log

[root@oldboy mnt]#rm -f dd.log

[root@oldboy mnt]#ll

total 4

drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data


[root@oldboy mnt]#echo "mount -t nfs 192.168.0.114:/backup/NFS /mnt" >>/etc/rc.local  加入开机启动

[root@oldboy mnt]#cat /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don‘t

# want to do the full Sys V style init stuff.


touch /var/lock/subsys/local

/usr/local/nginx/sbin/nginx

/etc/init.d/keepalived start

mount -t nfs 192.168.0.114:/backup/NFS /mnt



三、NFS服务的相关功能组件介绍

NFS服务端:

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

rpcbind (pid  3239) is running...

[root@backup ~]# /etc/init.d/nfs status    

rpc.svcgssd is stopped

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

nfsd (pid 3300 3299 3298 3297 3296 3295 3294 3293) is running...

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

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

rpc    3239    1  0 09:01 ?     00:00:00 rpcbind rpc服务 rpcbind==>portmap(C5.8)远程过程调用服务

root   3270    2  0 09:01 ?     00:00:00 [rpciod/0] 

root   3279    1  0 09:01 ?     00:00:00 rpc.rquotad  磁盘配额进程

root   3284    1  0 09:01 ?     00:00:00 rpc.mountd   权限管理进程

root   3291    2  0 09:01 ?     00:00:00 [nfsd4]      

root   3292     2  0 09:01 ?    00:00:00 [nfsd4_callbacks]

root   3293     2  0 09:01 ?    00:00:00 [nfsd]       NFS主进程

root   3294     2  0 09:01 ?    00:00:00 [nfsd]

root   3295     2  0 09:01 ?    00:00:00 [nfsd]

root   3296     2  0 09:01 ?    00:00:00 [nfsd]

root   3297     2  0 09:01 ?    00:00:00 [nfsd]       NFS主进程

root   3298     2  0 09:01 ?    00:00:00 [nfsd]

root   3299     2  0 09:01 ?    00:00:00 [nfsd]

root   3300     2  0 09:01 ?    00:00:00 [nfsd]       NFS主进程

root   3327     1  0 09:01 ?    00:00:00 rpc.idmapd   

root   9165  6649  0 20:56 pts/1  00:00:00 grep -E rpc|nfs


[root@backup ~]# /etc/init.d/nfs restart

Shutting down NFS daemon:                         [  OK  ]

Shutting down NFS mountd:                         [  OK  ]

Shutting down NFS quotas:                         [  OK  ]

Shutting down NFS services:                       [  OK  ]

Shutting down RPC idmapd:                         [  OK  ]

Starting NFS services:                            [  OK  ]

Starting NFS quotas:                              [  OK  ]

Starting NFS mountd:                              [  OK  ]

Starting NFS daemon:                              [  OK  ]

Starting RPC idmapd:                                [  OK  ]


[root@backup ~]# ps -ef|egrep "rpc|nfs"   

rpc       3239     1  0 09:01 ?        00:00:00 rpcbind

root      3270     2  0 09:01 ?        00:00:00 [rpciod/0]

root      9268     1  0 20:58 ?        00:00:00 rpc.rquotad

root      9273     1  0 20:58 ?        00:00:00 rpc.mountd

root      9280     2  0 20:58 ?        00:00:00 [nfsd4]

root      9281     2  0 20:58 ?        00:00:00 [nfsd4_callbacks]

root      9282     2  0 20:58 ?        00:00:00 [nfsd]

root      9283     2  0 20:58 ?        00:00:00 [nfsd]

root      9284     2  0 20:58 ?        00:00:00 [nfsd]

root      9285     2  0 20:58 ?        00:00:00 [nfsd]

root      9286     2  0 20:58 ?        00:00:00 [nfsd]

root      9287     2  0 20:58 ?        00:00:00 [nfsd]

root      9288     2  0 20:58 ?        00:00:00 [nfsd]

root      9289     2  0 20:58 ?        00:00:00 [nfsd]

root      9316     1  0 20:58 ?        00:00:00 rpc.idmapd

root      9365  6649  0 21:08 pts/1    00:00:00 egrep rpc|nfs


[root@backup ~]# cat /var/lib/nfs/etab

/backup/NFS     192.168.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534)


NFS客户端:

[root@oldboy mnt]#df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3             7.6G  2.2G  5.1G  31% /

tmpfs                 495M     0  495M   0% /dev/shm

/dev/sda1             190M   27M  153M  15% /boot

192.168.0.114:/backup/NFS

                      7.6G  4.7G  2.6G  65% /mnt

[root@oldboy mnt]#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)

192.168.0.114:/backup/NFS on /mnt type nfs (rw,vers=4,addr=192.168.0.114,clientaddr=192.168.0.131)


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

#shared backup for bbs by oldboy at 20150711

/backup/NFS 192.168.0.0/24(rw,sync)  

 共享目录  可以访问共享  访问的客

          目录的网段或主 户端权限

          机、域名       以及数据

                        是否从缓

                        存同步到

                        磁盘


四、配置NFS生产重要技巧

1.确保所有服务器对NFS共享目录具备相同的权限

  a.all_squash把所有客户端都压缩成匿名用户

  b.就是anonuid,anongid指定的UID和GID的用户

2.所有的客户端和服务端都需要有一个相同的UID和GID的用户,即nfsnobody(UID必须相同)


本文出自 “兰州linux运维” 博客,请务必保留此出处http://linuxzkq.blog.51cto.com/9379412/1675931

NFS网络文件共享服务

标签:nfs网络文件共享服务

原文地址:http://linuxzkq.blog.51cto.com/9379412/1675931

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!