This topic describes how to install a Network File System (NFS) client in Linux and use the mount command to mount an NFS file system.

Prerequisites

Step 1: Install an NFS client

You must install an NFS client in Linux before mounting an NFS file system on an Elastic Compute Service (ECS) instance.

  1. Log on to the ECS console.
  2. Use the following command to install the NFS client.
    • If CentOS, RHEL, or Aliyun Linux is running on the ECS instance, use the following command to install the NFS client.
      sudo yum install nfs-utils
    • If Ubuntu or Debian is running on the ECS instance, use the following commands to install the NFS client.
      sudo apt-get update
      sudo apt-get install nfs-common
  3. Set the maximum number of concurrent NFS requests to 128. For more information, see How can I modify the maximum number of concurrent NFS requests?.

Step 2: Mount an NFS file system

You can use the domain name of the file system or the domain name of the mount target to mount the NFS file system on an ECS instance. The domain name of the file system is resolved to the IP address of the mount target in the zone where the ECS instance resides in a zone.

  1. Log on to the ECS console.
  2. Mount the NFS file system.
    • To mount an NFSv4 file system, use the following command.
      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                                

      If you fail to mount the file system, use the following command.

      sudo mount -t nfs4 -o rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport file-system-id.region.nas.aliyuncs.com:/ /mnt                               
    • To mount an NFSv3 file system, use the following command.
      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

    The following table describes the parameters used in the mounting command.

    Parameter Description
    file-system-id.region.nas.aliyuncs.com:/ /mnt file-system-id.region.nas.aliyuncs.com specifies the mount target of the NAS file system, the forward slash (/) following the mount target specifies the root directory of the NAS file system, and /mnt specifies the local mount point that resides on a Linux ECS instance. You need to replace these example parameters based on your business requirements.
    • The mount target: You can log on to the NAS console, find the target file system, and click Manage to go to the Details page. Then, you can obtain the mount target of the file system.
    • The directory of the NAS file system: Specify the root directory (/) or a subdirectory (/share). If a subdirectory is specified, you must ensure that the subdirectory exists.
    • The local mount point on which you want to mount a file system: Specify the root directory (/) or a subdirectory (/mnt) of a system such as Linux. If a subdirectory is specified, you must ensure that the subdirectory exists.
    vers The version of the file system.

    NFSv3 and NFSv4 are applicable.

    Mount options

    Multiple mount options are available when you mount a file system. For more information, see the following table.

    Notice When you set parameters, take note of the following items.
    • To avoid a decrease in performance, we recommend that you specify the maximum value (1048576) for both the rsize parameter and the wsize parameter.
    • If you need to modify the timeo parameter, we recommend that you specify a minimum of 150 for the parameter. The timeo parameter is measured in deciseconds (tenths of a second). For example, a value of 150 indicates 15 seconds.
    • To avoid data inconsistency, we recommend that you do not use the soft parameter. Use caution with the soft parameter.
    • We recommend that you use the default values for other mount parameters. For example, a decrease in performance may occur due to changes in some mount parameters. These mount parameters include the size of the read or write buffer or the use of attribute caching.
    Separate multiple mount parameters with commas (,). The following table describes the mount parameters.
    Parameter Description
    rsize Specifies the maximum number of bytes in each read request that the NFS client can receive. Recommended value: 1048576
    wsize Specifies the maximum number of bytes in each write request that the NFS client can send. Recommended value: 1048576
    hard Specifies that applications must stop accessing a file system when the file system is unavailable, and wait until the file system is available. We recommended that you use the hard parameter.
    timeo Specifies the time in deciseconds that the NFS client waits before it retries an NFS request. Recommended value: 60 seconds
    retrans Specifies the number of times the NFS client retries a request. Recommended value: 2
    noresvport Specifies that the NFS client uses a different TCP source port for a new network connection to ensure data integrity. We recommend that you use the noresvport parameter.
  3. Use the mount -l command to view the mount result.

    The following figure shows an example of a successful mount.

    View the mount result

    After a file system is mounted, you can use the df -h command to view the size of the file system.

  4. After you mount an NAS file system on an ECS instance, you can access the file system from the ECS instance.

    You can access the file system in the same way you access a local directory. The following figure shows an example.

    Read and write operations

Troubleshoot common errors

If a mount operation fails, you can troubleshoot the issue. For more information, see Troubleshoot and fix mount issues.