设为首页 收藏本站
查看: 273|回复: 0

[经验分享] NFS网络文件共享服务

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-20 09:31:56 | 显示全部楼层 |阅读模式
         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服务端:
[iyunv@backup ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[iyunv@backup ~]# uname -r Centos当前系统内核版本号
2.6.32-504.el6.x86_64
[iyunv@backup ~]# uname -m
x86_64
[iyunv@backup ~]# uname -n 机器名
backup
[iyunv@backup ~]# rpm -qa "nfs-utils|rpcbind|portmap"
[iyunv@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

   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
[iyunv@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客户端:
[iyunv@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!

[iyunv@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
[iyunv@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服务端:
[iyunv@backup ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                 [  OK  ]
[iyunv@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
[iyunv@backup ~]# /etc/init.d/rpcbind status
rpcbind (pid  3169) is running...
[iyunv@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

[iyunv@backup ~]# /etc/init.d/rpcbind stop
Stopping rpcbind:                                 [  OK  ]
[iyunv@backup ~]# rpcinfo -p localhost   
rpcinfo: can't contact portmapper: RPC: Remote system error - Connection refused

[iyunv@backup ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                 [  OK  ]
[iyunv@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
[iyunv@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  ]
[iyunv@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

[iyunv@backup ~]# chkconfig rpcbind on
[iyunv@backup ~]# chkconfig nfs on
[iyunv@backup ~]# chkconfig --list nfs
nfs             0:off   1:off   2:on    3:on    4:on       5:on    6:off
[iyunv@backup ~]# chkconfig --list rpcbind
rpcbind         0:off   1:off   2:on    3:on    4:on       5:on    6:off

[iyunv@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.
#
[iyunv@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客户端:
[iyunv@oldboy ~]#/etc/init.d/rpcbind start  客户端只需要启动rpcbind
Starting rpcbind:                                 [  OK  ]
[iyunv@oldboy ~]#/etc/init.d/rpcbind status
rpcbind (pid  2924) is running...
[iyunv@oldboy ~]#chkconfig rpcbind on
[iyunv@oldboy ~]#chkconfig --list rpcbind   
rpcbind         0:off   1:off   2:on    3:on    4:on       5:on    6:off

NFS服务端:
[iyunv@backup ~]# ll /etc/exports
-rw-r--r--. 1 root root 0 Jan 12  2010 /etc/exports
[iyunv@backup ~]# cat /etc/exports
[iyunv@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
[iyunv@backup ~]# cat /etc/exports
#shared backup for bbs by oldboy at 20150711
/backup/NFS 192.168.0.0/24(rw,sync)
[iyunv@backup ~]# /etc/init.d/nfs reload和exportfs -r是等价的  优雅平滑重启NFS服务,不影响服务使用,提升客户体验
[iyunv@backup ~]# showmount -e localhost 服务端查看共享
Export list for localhost:
/backup/NFS 192.168.0.0/24

[iyunv@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服务监听端口)

[iyunv@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
[iyunv@oldboy ~]#mount -t nfs 192.168.0.114:/backup/NFS /mnt
[iyunv@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

[iyunv@backup ~]# ll /backup/NFS  NFS服务端共享的目录要给其他用户给“写权限”,以免客户端写数据时出现“无权限”的错误
total 4
drwxrwxrwx 5 nobody nobody 4096 Apr 13 00:00 data

[iyunv@oldboy ~]#ll /mnt  NFS客户端
total 4
drwxrwxrwx 5 nobody nobody 4096 Apr 13 00:00 data

[iyunv@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)

[iyunv@backup ~]# grep 65534 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

提高NFS服务端共享目录的安全性操作
[iyunv@backup ~]# chmod 755 /backup
[iyunv@backup ~]# chown -R nfsnobody.nfsnobody /backup

NFS客户端:
[iyunv@oldboy mnt]#pwd
/mnt
[iyunv@oldboy mnt]#ll
total 4
drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data
[iyunv@oldboy mnt]#touch oldboy.log
[iyunv@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
[iyunv@oldboy mnt]#rm -f oldboy.log
[iyunv@oldboy mnt]#ll
total 4
drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data

NFS服务端:
[iyunv@backup ~]# chmod 755 /backup/NFS
[iyunv@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客户端:
[iyunv@oldboy mnt]#ll   
total 4
drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data
[iyunv@oldboy mnt]#touch dd.log
[iyunv@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
[iyunv@oldboy mnt]#rm -f dd.log
[iyunv@oldboy mnt]#ll
total 4
drwxrwxrwx 5 nfsnobody nfsnobody 4096 Apr 13 00:00 data

[iyunv@oldboy mnt]#echo "mount -t nfs 192.168.0.114:/backup/NFS /mnt" >>/etc/rc.local  加入开机启动
[iyunv@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服务端:
[iyunv@backup ~]# /etc/init.d/rpcbind status
rpcbind (pid  3239) is running...
[iyunv@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...
[iyunv@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

[iyunv@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  ]

[iyunv@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

[iyunv@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客户端:
[iyunv@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
[iyunv@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)

[iyunv@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必须相同)



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-88519-1-1.html 上篇帖子: Openssl建立CA,在组织内部基于ca的认证 下篇帖子: Linux下的软件安装 网络
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表