Batch mount an NFS file system on multiple ECS instances

Updated at:

If you need multiple ECS instances to share data from the same NFS file system, you can use Cloud Assistant to mount the file system on the instances in a batch operation.

Prerequisites

You have created a file system. For more information, see Create a file system.

Network requirements

You can use the console to perform a batch mount on multiple instances if your network environment meets any of the following requirements:

  • The ECS instances and the NAS mount target are in the same VPC.

  • The ECS instances and the NAS mount target are in the same classic network, and you have granted the instances access through the mount target's permission group. For more information, see Manage permission groups.

  • The VPCs of the ECS instances and the NAS mount target are connected, and you have granted the instances access through the mount target's permission group. For more information, see Mount a NAS file system across VPCs in the same region by using CEN.

Limits

  • Operating system

    You can mount the file system only on a Linux ECS instance. Linux distributions such as CoreOS, FreeBSD, and Fedora CoreOS do not support the mount feature of the NAS console. If your ECS instance runs Red Hat Enterprise Linux (RHEL), you must install the Cloud Assistant client by using the RPM Package Manager (RPM) package before you mount your file system. For more information, see Install the Cloud Assistant agent.

  • Instance and tool status

    • ECS instances must be in the Running state. If an instance is Starting or Stopped, change its state to Running before you proceed.

    • The Cloud Assistant Agent must be running and in a healthy state.

  • ECS limits

    The ECS instances and the NAS file system must be in the same region. Cloud Assistant does not support cross-region mount operations.

  • File system

    This feature supports only NFS file systems.

Procedure

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Maintenance & Monitoring > Cloud Assistant.

  3. In the upper-left corner of the page, select a region and resource group.

  4. On the Common Commands tab, search for the ACS-NAS-ClickMount-Mount-Linux-NFS-v2.sh command and click Run.

  5. In the Run Command panel, configure the parameters and select the target ECS instances.

    Parameter

    Description

    Command content

    Click View command content to review the command content.

    Execution plan

    Select a schedule to run the command.

    • Run Immediately: The command is run immediately.

    • After the next startup of the system: The instance runs the command the next time it starts.

    • After each system startup: The instance runs the command every time it starts.

    • Dry Run Only: The system checks the request but does not run the command. This option checks the request parameters, instance execution environment, and Cloud Assistant Agent status.

    • Run on Schedule: Runs the command at a specified time or on a schedule.

      • Run at Fixed Interval: Runs the command at a specified interval (in seconds, minutes, hours, or days). This method is ideal for tasks that must run at a fixed frequency.

        Note

        The following limits apply to fixed-interval execution:

        • The interval must be between 60 seconds and 7 days, and must be longer than the timeout period of the scheduled task.

        • The execution interval is based only on the fixed frequency and is not affected by the actual time required for a task to complete. For example, if you set the command to run every 5 minutes and a task takes 2 minutes to complete, the next task will start 3 minutes after the previous one finishes.

        • The task does not run immediately upon creation. For example, a task set to run every 5 minutes will first execute 5 minutes after you create it.

      • Run Only Once at Specified Time: The command is run once at the specified time and in the specified time zone.

        For example, if you set Execution Time to 2022-05-17 17:30:50 and Time Zone to (GMT+8:00) Asia/Shanghai, the command is run at 17:30:50 on May 17, 2022 (China Standard Time).

      • Run on Clock-based Schedule: Runs the command based on a Cron expression. You can define the repetition frequency with precision up to seconds, minutes, hours, days of the month, months, days of the week, and years. In the specified time zone, the system calculates the execution time based on the Cron expression and runs the task. This flexible option is ideal for complex scheduled tasks. For more information, see Cron expressions.

        Note

        The minimum interval must be greater than or equal to the timeout period of the scheduled task and no less than 10 seconds.

        For example, if you set Repeat Frequency to 0 0 12 ? * WED 2022 and Time Zone to (GMT+8:00) Asia/Shanghai, the system runs the command at 12:00 PM every Wednesday in 2022 (China Standard Time).

    Execution Path

    The path where the command is run.

    Username

    The name of the user that is used to run the command on the ECS instance.

    Running commands with the least privilege is a security best practice. We recommend that you run Cloud Assistant commands as a regular user. For more information, see Run Cloud Assistant commands as a regular user.

    By default, commands are run as the root user on Linux instances and as the System user on Windows instances.

    Timeout

    Specify the Timeout for a command to run on an instance. If the command execution task times out, Cloud Assistant forcibly terminates the task process.

    Unit: seconds. The default value is inherited from the command's original Timeout setting.

    Note

    This value applies only to the current command execution and does not change the timeout setting of the command itself.

    Tags

    Applies a tag key and tag value to the command execution for easier filtering and management.

    Task Stop Scope

    Defines what to stop when an execution is manually stopped or times out.

    • Command Process: Stops the script process when the task is stopped.

    • Command Process Tree: Stops the process tree, which includes the script process and all its child processes, when the task is stopped.

    Launcher

    The launcher that is used to run the script.

    Command parameters

    In the Command Parameter text box, enter the value for the command's custom parameter.

    • MountTargetDomain: The domain name of the file system mount target.

      Find this domain name in the mount target list for the file system in the NAS console. Example: ****.nas.aliyuncs.com. For more information, see Manage mount targets.

    • EcsLocalPath: The local path on the ECS instance for the mount.

      Must be an absolute path that starts with / (for example, /mnt) and an empty directory.

    • NasRemotePath: The directory on the NAS file system to mount.

      You can configure it as the NAS root directory (/) or any subdirectory (for example, /abc).

    • ProtocolType: The protocol type of the file system.

      • General-purpose NAS: NFSv3 and NFSv4.0

      • Extreme NAS: NFSv3

      Important

      Make sure that you enter the correct parameter value. The value is case-sensitive and cannot have leading or trailing spaces. An invalid parameter value will cause the command to fail.

    • AutoMountOnBoot: Specifies whether to enable auto-mount on boot for the file system.

      Valid values: true or false. When auto-mount on boot is enabled, you do not need to repeat the mount operation when you restart the ECS instance.

      Important

      Make sure that you enter the correct parameter value. The value must be in lowercase and cannot have leading or trailing spaces. An invalid parameter value will cause the command to fail.

    • MountParam: The mount parameters.

      Leave this empty unless you have specific mount requirements. For information about the parameters, see Mount an NFS file system.

    Select instances

    Select one or more destination ECS instances.

    If you have a large number of instances, you can enter an instance ID, instance name, or tag in the search box to search for instances. You can also filter instances by Cloud Assistant Agent status.

  6. Click Run.

View command execution results

After running a mount, unmount, or query command, you can use Cloud Assistant to view the batch execution results.

  1. Log on to the ECS console.

  2. In the left-side navigation pane, choose Maintenance & Monitoring > Cloud Assistant.

  3. In the upper-left corner of the page, select a region and resource group.

  4. On the Command Execution Results tab, select Command Name from the drop-down list in the search box, enter the name of the command that you want to query, and then click the 查询图标 icon.

    • Mount: ACS-NAS-ClickMount-Mount-Linux-NFS-v2.sh

    • Unmount: ACS-NAS-ClickMount-Unmount-Linux-NFS.sh

    • Query: ACS-NAS-ClickMount-Check-Linux-NFS.sh

  5. In the command execution result list, find the destination command and click View in the Operation column.

  6. In the command execution details panel, click the Instances tab. Then, click the 批量图标001 icon that corresponds to the destination instance to view the command output.

    If the command output contains an error, identify and fix the root cause and then run the command again. For more information about error codes, see Error messages.

  7. After you view the result, click Close.

Error messages

The following table describes the error codes that may appear in the command output.

ErrorCode

ErrorMsg

SystemNoPermission

Insufficient permissions on the operating system. Root permissions are required.

SystemMissingMounts

The operating system is missing the mount information file /proc/self/mounts.

SystemMissingFstab

The operating system is missing the automatic mount configuration file /etc/fstab.

SystemBashOutdated

The Bash version of the operating system is outdated. Upgrade to Bash 4.0 or later.

BadInputMountTarget

The mount target parameter is invalid. Use a mount target that ends with .nas.aliyuncs.com.

BadInputLocalPath

The specified mount path parameter is invalid. Use a Linux absolute path that starts with /.

BadInputRemotePath

The entered NAS directory parameter is invalid. Please use an absolute path that starts with /.

BadInputProtocol

The specified protocol type parameter is invalid. Please use NFSv3 or NFSv4.0.

BadInputAutoMount

The entered auto-mount parameter is invalid. Please use true or false.

BadInputForceUnmount

The value of the force unmount parameter is incorrect. Please use true or false.

NasClientNfsInstallFail

Failed to install the NFS client. Manually install it.

LocalPathCreateFail

Failed to create the mount path. Manually create it.

LocalPathAlreadyMounted

The local path is already a mount point for another NAS mount target. Select a different path.

LocalPathNonEmpty

The directory specified by the local path is not empty. Select a different path.

LocalPathNotOnMountTarget

The local path is not mounted to this NAS mount target. Initiate the operation from the correct NAS mount target.

LocalPathMultipleMounts

The local path is mounted multiple times. Check the path and then perform a force unmount.

LocalPathAncestorMounted

The parent directory of the local path is already a mount point. Select a different path.

LocalPathNonExistent

The local path does not exist. Select a different path.

RemotePathCreateFail

Failed to create the NAS subdirectory. Mount the NAS root directory.

MountFailRemoteRoot

Failed to mount the NAS root directory. For troubleshooting information, see Troubleshoot file system mount failures.

MountFailRemotePath

Failed to mount the NAS subdirectory. Mount the NAS root directory.

UnmountFailRemoteRoot

Failed to unmount the NAS root directory before you mount a NAS subdirectory. Mount the NAS root directory.

UnmountFailLocalPath

Failed to unmount the NAS file system. Stop related applications and then perform a force unmount.

UnmountFailRemoveAutoMount

Failed to remove the NAS auto-mount configuration.

Related operations

You can also use Cloud Assistant to run commands that perform batch queries or unmount file systems.

Actions

Command

Description

Batch unmount

ACS-NAS-ClickMount-Unmount-Linux-NFS.sh

To create a batch unmount task, run a command by using Cloud Assistant and replace the command in Step 5 with the unmount command.

When you run the unmount command, configure the following parameters:

  • mounttargetdomain: The domain name of the file system mount target.

    You can view the domain name of the mount target in the mount target list of the destination file system in the NAS console. Example: ****.nas.aliyuncs.com. For more information, see Manage mount targets.

  • ecslocalpath: The local path on the server where the NAS file system is mounted.

    In the NAS console, find the mount target list of the destination file system and click Mount. In the Actions column of the destination ECS instance, click Query Mount Details to view the mount path.

  • cancelautomountonboot: Specifies whether to cancel auto-mount on boot. Valid values: true and false.

    When set to true, the /etc/fstab file in the ECS instance is modified.

  • forceunmount: Specifies whether to perform a force unmount. Valid values: true and false.

    A force unmount executes the umount -lf <mount_path> command. This operation may cause the loss of unwritten data and make related applications exit unexpectedly. We recommend that you first run the fuser -mv <mount_path> command on the ECS instance to check for processes that are using the mount path. You can use the force unmount feature only after you confirm that no applications are using the file system and that the file system cannot be unmounted by using normal methods. For more information about the risks of a force unmount, see What are the risks of a force unmount of a NAS file system?

Batch query

ACS-NAS-ClickMount-Check-Linux-NFS.sh

To create a batch query task, run a command by using Cloud Assistant and replace the command in Step 5 with the query command.

When you run the query command, configure the following parameter:

mounttargetdomain: The domain name of the mount target. If you leave this parameter empty, the command queries all NAS file systems mounted on the instance.

FAQ