“This is the first day of my participation in the August More Text Challenge. For details, see: August More Text Challenge.”
Linux server
The installation
-
Centos7 comes with rpcbind, so simply run yum -y install nfs-utils
Yum -y install nfs-utils rpcbind and install NFS + RPC.
-
Verify that the installation is successful
rpm -qa nfs-utils
-
View the NFS version supported by the NFS service
cat /proc/fs/nfsd/versions
configuration
-
Create a shared directory /data/share(directory can be customized) and set permissions
mkdir /data/share chmod -R 777 /data/share Copy the code
-
Configure and edit the default NFS configuration file /etc/exports
// All IP addresses in the fixed network segment can be mounted echo "/ data/NFS 172.18.30. * (rw, sync, no_root_squash)" >> /etc/exports // Fixed network segment Fixed IP address ranges can be mounted echo "/ data/NFS 172.18.30.0/24 (rw, sync, no_root_squash)" >> /etc/exports // All clients can be mounted echo "/data/nfs *(rw,sync,no_root_squash)" >> /etc/exports Copy the code
Description of permission configuration:
- Rw: read/write
- Ro: read-only. Whether the file system can be read and written depends on the RWX of the file system and its identity
- No_root_squash: If an NFS client accesses the client as a root administrator, the client is mapped as the root administrator of the NFS server
- Root_squash: If the NFS client accesses the client as the root administrator, the client is mapped as the nobody user of the NFS server
- All_squash: The user that logs in to NFS is mapped as an anonymous user, usually nobody(NFsnobody).
- Insecure: Unauthorized access from the client is allowed
- Sync: Data is synchronized to the memory and hard disk
- Async: Data is temporarily stored in memory instead of being written directly to hard drive
- Anonuid: Specifies the value of the UID, which must exist in /etc/passwd
- Anongid: Specifies the gid value
-
To make the NFS configuration take effect exportfs -r
The parameters of exportfs are described as follows:
- -a: mount or unmount everything in /etc/exports
- -r: Reexport all directories: Export all directories again
- -u: umount directory
- -v: verbose displays details
-
View the NFS shared directory and its status
exportfs -v
-
Check whether the shared directory is set successfully
showmount -e
Start & Check
- Starting the RPC Service
/ / start the RPC systemctl start rpcbind // Set boot systemctl enable rpcbind Copy the code
- Starting the NFS Service
// Start NFS systemctl start NFS // Set systemctl to start NFS upon startupCopy the code
rpcinfo -p
If the list of ports (port: 111) registered with the RPC server is displayed, the startup is successful.
Windows & Linux client
NFS
Linux
You do not need to start the NFS service on the client to use the showmount/mount tool
- NFS
yum -y install nfs-utils
- Detecting THE RPC Service
rpcinfo -p
- View the directories that can be mounted on the server
showmount -e 129.xxx.xx.139
Windows
For details, see Setting the data for Mounting an NFS Share on a Linux Server in Windows 7
Mount the directory
Linux
- Mount the server directory to the local directory
mount -t nfs 129.xxx.xx.139:/data/share /data/share
- Validation: on the server side
/data/share
After creating a file in the directory, go to the directory mounted on the client to check whether the file is synchronized- use
df -hT
You can view the usage of file system disks on the Linux operating system
- use
Automatically mount
After the client starts, the NFS file system can be automatically loaded:
The mount command: for example: the mount -t NFS 192.168.3.172: / data/share/data/share written to the/etc/rc. The local
Note: When the /etc/fstab OS starts, it is recommended to load the file system first and then start the network. If the network is not available, NFS cannot be loaded and errors always occur. Therefore, it is recommended to put the file system in /etc/rc.local
Windows7
-
mount \\file-system-nas.com\data\share y:
For details, see Setting the data for Mounting an NFS Share on a Linux Server in Windows 7
Automatically mount
For details, see Automatically Mounting an NFS File System in Windows
Q&A
RPC: Port mapper failure
Error message: RPC: port mapping failed. Since the problem is the port, allow the port. View the running RPC port about NFS. Rpcinfo -p;
// Release port on the firewall
firewall-cmd --zone=public --add-port=111/tcp --permanent
firewall-cmd --zone=public --add-port=20048/tcp --permanent
firewall-cmd --zone=public --add-port=111/udp --permanent
firewall-cmd --zone=public --add-port=20048/udp --permanent
// Restart the firewall
firewall-cmd --reload
// Check the firewall public ports
firewall-cmd --zone=public --list-ports
Copy the code
NET HELPMSG 53
The NFS server has an option to work in insecure mode (allowing higher incoming port numbers). Windows NFS clients usually use a higher port number. You can enable the option insecure by adding an option to the share
Example: /share *(insecure,rw)
Other commands
Viewing the NFS service version on the client:
nfsstat -c
On the server, view the NFS version
nfsstat -s
Check the local centos version:
cat /etc/redhat-release
Deleting an NFS Share
Just uninstall the command,umount
Use the following
Mount Mounts additional parameters
Run the man NFS command to view the help document. The mount parameter names vary with NFS versions. Example: The mount -t NFS -o vers = 4.1, proto = TCP, timeo = 60 129.204.4.139: / data/share/data/share
Refer to the reading
Start and stop the NFS server
Common NFS mount options
Configuring an NFS Server