Linux NFS File Sharing | Configuration Process | Super Detailed

➤NFS overview

NFS is a network file system protocol based on TCP/IP transmission. By using the NFS protocol, the client can access the shared resources in the remote server as if it were accessing a local directory.

➤1. Advantages and disadvantages of NFS

For most load balancing clusters, it is a common practice to use the NFS protocol to share data storage. NFS is also a protocol that NAS storage devices must support. However, because NFS does not have a user authentication mechanism, and the data is transmitted in plain text on the network, the security is very poor, and it can generally only be used in a local area network.

➤2, NFS service realizes the required conditions

The realization of the NFS service relies on the RPC (Remote Process Call) mechanism to complete the remote to local mapping process.
Therefore, it is necessary to install the nfs-utils and rpcbind software packages to provide NFS sharing services. The former is used for NFS sharing publishing and access, and the latter is used for RPC support.

➤NFS service configuration

The NFS configuration file is /etc/exports (configured on the server side). The
format is:
shared directory location client address (privilege option)
example /test888 192.168.78.0/24(rw,sync,no_root_squash) #share the /text888 directory To all users on the 192.168.78.0 network segment

➤The server uses NFS to publish shared resources

➤1. Install nfs-utils, rpcbind packages

rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
Insert picture description here

➤2. Set the shared directory: vim /etc/exports

mkdir /text888 #Create shared directory
chmod 777 /text888 #Modify shared directory permissions
vim /etc/exports
/text888 192.168.184.0/24(rw,sync,no_root_squash)
Insert picture description here

The client address can be a host name, IP address, or network segment address, and wildcards "*" and "?" are allowed.
"Rw" means read and write allowed, and "ro" means read only.
sync: Means synchronous writing to the memory and hard disk.
no_root_squash: Indicates that the local root authority is granted when the client is accessed as root (the default is root_squash).
root_squash: means that when the client uses the root user to access the shared directory, the root user is mapped to an anonymous user.

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 then write it to disk when necessary.
subtree_check (default): If the output directory is a subdirectory, the nfs server will check the permissions of its parent directory.
no_subtree_check: Even if the output directory is a subdirectory, the nfs server does not check the permissions of its parent directory, which can improve efficiency.

➤3. Start the NFS service program

When manually loading the NFS sharing service, you should start rpcbind first, and then start nfs

systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs

Insert picture description here

➤View the NFS shared directory published by the machine

exportfs -rv #Release share
showmount -e
Insert picture description here

➤Access NFS shared resources in the client

➤1. Install nfs-utils, rpcbind packages

rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind
Insert picture description here

➤2. Check which directories are shared on the NFS server

showmount -e 192.168.78.22 Insert picture description here
mkdir /text777 #Client creates a mount directory
mount 192.168.78.22:/test888 /text777 Mount directory
df -Th #Confirm the mount result Insert picture description here
Test whether it is accompanied by: the
client creates a file
Insert picture description here

Server checks created files
Insert picture description here

Set up automatic mounting

vim /etc/fstab

192.168.80.10:/opt/wwwroot /myshare nfs defaults,_netdev 0 0

_netdev: Indicates that the mounting device requires a network
Insert picture description here

Note: Forcibly uninstalling NFS.
If the server-side NFS service suddenly stops while the client is being mounted and used, the client will be stuck when executing the df -h command. At this time, you cannot uninstall directly by using the umount command directly. You need to add the -lf option to uninstall.
umount -lf /text777

Guess you like

Origin blog.csdn.net/Dark_Tk/article/details/114100517
Recommended