NFS shared storage service

1, Overview
(1) NFS (Network File System)
NFS is a network file system protocol based on TCP/IP transmission. By using the NFS protocol, clients can access shared resources in remote servers as if they were local directories.
For most load balancing clusters, using NFS protocol to share data storage is a common practice, and NFS is also a protocol that NAS storage devices must support. However, because NFS has no user authentication mechanism and the data is transmitted in clear text on the network, the security is very poor and can only be used in LAN.

The implementation of NFS service depends on RPC (Remote Process Call) mechanism to complete the remote to local mapping process.
Therefore, NFS utils and rpcbind packages need to be installed to provide NFS shared services. The former is used for NFS shared publishing and access, and the latter is used for RPC support

The configuration file for NFS is / etc/exports. The format is shared directory location and client address (permission option)

2, NFS file sharing service setup

Server environment resources

Server: centos7.8 192.168.111.140

client: centos7.8 192.168.111.141

The operation process of the server is as follows:

Log in to 192.168.111.140 and check whether the software package has been installed

rpm -q rpcbind nfs-utils

 

 

As shown in the figure, it means it has been installed.

otherwise

rpm -q rpcbind nfs-utils

-------------------------------

yum -y install nfs-utils rpcbind

Turn off the firewall and selinux on the server

systemctl stop firewalld

---------------------------------------------------
vim /etc/selinux/config ###This requires restarting the server

SELINUX=enforcing

----------------------------------------------------


setenforce 0 ;Temporarily shut down without restarting the server

Set shared directory

mkdir -p /opt/gongxiang


chmod 777 /opt/gongxiang

Modify the shared configuration file / etc/exports. Then reload the file: exports -a

vim /etc/exports

/opt/gongxiang 192.168.111.141/24(rw,sync,no_root_squash)

---------------------------------------------------------

The client address can be a hostname IP Address, network segment address, allowed“*","?"Wildcards.
"rw" Indicates that reading and writing are allowed“ ro" Indicates read-only.
sync : Indicates synchronous writing to memory and hard disk.
no_root_squash : Indicates that when the client root Give local identity when accessing root Permissions (default is root_squash).
root_squash : Represents the client root When a user accesses the shared directory, the root Users are mapped to anonymous users.

Other common options
all_squash : All access users are mapped to anonymous users or user groups.
async : Save the data in the memory buffer first and write it to the disk if necessary.
subtree_check(Default): if the output directory is a subdirectory, then nfs The server will check the permissions of its parent directory.
no_subtree_check : Even if the output directory is a subdirectory, nfs The server also does not check the permissions of its parent directory, which can improve efficiency

 

Restart service

systemctl restart nfs
systemctl restart rpcbind
It can be set to start automatically
systemctl enable rpcbind #It can be directly set to start automatically
systemctl enable nfs

View the shared file directory published locally

exportfs -rv #Publish share
showmount -e

 

The client operation flow is as follows

Log in to 192.168.111.141 to check whether the software package has been installed

rpm -q rpcbind nfs-utils

As shown in the figure, it means it has been installed, otherwise

rpm -q rpcbind nfs-utils

-------------------------------

yum -y install nfs-utils rpcbind

Turn off the firewall and selinux on the server

systemctl stop firewalld

---------------------------------------------------
vim /etc/selinux/config ###This requires restarting the server

SELINUX=enforcing

----------------------------------------------------


setenforce 0 ;Temporarily shut down without restarting the server

View service end work items

showmount -e 192.168.111.140

 

Mount directory

mkdir -p /opt/mygongxiang
mount 192.168.111.140:/opt/gongxiang /opt/mygongxiang

see

 

Set boot auto mount

vim /etc/fatab

 

Test verification

Create a new file ABC on the server / opt/gongxiang Txt, and then confirm whether there is ABC in the / opt/mygongxiang path on the client Txt file

####################The above is for learning reference only. Please do not spray indiscriminately##########################

 

Added by kansaschuck on Thu, 27 Jan 2022 09:37:56 +0200