NFS Network File System

1, NFS Network File System Introduction

    1) NFS concepts Description:

    What is nfs? nfs is an acronym for Network File system, and its main function is to allow the network can share files or directories each other between different host systems. NFS clients (typically an application server, such as Web) server may be shared by a data file directory is mounted NFS mount (Mount) manner to the NFS client local system (that is a mount point a). View from the NFS client mount a local directory, that is, access to a shared directory on the NFS server.

    A network share with Windows systems like NFS network file system, security features, network drive mappings, this is also similar to the Linux Samba service.

    2) NFS in the enterprise application scenarios:

    In scenes work in the enterprise cluster architecture, NFS network file sharing systems are generally used to store video, images, attachments and other static resource files (usually the site's users to upload files on NFS shared in), NFS is the current Internet architecture one of the most commonly used data storage services, in particular small and medium sized company website high frequency applications. In addition to large companies or portal using NFS, but may also use MFS, GFS, FASTFS, TFS and other distributed file systems.

    3) Network File System Type:

    NFS: suitable for small and medium enterprises;

    MFS: used to store image files, distributed file system;

    GFS: generally used for cloud computing, do back-end storage of large files.

2, NFS server environment

[root@localhost /]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.1 (Maipo) # RedHat7.1 operating system
[root@localhost /]# uname -r
3.10.0-229.el7.x86_64.debug
[root@localhost /]# ifconfig|sed -n '2,2p'|awk '{print $2}'
Server IP address 192.168.26.11 #

3, NFS installation service

    1) yum install nfs service package

    ① rpcbind: This package is rpc main program, the client and the server needs to be installed;

    ② nfs-utils: This package is the main program NFS services, clients and servers need to be installed.

[Root @ localhost /] # rpm -qa nfs-utils rpcbind # check whether the installation package
[Root @ localhost /] # yum -y ××× tall nfs-utils rpcbind # install packages
[Root @ localhost /] # rpm -qa rpcbind nfs-utils # check whether the installation package
rpcbind-0.2.0-26.el7.x86_64
nfs-utils-1.3.0-0.8.el7.x86_64

    2) error when installing packages and solutions

    ① install rpcbind error message

[root@nfs-client /]# yum -y ×××tall rpcbind

Failed to set locale, defaulting to C

Loaded plug×××: fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirrors.163.com

 * extras: mirrors.163.com

 * updates: mirrors.163.com

*********************** omitted part ***************

error: %pre(rpcbind-0.2.0-44.el7.x86_64) scriptlet failed, exit status 6

Error in PREIN scriptlet in rpm package rpcbind-0.2.0-44.el7.x86_64

  Verifying  : rpcbind-0.2.0-44.el7.x86_64                                         1/1

 

Failed:

  rpcbind.x86_64 0:0.2.0-44.el7                                                       

 

Complete!

    ② Solution

Error message when installing the software to perform any script error has occurred, after Baidu know by installing rpm when the package will first execute rpm pre-scripts package, the script should be executed when the error occurred, so I tried View this script is executed what content ;

So how do you get to this script it?

Take the corresponding rpm package
yum ××× tall xxxxpackage --downloadonly --downloaddir = / root
acquired rpm corresponding to pre-install script
rpm --scripts -qp xxxxpackage> x-scripts.log

The script found useful to useradd / userdel command to add rpc user, thus remembered before using chattr + i / etc / passwd for the passwd file locking done deal, it will cause useradd / userdel command can not be executed properly, this should be It is the cause of pre-scripts can not execute it properly, use the chattr -i / etc / passwd after unlocking software can be installed properly.

4, start the NFS service (server-side)

    1) Start rpcbind service

[root@localhost /]# systemctl start rpcbind       #启动rpcbind
[Root @ localhost /] # systemctl enable rpcbind # Check whether to start rpc
[Root @ localhost /] # systemctl is-active rpcbind # Set boot from the start rpcbind
active
[Root @ localhost /] # systemctl is-enabled rpcbind # rpcbind to see whether the boot from the start
enabled

    2) Start nfs service

[Root @ localhost /] # systemctl start nfs # nfs start
[Root @ localhost /] # systemctl is-active nfs # to see whether nfs start
active
[Root @ localhost /] # systemctl enable nfs-server.service # Set boot from the start nfs
ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/multi-user.target.wants/nfs-server.service'
[root@localhost /]# echo $?
0
Whether [root @ localhost /] # systemctl is-enabled nfs-server # View nfs boot from the start
enabled

    3) View rpc process

[Root @ localhost /] # ps -ef | grep -v grep | grep rpc
rpc       22647      1  0 15:31 ?        00:00:00 /sbin/rpcbind -w
root      22676      2  0 15:33 ?        00:00:00 [rpciod]
rpcuser   22686      1  0 15:33 ?        00:00:00 /usr/sbin/rpc.statd --no-notify
root      22691      1  0 15:33 ?        00:00:00 /usr/sbin/rpc.idmapd
root      22692      1  0 15:33 ?        00:00:00 /usr/sbin/rpc.mountd

    4) Check the status rpc

[root@localhost /]# systemctl status rpcbind
Part ########### ########### omitted
   Active: active (running) since 五 2019-06-14 15:31:56 CST; 8min ago
Part ########### ########### omitted

    5) Check there are no registered rpc port (default port 111 is the rpc)

[root@localhost /]# 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
    100024    1   udp  44701  status
    100024    1   tcp  55897  status
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  48795  nlockmgr
    100021    3   udp  48795  nlockmgr
    100021    4   udp  48795  nlockmgr
    100021    1   tcp  59460  nlockmgr
    100021    3   tcp  59460  nlockmgr
    100021    4   tcp  59460  nlockmgr

5, NFS client startup (you can only start rpc service)

    1) nfs client environment

[root@vms002 /]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.1 (Maipo) # Operating System
[root@vms002 /]# uname -r
3.10.0-229.el7.x86_64
[root@vms002 /]# ifconfig|sed -n '2,2p'|awk '{print $2}'
192.168.26.102 #nfs client IP address

    2) install rpcbind    

[root@vms002 /]# yum -y ×××tall rpcbind

    3) Start rpcbind service

[root@vms002 /]# systemctl start rpcbind
[root@vms002 /]# systemctl is-active rpcbind
active

    2) View rpc there is no registered port

[root@vms002 /]# 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
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100024    1   udp  57887  status
    100024    1   tcp  36792  status
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  51830  nlockmgr
    100021    3   udp  51830  nlockmgr
    100021    4   udp  51830  nlockmgr
    100021    1   tcp  46841  nlockmgr
    100021    3   tcp  46841  nlockmgr
    100021    4   tcp  46841  nlockmgr

6, configuration and testing

    1) server configuration

    ① you want to create a shared directory

[root@localhost /]# ifconfig|sed -n '2,2p'|awk '{print $2}'
192.168.26.11
[root@localhost /]# mkdir /data

    ② configuration NFS configuration file (the default configuration file is empty)

[root@localhost /]# vim /etc/exports

###############
/ Data 192.168.26.0/24(rw,sync) # / data is shared directory; 192.168.26.0/24 is allowed access to the network addresses; (rw, sync) is the authority

    ③ reloaded nfs service (try not to restart the service)

[root@localhost /]# systemctl reload nfs

    ④ Check nfs shared configuration is successful

[root@localhost /]# showmount -e localhost
Export list for localhost:
/data 192.168.26.0/24

    ⑤ store data or create a file to a shared directory created in Step inside, compared with the client whether as inferior

[root@localhost /]# cd /data/
[root@localhost data]# touch aa{1..3}
[root@localhost data]# touch oldboy-{5..8}
[root@localhost data]# ls
aa1  aa2  aa3  oldboy-5  oldboy-6  oldboy-7  oldboy-8

    ⑥ the owner and the shared directory is a user group is set to NFS

[root@localhost data]# chown -R nfsnobody:nfsnobody /data/
[root@localhost data]# ls -ld /data
drwxr-xr-x. 2 nfsnobody nfsnobody 96 6月  14 16:24 /data

    2) Client configuration and testing

    ① check NFS server is OK

[root@vms002 /]# ifconfig|sed -n '2,2p'|awk '{print $2}'
192.168.26.102
[Root @ vms002 /] # showmount -e 192.168.26.11
Export list for 192.168.26.11:
/data 192.168.26.0/24

    Create a mount ② client directory nfs-data, to mount nfs

[Root @ vms002 /] # mkdir / nfs-data # Create the mount directory
[Root @ vms002 /] # mount -t nfs 192.168.26.11:/data / nfs-data / # mount the shared directory nfs
[Root @ vms002 /] # df -hT # View the mounted nfs shared directory
File system type available capacity has been used with a mount point%
/dev/sda1           xfs        40G  3.2G   37G    8% /
192.168.26.11:/data nfs4 18G 4.1G 14G 24% / nfs-data #nfs shared directory

    ③ see if nfs-data directory is an NFS server sharing the data and creates the file to see if write access to the nfs success.

[root@vms002 /]# cd /nfs-data/
[root@vms002 nfs-data]# ls
aa1  aa2  aa3  oldboy-5  oldboy-6  oldboy-7  oldboy-8
[root@vms002 nfs-data]# touch www{1..5}
[root@vms002 nfs-data]# ls
aa1  aa3       oldboy-6  oldboy-8  www2  www4
oldboy AA2-5-7 oldboy www1 www3 www5

    ④ set the boot automatically mount

[root@vms002 /]# vim /etc/fstab 
192.168.26.11:/data  /nfs-data  nfs  defaults  0 0
[root@vms002 /]# umount /nfs-data/
[root@vms002 /]# df -hT
File system type available capacity has been used with a mount point%
/dev/sda1      xfs        40G  3.2G   37G    8% /
devtmpfs       devtmpfs  2.0G     0  2.0G    0% /dev
tmpfs          tmpfs     2.0G  148K  2.0G    1% /dev/shm
tmpfs          tmpfs     2.0G   17M  2.0G    1% /run
tmpfs          tmpfs     2.0G     0  2.0G    0% /sys/fs/cgroup
/ Dev / sr0 iso9660 3.7G 3.7G 0 100% /run/media/jerry/RHEL-7.1 Server.x86_64
[root@vms002 /]# mount -a
[root@vms002 /]# df -hT
File system type available capacity has been used with a mount point%
/dev/sda1           xfs        40G  3.2G   37G    8% /
devtmpfs            devtmpfs  2.0G     0  2.0G    0% /dev
tmpfs               tmpfs     2.0G  148K  2.0G    1% /dev/shm
tmpfs               tmpfs     2.0G   17M  2.0G    1% /run
tmpfs               tmpfs     2.0G     0  2.0G    0% /sys/fs/cgroup
/ Dev / sr0 iso9660 3.7G 3.7G 0 100% /run/media/jerry/RHEL-7.1 Server.x86_64
192.168.26.11:/data nfs4       18G  4.1G   14G   24% /nfs-data

    3) Client error cases:

    ① testing services side of the NFS service fails, the error message

[Root @ vms002 /] # showmount -e 192.168.26.11
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

    ② Solution:

    # The information given above, nfs server may be firewalld server (firewall) intercepted, close NFS server or the firewall allows

[root@localhost data]# systemctl stop firewalld

    #nfs client to check again whether the client can connect to the server nfs

[Root @ vms002 NFS data] # showmount -e 192.168.26.11
Export list for 192.168.26.11:
/data 192.168.26.0/24

7. Conclusions

    1) NFS server

    ① Check for and install nfs service

[root@localhost /]# rpm -qa rpcbind nfs-utils
[root@localhost /]# yum -y ×××tall rpcbind nfs-utils

    ② start rpc nfs and services as well as setting and check the boot from the start

[root@localhost /]# systemctl start rpcbind
[root@localhost /]# systemctl enable rpcbind
[root@localhost /]# systemctl start nfs-server
[root@localhost /]# systemctl enable nfs-server
[root@localhost /]# systemctl is-active rpcbind
active
[root@localhost /]# systemctl is-enabled rpcbind
enabled
[root@localhost /]# systemctl is-active nfs-server
active
[root@localhost /]# systemctl is-enabled nfs-server
enabled

    ③ configure the shared / data directory

[root@localhost /]# vim /etc/exports
############### comment ################
/data 192.168.26.0/24(rw,sync)

    ④ reload the NFS service (try not to restart)

[root@localhost /]# systemctl reload nfs

    ⑤ check whether nfs service configuration success

[root@localhost /]# showmount -e localhost
Export list for localhost:
/data 192.168.26.0/24

    ⑥ Set permissions on a shared directory (the owner and the shared directory is a user group is set to nfs)

[root@localhost data]# chown -R nfsnobody:nfsnobody /data/
[root@localhost data]# ls -ld /data
drwxr-xr-x. 2 nfsnobody nfsnobody 96 6月  14 16:24 /data

    2) Client (client service can only start rpc)

    ① and install nfs rpc software

[root@localhost /]# rpm -qa rpcbind nfs-utils
[root@localhost /]# yum -y ×××tall rpcbind nfs-utils

    ② start rpc service, and set boot from the start, and check

[root@vms002 /]# systemctl start rpcbind
[root@vms002 /]# systemctl enable rpcbind
[root@vms002 /]# systemctl is-active rpcbind
active
[root@vms002 /]# systemctl is-enabled rpcbind
enabled

    ③ Check the NFS server is OK

[Root @ vms002 /] # showmount -e 192.168.26.11
Export list for 192.168.26.11:
/data 192.168.26.0/24

    ④ mount and test

[root@vms002 /]# mount -t nfs 192.168.26.11:/data /nfs-data/
[root@vms002 /]# cd /nfs-data/
[root@vms002 nfs-data]# ls
aa1  aa2  aa3  oldboy-5  oldboy-6  oldboy-7  oldboy-8
[root@vms002 nfs-data]# touch www{1..5}
[root@vms002 nfs-data]# ls
aa1  aa3       oldboy-6  oldboy-8  www2  www4
oldboy AA2-5-7 oldboy www1 www3 www5

    ⑤ to set the boot automatically mount

[root@vms002 /]# vim /etc/fstab 
192.168.26.11:/data  /nfs-data  nfs  defaults  0 0


Guess you like

Origin blog.51cto.com/13716812/2409230
Recommended