centos7-10-install nfs server

服务器 10.23.241.97
客户端 10.23.241.177

1 Introduction to NFS

(1) What is NFS

NFS is the abbreviation of Network File System. Its biggest function is to allow different machines and different operating systems to share files with each other through the network.

​ The NFS server allows the PC to mount the directory shared by the NFS server on the network to the local file system. From the local system, the remote host's directory is like a disk partition of its own, in use It is quite convenient.

NFS is generally used to store static data such as shared videos and pictures.
(2) NFS mount principle

Insert picture description here
When we set up a shared directory /home/public on the NFS server, other NFS clients that have access to the NFS server can mount this directory to a mount point of their file system. This mount point can Define by yourself, as shown in the figure above, the directories mounted by client A and client B are different.

And after mounting, we can see all the data of the server /home/public locally. If the client configured on the server is read-only, then the client can only be read-only. If you configure read and write, the client can read and write.

After mounting, the NFS client view disk information command: #df -h.

Since NFS uses the network to transmit data between the server and the client, there must be a corresponding network port to transmit data between the two. Which port does the NFS server use for data transmission? Basically, the port of the NFS server is opened at 2049, but the file system is very complicated. Therefore, NFS also has other programs to start additional ports. These additional ports used to transmit data are randomly selected and are less than 1024 ports; since they are random, how does the client know what the NFS server is using? Which port is it? At this time, it needs to be achieved through the remote procedure call (Remote Procedure Call, RPC) protocol!

2 Install nfs service

Need to install nfs server
(1) The first step: install NFS and rpc, each machine needs to be installed .
#yum install -y nfs-utils
#Install nfs service# yum install -y rpcbind#Install rpc service
(2) The second step: start the service and settings to start, each machine is started .
Note: Start the rpc service first, and then start the nfs service.
#systemctl start rpcbind #Start the rpc service first#
systemctl enable rpcbind #Set boot up
#systemctl start nfs-server
#Start nfs service# systemctl enable nfs-server #Set boot up

systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs-server
systemctl enable nfs-server

(3) Step 3: Configure the shared file directory and edit the configuration file :
first create the shared directory, and then edit the configuration in the /etc/exports configuration file.
#mkdir -p /some/path
#vi /etc/exports

/some/path *(no_root_squash,rw,sync,no_subtree_check)

Parameter Description

其中,rw:读/写权限,只读权限的参数为ro;
其中,sync:数据同步写入内存和硬盘,也可以使用async,此时数据会先暂存于内存中,而不立即写入硬盘。
其中,no_root_squash:NFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。

For example, /some/path 10.23.241.0/24(rw) is
as above, the shared directory is /some/path, the allowed clients are 10.23.241.0/24 network users, and the permissions are read and write.
Please note that there is no space between the NFS client address and the permissions .
(4) Reload the NFS service to make the configuration file effective
#systemctl reload nfs#Reload the NFS service to make the configuration file effective

3 Test and use

Verify that the test is available

3.1 Client Mount

(5-1) Client mount
#mount -t nfs 10.23.241.97:/some/path /mnt
(5-2) View the mount status
#df -h View the mount status
Insert picture description here

3.2 View the mounting situation

Insert picture description here

Use the showmount command to view the NFS server sharing information. -e or -exports displays the output list of the NFS server. The output format is "The shared directory name allows the client address to be used".

3.3 Cancel client mount

#umount /mnt or
#umount -l /mnt The
second command with -l is added, which is a mandatory command. You can use
#df -h to view the mounting status when device is busy .

Guess you like

Origin blog.csdn.net/qq_20466211/article/details/113256271