Mount NFS File System
Get Mount Address
After the mount point is created, the file system can be used. You can query the mount address of the mount target on the page of each file system, as shown in the following figure:
After logging in to the virtual machine or container, use the mount address to operate the file system.
Install NFS Client
Most operating systems do not install the NFS client by default, so you need to manually install the NFS client before mounting the file system.
Log in to the cloud server and run commands to install the NFS client.
- For CentOS/RHEL operating system, please run the following command:
yum install nfs-utils
- For Ubuntu/Debian operating system, please run the following command:
apt-get install nfs-common
The above commands require root authority.
Mount the NFS File System Manually
The following command is recommended to mount the file system (requires root privileges):
mount -t nfs4 -o minorversion=1, rsize=1048576, wsize=1048576, hard, timeo=600, retrans=2, noresvport < Mount address >:/ /< Target directory >
Where
For the explanation of the parameters in the command, see the following table (for more parameters, please refer to NFS document):
Option | Description |
---|---|
minorversion | The minor version number of the mount protocol. Must be 1, and NFS 4.1 protocol is specified. |
rsize | Sets the maximum number of bytes of data that a read request of a client file can receive. Setting the value too small will cause read throughput to decrease. Recommended value: 1048576。 |
wsize | Sets the maximum number of bytes that a write request of a client file can send. Setting the value too small will cause write throughput to decrease. Recommended value: 1048576。 |
hard | The option for retry behavior of the Client, which has two optional values: hard and soft. Use hard by default. With the hard option, the client will retry indefinitely before the server responds. This option can ensure the maximum data integrity. With the soft option, the client gives up after retrying for a period of time and returns an error to the client. If this option is enabled, it is recommended to increase the timeo value to reduce the risk of data corruption. Recommended value: hard。 |
timeo | The amount of time the client waits for a response before retrying an NFS request, in 0.1 sec. The value should not be lower than 150, which is 15 seconds. Recommended value: 600。 |
retrans | The number of retry requests of the client, after which it will attempt further recovery operations. Recommended value: 2。 |
noresvport | Whether to use the privileged port number. There are two optional values: resvport and noresvport. The default is resvport. resvport represents the use of the privileged port number (1-1023), and noresvport represents the use of the privileged port number (>1023). The range of unprivileged port numbers is larger, which can reduce service unavailability caused by port allocation. Recommended value: noresvport。 |
Mount the NFS File System Automatically
File systems manually mounted will lose the mount information after restarting. If you need to mount the file system automatically when the system starts, you can follow the steps below.
Modify /etc/fstab
and add the following (requires root privileges):
< Mount point address >:/ < Target directory > nfs4 minorversion=1, rsize=1048576, wsize=1048576, hard, timeo=600, retrans=2, noresvport,_netdev 0 0
Compared with manual mounting, automatic mounting will have one more parameter _netdev
. This parameter requires the operating system to attempt to mount the file system after the network is ready. If this parameter is not specified, the risk of mount failure will rise.
Unmount the NFS File System
Use the umount
command to unmount the file system:
umount < Target directory >
View the Mounted NFS File System
You can view the mounted file systems using the following command:
cat /proc/mounts
If you need to view the capacity information of the file system, you can use the following command:
df -h