从 Amazon Elastic Container Service 挂载 - FSx for Lustre
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

从 Amazon Elastic Container Service 挂载

您可以从 Amazon EC2实例上的 Amazon Elastic Container Service(Amazon ECS)Docker 容器访问 FSx for Lustre 文件系统。您可以使用以下任一选项执行该操作:

  1. 从托管 Amazon ECS 任务的 Amazon EC2 实例挂载 FSx for Lustre 文件系统,然后将该挂载点导出到您的容器中。

  2. 将文件系统直接挂载到任务容器中。

有关 Amazon ECS 的更多信息,请参阅《Amazon Elastic Container Service 开发人员指南》中的什么是 Amazon Elastic Container Service?

我们建议使用选项 1(从托管 Amazon ECS 任务的 Amazon EC2 实例挂载),因为它可以更好地利用资源,尤其是在同一 EC2 实例上启动多个容器(超过五个)或者任务持续时间很短(少于 5 分钟)时。

如果您无法配置 EC2 实例,或者您的应用程序需要容器的灵活性,请使用选项 2(从 Docker 容器挂载)。

注意

不支持在 Fargate 发射类型上安装 FSx f Amazon or Lustre。

以下各节介绍了用于从 Amazon ECS 容器挂载 FSx for Lustre 文件系统的每个选项的操作过程。

从托管 Amazon ECS 任务的 Amazon EC2 实例挂载

此过程会向您介绍如何在 EC2 实例上配置 Amazon ECS,以在本地挂载 FSx for Lustre 文件系统。此过程使用 volumesmountPoints 容器属性来共享资源,并使本地运行的任务可以访问该文件系统。有关更多信息,请参阅《Amazon Elastic Container Service 开发人员指南》中的启动 Amazon ECS 容器实例

此过程是经 Amazon ECS 优化的 Amazon Linux 2 AMI 编写的。如果您正在使用其他 Linux 发行版,请参阅 安装 Lustre 客户端

从 EC2 实例上的 Amazon ECS 挂载文件系统。
  1. 手动或使用自动扩缩组启动 Amazon ECS 实例时,请将以下代码示例中的行添加到用户数据字段的末尾。替换示例中的以下项目:

    • file_system_dns_name 替换为实际文件系统的 DNS 名称。

    • mountname 替换为文件系统的挂载名称。

    • mountpoint 替换为您需要创建的文件系统的挂载点。

    #!/bin/bash ...<existing user data>... fsx_dnsname=file_system_dns_name fsx_mountname=mountname fsx_mountpoint=mountpoint amazon-linux-extras install -y lustre mkdir -p "$fsx_mountpoint" mount -t lustre ${fsx_dnsname}@tcp:/${fsx_mountname} ${fsx_mountpoint} -o relatime,flock
  2. 创建 Amazon ECS 任务时,请在 JSON 定义中添加以下 volumesmountPoints 容器属性。将 mountpoint 替换为文件系统的挂载点(例如 /mnt/fsx)。

    { "volumes": [ { "host": { "sourcePath": "mountpoint" }, "name": "Lustre" } ], "mountPoints": [ { "containerPath": "mountpoint", "sourceVolume": "Lustre" } ], }

从 Docker 容器挂载

以下过程介绍了如何配置 Amazon ECS 任务容器来安装 lustre-client 程序包并在其中挂载 FSx for Lustre 文件系统。该过程使用 Amazon Linux(amazonlinux)Docker 映像,但类似的方法也适用于其他发行版。

从 Docker 容器挂载文件系统
  1. 在您的 Docker 容器上,安装 lustre-client 程序包并使用 command 属性挂载您的 FSx for Lustre 文件系统。替换示例中的以下项目:

    • file_system_dns_name 替换为实际文件系统的 DNS 名称。

    • mountname 替换为文件系统的挂载名称。

    • mountpoint 替换为文件系统的挂载点。

    "command": [ "/bin/sh -c \"amazon-linux-extras install -y lustre; mount -t lustre file_system_dns_name@tcp:/mountname mountpoint -o relatime,flock;\"" ],
  2. 使用 linuxParameters 属性向您的容器添加 SYS_ADMIN 功能,以授权其挂载您的 FSx for Lustre 文件系统。

    "linuxParameters": { "capabilities": { "add": [ "SYS_ADMIN" ] } }