Before you access an Apsara File Storage NAS file system, you must create a NAS file system and mount the file system to an Elastic Compute Service (ECS) instance. This topic describes how to create a Network File System (NFS) file system in the NAS console. This topic also describes how to mount the NFS file system on an ECS instance of CentOS 8.2 in a virtual private cloud (VPC). You can then upload data to or download data from the file system.

Prerequisites

  • The NAS service is activated.

    To activate the NAS service, go to the NAS service page and perform the operations as prompted.

  • An ECS instance of CentOS 8.2 is created in the China (Hangzhou) region. For more information, see Purchase an instance.

Step 1: Create an NFS file system and create a mount target for the file system

  1. Log on to the NAS console.
  2. In the File System Selection Guide section of the Overview page, click Create a Common NAS File System.
  3. On the Create a Common NAS File System page, set the required parameters. The following table describes the parameters. For other parameters, select values based on your business requirements or use the default values.
    Parameter Description
    Region Select China (Hangzhou).
    Zone Select Hangzhou Zone B. Select the zone where the ECS instance resides.
    Protocol Type Select NFS.
    Network Type Select VPC.
    VPC Select the VPC where the ECS instance resides.
    VSwitch Select a vSwitch that resides in the VPC.
  4. Click Buy Now and complete the payment as prompted.

Step 2: Mount the file system

  1. Connect to the ECS instance. For more information, see Guidelines on instance connection.
  2. Run the following command to install an NFS client:
    sudo yum install nfs-utils
  3. Run the following command to set the number of concurrent NFS requests to 128:
    sudo echo "options sunrpc tcp_slot_table_entries=128" >>  /etc/modprobe.d/sunrpc.conf
    sudo echo "options sunrpc tcp_max_slot_table_entries=128" >>  /etc/modprobe.d/sunrpc.conf
  4. Run the following command to mount the file system by using the NFSv3 protocol:
    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
    file-system-id.region.nas.aliyuncs.com:/ /mnt is in the format of <Domain name of the mount target>:<Mount directory of the file system><Path of the mount directory>. Replace the values based on your actual scenarios.
  5. Run the mount -l command to view the mount result.

Step 3: Upload and download data

After you mount a NAS file system on an ECS instance, you can access the file system as a local directory. The following code shows an example:Read and write operations