This topic describes how to access a Network File System (NFS) share from a Linux Elastic Compute Service (ECS) instance. This requires a client installed on the ECS instance.

Prerequisites

An NFS share is created. For more information, see Create a share.

Manually mount an NFS share

  1. Log on to the ECS console.
  2. Connect to your Linux ECS instance. For more information, see Connect to an instance.
  3. From the ECS instance, run the following command to mount an NFS share to a local directory of the client:
    • IPv4:
      mount.nfs 192.168.0.0:/shares local-directory
    • IPv6:
      mount.nfs [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares local-directory
    • If you use the NFS version 3 protocol, perform the following steps:
      1. Run the following command to query the mount path, for example, 192.168.0.0:/shares:
        showmount -e <gateway IP address>
      2. Run the following command to mount the share:
        mount -t nfs -o vers=3,proto=tcp,nolock 192.168.0.0:/shares local-directory
    Note
    • You can mount a share over IPv6 only in the China (Hohhot) region. Make sure that the virtual private cloud (VPC) and vSwitch of the gateway support IPv6.
    • If you want to mount a share over IPv6, make sure that an IPv6 address is configured for the client on the ECS instance.
    • If the VPC and vSwitch of an existing gateway support IPv6, you can obtain an IPv6 mount target after you enable IPv6 support for the gateway. By default, the gateways created in this VPC support IPv6.

    Parameters in the preceding commands:

    • 192.168.0.0:/shares: the mount target of the gateway, including the IPv4 address and the share name. Replace this value with the actual values of your mount target. To query the mount target of a gateway, log on to the CSG console and navigate to the Share page of the gateway.
    • [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares: the mount target of the gateway, including the IPv6 address and the share name. Replace this value with the actual values of your mount target. To query the mount target of a gateway, log on to the CSG console and navigate to the Share page of the gateway.
    • local-directory: a local directory of the client. Specify a directory that supports read and write operations. You cannot specify a directory that does not exist.
    • You can optionally specify the noac parameter in the mount command. You can specify this parameter if the express synchronization feature is enabled and the share that you want to mount is added to an express synchronization group. After you specify this parameter, the client obtains the file system metadata from the gateway in real time. This allows you to check the synchronization result on the client at the earliest opportunity. This parameter has an observable impact on the read/write performance on the client. If the client needs to monitor data changes, we recommend that you specify this parameter. If the client requires high write/read performance, we recommend that you do not specify this parameter. The following sample code provides an example of a mount command that includes the noac parameter:
      mount.nfs -o noac 192.168.0.0/shares local-directory
  4. Run the df -h command to check the mount result.

    If the returned result is similar to the following output, the NFS share is mounted to the local directory of the client.

    挂载
    Note After the NFS share is mounted, you can view the capacity of the file system that is managed by the NFS share. Object Storage Service (OSS) provides unlimited storage capacity. For the file system capacity supported for individual gateway specifications, see Specifications.

Access an NFS share

After an NFS share is mounted, you can access the NFS share in the same way that you access a local directory. If you have write permissions on the NFS share, you can write data to the NFS share. If you have read-only permissions on the NFS share, you can only read data from the NFS share.

Note A share of a gateway is synchronized with the OSS bucket associated with the share. When you manage a share, the changes to the share are also applied to the associated OSS bucket.

Enable automatic mounting of an NFS share

If you restart the ECS instance on which an NFS file system is mounted, the mount information about the file system may be lost. To prevent this issue, you can modify the /etc/fstab or /etc/rc.local configuration file on the Linux ECS instance to enable automatic mounting at instance startup. We recommend that you use the /etc/fstab file.

Note Before you enable automatic mounting, make sure that the preceding manual mounting is successful. This prevents startup failures of the ECS instance.
  1. Open the configuration file and add the mount command.
    • Method 1 (recommended): Open the /etc/fstab file and add the mount command.
      Note If you enable automatic mounting in CentOS 6, perform the following steps first:
      1. Run the chkconfig netfs on command to enable the NetFS service to start at system startup.
      2. Open the /etc/netconfig file and comment out inet6-related information.
      • To use NFSv4 to mount the file system, add the following command:
        • To mount the file system over IPv4, run the following command:
          192.168.0.0:/shares local-directory nfs defaults 0 0
        • To mount the file system over IPv6, run the following command:
          [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares local-directory nfs defaults 0 0
      • To use NFSv3 to mount the file system, add the following command:
        • To mount the file system over IPv4, run the following command:
          192.168.0.0:/shares local-directory nfs vers=3.0 defaults 0 0
        • To mount the file system over IPv6, run the following command:
          [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares local-directory nfs vers=3.0 defaults 0 0
    • Method 2: Open the /etc/rc.local file and add the mount command.
      Note Before you configure the rc.local file in the /etc/ directory, make sure that you have execute permissions on the rc.local file in the /etc/ directory and the rc.local file in the /etc/rc.d/ directory. For example, in CentOS 7.x, execute permissions are not granted by default. Before you edit the rc.local file in the /etc/ directory, make sure that you are granted execute permissions.
      • To use NFSv4 to mount the file system, add the following command:
        • To mount the file system over IPv4, run the following command:
          sudo mount.nfs 192.168.0.0:/shares local-directory
        • To mount the file system over IPv6, run the following command:
          sudo mount.nfs [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares local-directory
      • To use NFSv3 to mount the file system, add the following command:
        • To mount the file system over IPv4, run the following command:
          sudo mount -t nfs -o vers=3,proto=tcp,nolock 192.168.0.0:/shares local-directory
        • To mount the file system over IPv6, run the following command:
          sudo mount -t nfs -o vers=3,proto=tcp,nolock [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares local-directory

    Parameters in the preceding commands:

    • 192.168.0.0:/shares: the mount target of the gateway, including the IPv4 address and the share name. Replace this value with the actual values of your mount target. To query the mount target of a gateway, log on to the CSG console and navigate to the Share page of the gateway.
    • [2408:4004:ffff:ffff:ffff:ffff:ffff:ffff]:/shares: the mount target of the gateway, including the IPv6 address and the share name. Replace this value with the actual values of your mount target. To query the mount target of a gateway, log on to the CSG console and navigate to the Share page of the gateway.
    • local-directory: a local directory of the client. Specify a directory that supports read and write operations. You cannot specify a directory that does not exist.
    • You can optionally specify the noac parameter in the mount command. You can specify this parameter if the express synchronization feature is enabled and the share that you want to mount is added to an express synchronization group. After you specify this parameter, the client obtains the file system metadata from the gateway in real time. This allows you to check the synchronization result on the client at the earliest opportunity. This parameter has an observable impact on the read/write performance on the client. If the client needs to monitor data changes, we recommend that you specify this parameter. If the client requires high write/read performance, we recommend that you do not specify this parameter. The following sample code provides an example of a mount command that includes the noac parameter:
      mount.nfs -o noac 192.168.0.0/shares local-directory
  2. Run the reboot command to restart the ECS instance.