This topic describes how to create a file system and mount the file system on an Elastic Compute Service (ECS) instance that runs Linux.

Prerequisites

  • An Alibaba Cloud account is created and passes the real-name verification. For more information, see Create an Alibaba Cloud account.
    Note You can use a RAM user to perform fine-grained access control. For more information, see Create a custom policy.
  • Apsara File Storage NAS is activated.

    The first time you log on to the NAS console, follow the instructions on the page to activate NAS.

  • NAS is authorized to access cloud resources.
    1. If you are a first-time user of a General-purpose NAS file system, follow these steps to complete the authorization. On the Overview page, click Authorization Management in the Authorization Management section.
    2. Click Go to authorization next to the Default NAS Authorization section.
    3. Click Authorize to assign the AliyunNASDefaultRole role to NAS.
  • ECS instances are available in the region where you want to create a file system. For more information, see Create an ECS instance.
  • If you want to add a mount target of the VPC type, you must create a VPC in the same region where the linked file system resides. Then, you can attach the ECS instance that hosts the file system to the VPC. For more information, see Create a VPC and VSwitch.

Step 1: Create a file system

  1. Log on to the NAS console.
  2. Choose File System > File System List and click Create File System.
  3. In the General-purpose NAS section, click Pay-as-you-go.
    The topic uses a pay-as-you-go file system as an example. If you want to attach a storage plan, click Purchase Storage Plan. A storage plan is a billing method that is more cost-effective compared to the pay-as-you-go billing method. For more information, see Purchase a storage plan.
  4. On the Buy page, set the following parameters.
    Parameter Description
    Region The region where you want to create the file system.
    Note If an ECS instance and a file system reside in different regions, the ECS instance cannot access the file system.

    You can create a maximum of 20 file systems in a region by using an Alibaba Cloud account.

    Storage types and protocol types that are supported by NAS change based on the region. For more information, see Regions and supported storage types and protocols.

    Zone The zone where the file system resides. Each region has multiple isolated locations known as zones. The power supply and network of each zone are independent. If a file system and an ECS instance reside in the same region but in different zones, they can communicate with each other.

    Select a zone from the drop-down list. We recommend that you select the zone where the ECS instance resides. This eliminates extra latency for cross-zone communication between the file system and the ECS instance.

    Protocol Type The protocol type. Select NFS (including NFSv3 and NFSv4).

    The Network File System (NFS) protocol is applicable to file sharing among Linux ECS instances.

    Storage Type The storage type. Valid values: Performance and Capacity.

    The maximum size of a Performance NAS file system is 1 PB. The maximum size of a Capacity NAS file system is 10 PB. The pay-as-you-go billing method is adopted.

    Encryption Specifies whether to encrypt data. You can use keys that are hosted by Key Management Service (KMS) to encrypt data stored on a file system. Data is automatically decrypted when you access encrypted data. For more information, see Data encryption.
    Network Type The network type. Valid values: VPC and Classic Network.
    This parameter specifies the network type of the mount targets for NAS file systems. You can add a maximum of two mount targets to each file system. For more information about how to add an extra mount target, see Create a mount target.
    Note
    • Mount targets of the classic network type are available only for regions that reside in China.
    • You can add mount targets of the classic network type to file systems. However, you can mount these file systems only on ECS instances.
    VPC The VPC. If no VPC is available, create a VPC in the VPC console.
    Note The VPC that you select must be the same as that of the ECS instance on which you mount a file system. An ECS instance and a file system may reside in different VPCs. To enable communication between the ECS instance and the file system, you can use Cloud Enterprise Network. For more information, see Enable a cross-VPC mount for a file system.
    VSwitch The VSwitch.
  5. Click Buy Now and follow the instructions to complete the payment.
    Note After you create the file system, the default permission group is attached to the file system. For more information about how to change a permission group, see Modify the permission group of a mount target.

Step 2: Install an NFS agent

Before you mount an NFS file system on a Linux ECS instance, you must install an NFS agent.

  1. Log on to the ECS console.
  2. Use the following command to install the NFS agent.
    • If CentOS, RHEL, or Aliyun Linux is running on the ECS instance, use the following command to install the NFS agent.
      sudo yum install nfs-utils
    • If Ubuntu or Debian is running on the ECS instance, use the following commands to install the NFS agent.
      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 3: Mount a file system

  1. Log on to the ECS console.
  2. Mount an NFS file system.

    Use the following command to mount the NFS file system. In the command, replace file-system-id.region.nas.aliyuncs.com:/ /mnt with a value that is specific to your environment.

    • 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 lists the parameters that are used in the mount command.
    Parameter Description
    file-system-id.region.nas.aliyuncs.com:/ /mnt 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 a local directory that resides on the Linux ECS instance. You must replace the example values based on your business requirements.
    • The mount target: The format is file-system-id.region.nas.aliyuncs.com. To obtain information about a mount target, follow these steps: Log on to the NAS console, find the target system, click Management next to the file system to go to the Details page. The Details page shows information about the mount target.
    • The directory of the NAS file system: Specify the root directory (/) or a subdirectory (/share). If a subdirectory is specified, make sure that the subdirectory exists.
    • The local directory 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, make sure that the subdirectory exists.
    vers The version of the file system. Only NFSv3 and NFSv4 are available.
    Mount option

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

    Notice When you set options, 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 mount option and the wsize mount option.
    • If you must modify the timeo mount option, we recommend that you specify a minimum of 150 for the mount option. The timeo mount option 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 mount option. Use caution with the soft mount option.
    • We recommend that you use the default values for other mount options. For example, a decrease in performance may occur due to changes in some mount options. These mount options include the size of the read or write buffer or the use of attribute caching.
    Separate multiple mount options with commas (,). The following table lists the mount options.
    Option Description
    rsize Specifies the maximum number of bytes in each read request that the NFS agent can receive. Recommended value: 1048576.
    wsize Specifies the maximum number of bytes in each write request that the NFS agent 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 mount option.
    timeo Specifies the time in deciseconds (tenths of a second) that the NFS agent waits before it retries an NFS request. Recommended value: 600, indicating 60 seconds.
    retrans Specifies the number of times the NFS agent retries a request. Recommended value: 2.
    noresvport Specifies that the NFS agent uses a different TCP source port for a new network connection to ensure data integrity. We recommend that you use the noresvport mount option.
  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 you fail to mount a file system, troubleshoot the issue. For more information, see Troubleshoot and fix mount issues.