NFS operations and deployment

1 basic knowledge

1.1 brief introduction and application scenarios

  1. Brief description NFS: network file system, which enables different host systems to share files or directories through the network. The client accesses the server by mounting the server directory locally
  2. Application scenario: When multiple web clusters provide external access through the load balancer, all pictures, attachments and videos are stored on a specific server to avoid the problem of data synchronization stored on the web server

1.2 benefits and rationale

  1. Shared storage benefits:
    • Achieve data consistency
    • Save website disk resources
    • Save website access bandwidth
  2. Port and RPC: NFS does not have a fixed external port, and idle ports will be randomly selected every time it is started. In order to enable clients to access NFS shares through the network, RPC service is used. RPC service is equivalent to an intermediary. Every time NFS is started, it will notify RPC of port information. When clients access NFS shares, they first find RPC to obtain NFS ports, and then use this port to access NFS shared resources RPC service must be started before NFS service before NFS can work properly
  3. Principle of NFS shared storage service: nfs server creates shared storage directory nfs client creates remote mount point directory nfs client for remote mount Realize the consistency of client data information

2 NFS service deployment

2.1 environmental information

2.1.1 system information

[root@xxx ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
uname -r

2.1.2 server information

server name

IP address

Server usage


nfs backup server


web server


web server


web server

2.2 server deployment

  1. Check and install services for NFS
rpm -aq|egrep "nfs-utils|rpcbind"
yum install nfs-utils rpcbind -y
rpm -aq|egrep "nfs-utils|rpcbind"

#Check whether the two software are installed, and check again after installation 2) Edit nfs profile

cat >>/etc/exports <<"EOF"

The file exists by default 3) Create shared directory and authorize

mkdir /data
chown -R nfsnobody.nfsnobody /data
# The nfsnobody user is created automatically when the nfs program is installed
  1. Start rpc and NFS services
/etc/init.d/rpcbind start
/etc/init.d/nfs start

You need to start the rpc service first 5) Check the service status and whether the shared directory is available

[root@xxx ~]# rpcinfo -p
#There are 111 ports for rpc service, 2049 ports for nfs service, and many mount ports, indicating that they are correct
[root@xxx ~]# showmount -e
Export list for

If the above results appear, the server configuration is successful It is better to mount locally. If the mount is successful, you can at least confirm that the server is configured correctly and can be mounted 6) Set startup self startup and check

chkconfig nfs on
chkconfig rpcbind on
chkconfig --list|egrep "nfs|rpcbind"

2.3 Client Deployment [same operation for 3 sets]

  1. Check and install services for NFS
rpm -aq|egrep "nfs-utils|rpcbind"
yum install nfs-utils rpcbind -y 
  1. Mount shared directory
[root@xxx ~]# showmount -e
[root@xxx ~]# mount -t nfs /mnt
[root@xxx ~]# df -h|tail -1
Filesystem         Size  Used Avail Use% Mounted on  8.6G  1.9G  6.4G  23% /mnt
  1. Set boot auto mount
echo " mount -t nfs /mnt " >>/etc/rc.local

Do not put in / etc/fatab for startup, because fstab starts earlier. At that time, the network service has not been started, and the mount will fail 4) Conduct shared storage test explain: The data created in the local mnt directory can be seen on nfs and other servers mounted with this directory, that is, data shared storage has been realized

3. Description of configuration and process

3.1 description of important documents related to NFS shared file system

/etc/exports			nfs Service master profile
/usr/sbin/showmount		see nfs Service shared directory information
/usr/sbin/rpcinfo		see rpc Is there any listing registration information in the service
/var/lib/nfs/etab		For viewing nfs Service default configuration information
/proc/mounts			nfs client mount Mount parameters (you can view the default mount parameter information)

3.2 process description of NFS service startup

3.3 NFS configuration file description:

  1. Common configuration and parameter description
[root@xxx ~]# cat /etc/exports
[catalogue] [Client address][jurisdiction]
  • catalogue The directory to be shared uses an absolute path. It needs to belong to the nfsnobody user and pay attention to read and write permissions
  • Client address It can be a separate IP address, host name, domain name, network segment address, * [all]
  • Permission [no space between and address], red permission is recommended
rw		Reading and writing;
ro		Read only;
sync	[default]Write directly to the hard disk;
async	Write to hard disk asynchronously (write to memory buffer first)
all_squash		Compress the permissions of all users to anonymous users[nfsnobody]
no_all_squash	[default]No user permission compression
root_squash	[default]compress root The user's permissions are anonymous[nfsnobody]
no_root_squash No compression root User rights(DANGER,Use less)
anonuid		Anonymous user uid,Default
anongid		Anonymous user gid,Default
 Note: at the end of the article, there are detailed diagrams of the relationship between the above parameters
  1. More configurations [generally no matter]
[root@xxx ~]# cat /var/lib/nfs/etab

You can see that in addition to the parameters we configured in the export file, there are many predefined parameters of the system, such as creating users

3.4 setting of NFS shared file system permission parameters

  1. The NFS server / etc/exports setting requires open writable permissions, that is, the server-side sharing permissions.
  2. The NFS directory permissions that the NFS server actually wants to share have writable permissions w
  3. Each machine corresponds to an nfsnobody user with the same UID 65534 as the NFS default configuration uid (ensure that the access permissions of all clients are uniform, otherwise each machine needs to establish users with the same UID at the same time, and override the default user configuration of NFS)

Only when the above three conditions are met can multiple NFS clients have the permission to view, modify and delete files uploaded by any other NFS client, which is particularly important when it is used as cluster shared storage in a large-scale cluster environment

3.5 frequently asked questions

[root@xxx ~]# showmount -e server_ip
clnt_create: PRC: Program not registered
#There is a problem with the startup sequence of the server
clnt_create: PRC: Port mapper failure - Unable to receive: errno 111(Connetcion refused)
#There is a firewall problem or the service is not started, or the port is not open

3.6 diagram of relationship between parameters

Previous: NFS file store

Posted by rich___ on Tue, 16 Nov 2021 01:53:29 -0800