Steps to use and configure NFS under centos7

  • 2020-06-15 11:00:22
  • OfStack

NFS stands for Network File System, or network file system. The client mounts the NFS server-side Shared data directory to the local directory.

Why do you need RPC?

Since NFS supports many functions and different programs are used to start different functions, the ports corresponding to NFS's corresponding functions cannot be fixed.

The unfixed port causes a communication barrier between the client and server, so RPC is needed to help.

When NFS starts, it will randomly access a number of ports and then actively register with RPC service to access relevant port and function information. RPC USES fixed port 111 to listen for requests from NFS clients.

The correct NFS service port information is returned to the client so that the client and server can transfer the data.

2. NFS workflow

1. When the program makes a request to access files on the NFS client, the local RPC(rpcbind) service of the client will issue a request for file access function to port 111 of RPC on the NFS server through the network.

2. RPC of NFS server finds the corresponding registered NFS port and notifies the client RPC service.

3. The client obtains the correct port and accesses the data online with NFS daemon.

4. After the data access is successful, return to the front-end access program to complete one access operation.

So whether the client or the server needs to use NFS, the RPC service must be installed.

RPC service of NFS, named portmap under Centos5 and rpcbind under Centos6.

3. NFS service installation configuration

nfs - utils, rpcbind

Check to see if NFS is installed


> rpm -qa nfs-utils rpcbind

> yum install nfs-utils rpcbind 

4. Start rpcbind service

View service status


> systemctl status rpcbind.service 

If you don't know where the rpcbind command is


> which rpcbind 

Start the rpc service


> systemctl restart rpcbind.service 

Check the rpc


> lsof -i :111

> netstat -lntup|grep rpcbind 

If -ES97en does not find the command, execute the following command


> yum install net-tools lsof 

View the port information that the nfs service registered with rpc


> rpcinfo -p localhost 

Check whether rpcbind is booted


> chkconfig --list rpcbind 

5. Start NFS service


> systemctl start nfs.service 

Check the status


> systemctl status nfs.service 

Look again at the port information registered with rpc


> systemctl status rpcbind.service 
0

6. NFS Common processes in detail


> ps -ef|egrep "rpc|nfs" 

rpc   101101   1 0 17:11 ?    00:00:00 /sbin/rpcbind -w

rpcuser 101188   1 0 17:22 ?    00:00:00 /usr/sbin/rpc.statd --no-notify

root   101190   2 0 17:22 ?    00:00:00 [rpciod]

root   101200   1 0 17:22 ?    00:00:00 /usr/sbin/rpc.idmapd

root   101201   1 0 17:22 ?    00:00:00 /usr/sbin/rpc.mountd

root   101206   2 0 17:22 ?    00:00:00 [nfsd4]

root   101207   2 0 17:22 ?    00:00:00 [nfsd4_callbacks]

root   101213   2 0 17:22 ?    00:00:00 [nfsd]

root   101214   2 0 17:22 ?    00:00:00 [nfsd]

root   101215   2 0 17:22 ?    00:00:00 [nfsd]

root   101216   2 0 17:22 ?    00:00:00 [nfsd]

root   101217   2 0 17:22 ?    00:00:00 [nfsd]

root   101218   2 0 17:22 ?    00:00:00 [nfsd]

root   101219   2 0 17:22 ?    00:00:00 [nfsd]

root   101220   2 0 17:22 ?    00:00:00 [nfsd]

root   101243 100830 0 17:28 pts/0  00:00:00 grep -E --color=auto rpc|nfs 

nfsd(ES127en.nfsd) main process, mainly manages whether the client can log in to the server, the logon ID to determine.
mountd(ES132en.mountd) manages the NFS file system, and manages the permissions of the logon users
rpc.lockd (not necessary) is used to lock files for simultaneous writing by clients
(not necessary) check the conformance of document 1
rpc. idmapd name maps the background process

7. Configuration NFS boot up


> systemctl status rpcbind.service 
3

8. NFS server configuration


> systemctl status rpcbind.service 
4

exports file configuration Format:

NFS client address 1(argument 1, argument 2...) Client address 2(argument 1, argument 2...)

Description:

NFS Shared directory:

To use the absolute path, it can be read and written by nfsnobody.

NFS Client Address:


> systemctl status rpcbind.service 
5

Parameters:

ro: The directory is read-only rw: Directories read and write sync: Writes data synchronously to the memory buffer and disk, which is inefficient, but can guarantee the 1 consistency of the data async: Saves data in a memory buffer before writing it to disk if necessary all_squash: Map all ordinary users and groups accessed remotely to anonymous users or user groups (nfsnobody) no_all_squash: Reverse of all_squash (default) root_squash: Map root users and their groups to anonymous users or user groups (default) no_root_squash: Inverts rootsquash anonuid=xxx: Map all remote access users to anonymous users and specify the user as local (UID=xxx) anongid=xxx: Map all remotely accessed user groups to anonymous user group accounts

Such as:


> systemctl status rpcbind.service 
6

Create directories that you want to share


> mkdir -p /data/tmp

> chown nfsnobody.nfsnobody /data/tmp 

Reload the nfs configuration


> exportfs -rv 

View the nfs server mount


> systemctl status rpcbind.service 
9

9. Mount test


> mkdir -p /data/tmp2

> mount -t nfs 192.168.1.233:/data/tmp /data/tmp2 

Check the mount


> df -h 

Create the file under tmp


> touch /data/tmp/1.txt 

Check to see if there are files under tmp2


> ls /data/tmp2 

Uninstall the mount


> umount /data/tmp2 

Related articles: