This topic describes how to mount a Network File System (NFS) file system on a Linux Elastic Compute Service (ECS) instance. If an NFS client is installed on a Linux ECS instance, you can manually or automatically mount the NFS file system.
Configure a Linux ECS instance
If want to mount an NFS file system on an ECS instance that runs Linux, you must configure the Linux ECS instance. If you configure a Linux ECS instance once, you no longer need to configure the Linux ECS instance the next time you mount a file system.
- Connect to the ECS instance. For more information, see Connection methods.
- Install an NFS client.
- If CentOS, Red Hat Enterprise Linux (RHEL), or Alibaba Cloud Linux is running on the
ECS instance, run the following command to install the NFS client:
sudo yum install nfs-utils
- If Ubuntu or Debian is running on the ECS instance, run the following commands to
install the NFS client:
sudo apt-get update
sudo apt-get install nfs-common
- If CentOS, Red Hat Enterprise Linux (RHEL), or Alibaba Cloud Linux is running on the
ECS instance, run the following command to install the NFS client:
- Increase the number of concurrent NFS requests. Run the following command to set the maximum number of concurrent NFS requests to 128. For more information, see How do I increase the maximum number of concurrent NFS requests?
if (lsmod | grep sunrpc); then (modinfo sunrpc | grep tcp_max_slot_table_entries) && sysctl -w sunrpc.tcp_max_slot_table_entries=128 (modinfo sunrpc | grep tcp_slot_table_entries) && sysctl -w sunrpc.tcp_slot_table_entries=128 fi (modinfo sunrpc | grep tcp_max_slot_table_entries) && echo "options sunrpc tcp_max_slot_table_entries=128" >> /etc/modprobe.d/alinas.conf (modinfo sunrpc | grep tcp_slot_table_entries) && echo "options sunrpc tcp_slot_table_entries=128" >> /etc/modprobe.d/alinas.conf
Manually mount the NFS file system
You can use the mount target of an NFS file system to mount the file system on a Linux ECS instance.
- Mount the NFS file system.
- If you want to mount a Capacity Apsara File Storage NAS file system or Performance
NAS file system, you can run one of the following commands:
Note
- To ensure optimal performance, we recommend that you mount a file system by using NFSv3.
- If your application runs based on file locks and you want to modify a file on multiple Linux ECS instances at the same time, use NFSv4 to mount a file system.
Run the following command to use NFSv3 to mount the file system:sudo mount -t nfs -o vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport file-system-id.region.nas.aliyuncs.com:/ /mnt
Run the following command to use NFSv4 to mount the file system:sudo mount -t nfs -o vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport file-system-id.region.nas.aliyuncs.com:/ /mnt
- To mount an Extreme NAS file system, run the following command:
sudo mount -t nfs -o vers=3,nolock,noacl,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport file-system-id.region.extreme.nas.aliyuncs.com:/share /mnt
The following table describes the parameters that you can configure in the mount command.Parameter Description Capacity NAS file systems or Performance NAS file systems: file-system-id.region.nas.aliyuncs.com:/ /mnt Extreme NAS: file-system-id.region.extreme.nas.aliyuncs.com:/share /mnt
<Domain name of a mount target>:<Name of a shared directory> <Path of a mount directory>. Replace the domain name of a mount target, the name of a shared directory, and the path of a mount directory based on your business requirements. - Domain name of a mount target: To view the domain name, perform the following steps: Log on to the NAS console. In the left-side navigation pane, click File System List. On the page that appears, find the file system that you want to manage and click Manage in the Actions column. On the page that appears, click Mount Targets. On the tab that appears, view the domain name of the mount target. For more information, see Manage mount targets.
- Name of a shared directory: specifies the root directory / or a subdirectory. If you specify a subdirectory such as /share, make sure that the subdirectory exists.
Note The shared directory of an Extreme NAS file system must start with /share. Example: /share and /share/subdir.
- Path of a mount directory: specifies the root directory / or a subdirectory such as /mnt of a Linux ECS instance. If the mount directory is a subdirectory, make sure that the subdirectory exists.
vers The protocol version of the file system. - vers=3: uses NFSv3 to mount the file system.
- vers=4: uses NFSv4 to mount the file system.
minorversion
specifies the minor version number of the protocol. NAS file systems supports NFSv4.0. If you use NFSv4 to mount a NAS file system, you must specify 0 as the minor version number for this parameter.
Note- Capacity NAS file systems and Performance NAS file systems support NFSv3 and NFSv4.
- Extreme NAS file systems support only NFSv3.
Mount options When you mount a file system, you can specify multiple mount options. Separate multiple mount options with commas (,). The following mount options are available:
- rsize: specifies the size of data blocks that the client reads from the file system. Recommended value: 1048576.
- wsize: specifies the size of data blocks that the client writes to the file system. Recommended
value: 1048576.
Note To prevent performance degradation, we recommend that you specify the maximum value (1048576) for both the rsize mount option and the wsize mount option.
- hard: specifies that applications stop accessing a file system when the file system is unavailable, and wait until the file system is available. We recommend that you use the hard mount option.
- timeo: specifies the period in deciseconds (tenths of a second) for which the NFS client
waits before the NFS client retries to send a request. Recommended value: 600 (60
seconds).
Note If you want to modify the timeo mount option, we recommend that you specify 150 or a greater value. The timeo mount option is measured in deciseconds (tenths of a second). For example, the value 150 indicates 15 seconds.
- retrans: specifies the number of times that the NFS client retries to send a request. Recommended value: 2.
- noresvport: specifies that a new TCP port is used to ensure network continuity between the file system and the ECS instance when the network recovers from a failure. We recommend that you use the noresvport mount option.
Notice- To prevent data inconsistency, we recommend that you do not use the soft mount option. Use of the soft mount option is at your own risk.
- We recommend that you use the default values for other mount options. Performance degradation may occur due to changes in several mount options. These mount options include the size of the read or write buffer or the use of attribute caching.
- If you want to mount a Capacity Apsara File Storage NAS file system or Performance
NAS file system, you can run one of the following commands:
- Run the
mount -l
command to view the mount result.If the command output that is similar to the following information appears, the mount is successful.After the file system is mounted, you can run the
df -h
command to view the storage capacity of the file system.If the file system failed to be mounted, troubleshoot the issue. For more information, see Fix mount issues.
- After the NAS file system is mounted, you can read data from and write data to the
NAS file system on the Linux ECS instance. You can access the file system the same way you access a local directory. The following figure shows an example.
Automatically mount the NFS file system
When you restart the ECS instance on which a file system is mounted, the mount information about the file system may be lost. To prevent the loss of the information, you can modify the /etc/fstab configuration file on the Linux ECS instance to enable automatic mounting at startup for an NFS file system.
- To mount an Extreme NAS file system, run the following command: To mount a Capacity NAS file system or Performance NAS file system, skip this step and go to Step 2.
Open the /etc/systemd/system/sockets.target.wants/rpcbind.socket configuration file, and comment out the rpcbind parameters that are related to IPv6, as shown in the following figure. Otherwise, the rpcbind service fails to run at startup.vi /etc/systemd/system/sockets.target.wants/rpcbind.socket
If you want to enable automatic mounting for CentOS 6.x, perform the following steps:- Run the
chkconfg netfs on
command to enable the netfs service at startup. - Open the /etc/netconfig configuration file, and comment out inet6-related information.
- Run the
- Open the /etc/fstab configuration file.
- If you want to mount a Capacity or Performance NAS file system, run one of the following
commands:
- Run the following command to use the NFSv3 protocol to mount the file system:
file-system-id.region.nas.aliyuncs.com:/ /mnt nfs vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0
- Run the following command to use the NFSv4 protocol to mount the file system:
file-system-id.region.nas.aliyuncs.com:/ /mnt nfs vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0
- Run the following command to use the NFSv3 protocol to mount the file system:
- If you want to mount an Extreme NAS file system, run the following command:
file-system-id.region.extreme.nas.aliyuncs.com:/share /mnt nfs vers=3,nolock,noacl,proto=tcp,noresvport,_netdev 0 0
Note- If you want to enable automatic mounting for CentOS 6.x, run the
chkconfg netfs on
command to enable the netfs service at startup. - If you want to enable automatic mounting for Ubuntu, run the following command:
Append[ ! -f /etc/rc.local ] && echo '#!/bin/bash' > /etc/rc.local; echo "mount -a -t nfs" >> /etc/rc.local; chmod +x /etc/rc.local
,x-systemd.automount
to the end of thenoresvport
mount option and do not change "0 0" in the command. - If you want to enable automatic mounting for Alibaba Cloud Linux, run the following
command:
Append[ ! -f /etc/rc.local ] && echo '#!/bin/bash' > /etc/rc.local; echo "mount -a -t nfs" >> /etc/rc.local; chmod +x /etc/rc.local
,x-systemd.automount,x-systemd.requires=systemd-resolved.service,x-systemd.after=systemd-resolved.service
to the end of thenoresvport
mount option and do not change "0 0" in the command.
For more information, see Mount parameters. The following table describes other mount options that are used in the preceding examples.Mount option Description _netdev Prevents automatic mounting before the network is connected. 0 (the first value after noresvport) Indicates whether to back up the file system by running the dump command. A non-zero value indicates that a file system is backed up. The default value for NAS file systems is 0. 0 (the second value after noresvport) Indicates the order in which the fsck command checks file systems at startup. The default value for NAS file system is 0. The default value 0 indicates that the fsck command is not run at startup. - If you want to mount a Capacity or Performance NAS file system, run one of the following
commands:
- Run the
reboot
command to restart the ECS instance.Note Before you restart the ECS instance, make sure that the manual mounting is successful. Otherwise, the ECS instance may fail to restart. If automatic mounting is enabled, you can run thedf -h
command to view the mounted NAS file systems after the ECS instance is restarted.