

# 将 Amazon EFS 与 Amazon EC2 Linux 实例结合使用
<a name="AmazonEFS"></a>

**注意**  
Amazon EFS 在 Windows 实例上不受支持。

Amazon EFS 提供可扩展文件存储以供和 Amazon EC2 一起使用。您可以使用 EFS 文件系统作为在多个实例上运行的工作负载和应用程序的通用数据源。有关更多信息，请参阅[Amazon Elastic File System产品页](https://www.amazonaws.cn/efs/)。

本教程向您展示如何在实例启动期间，使用 Amazon EFS 快速创建向导创建和附加 Amazon EFS 文件系统。有关如何使用 Amazon EFS 控制台创建文件系统的教程，请参阅 [Amazon Elastic File System User Guide](https://docs.amazonaws.cn/efs/latest/ug/getting-started.html)（《Amazon File System 用户指南》）中的 *Getting started with Amazon Elastic File System*（Amazon Elastic File System 入门）。

**注意**  
使用 EFS 快速创建 EFS 文件系统时，将使用以下服务推荐设置创建文件系统：  
[已启用自动备份](https://docs.amazonaws.cn/efs/latest/ug/awsbackup.html)。
在所选 VPC 中[管理挂载目标](https://docs.amazonaws.cn/efs/latest/ug/accessing-fs.html)。
[通用性能模式](https://docs.amazonaws.cn/efs/latest/ug/performance.html#performancemodes)。
[突增吞吐量模式](https://docs.amazonaws.cn/efs/latest/ug/performance.html#throughput-modes)。
使用 Amazon EFS 的默认密钥 (`aws/elasticfilesystem`) [启用静态数据加密](https://docs.amazonaws.cn/efs/latest/ug/encryption-at-rest.html)。
使用 30 天策略[启用 Amazon EFS 生命周期管理](https://docs.amazonaws.cn/efs/latest/ug/lifecycle-management-efs.html)。

**Topics**
+ [测试 EFS 文件系统](#efs-test-file-system)
+ [删除 EFS 文件系统](#efs-clean-up)

## 测试 EFS 文件系统
<a name="efs-test-file-system"></a>

您可以连接到实例并验证文件系统是否已挂载到您指定的目录（例如，/mnt/efs）。

**验证文件系统是否已装载**

1. 连接到您的实例。有关更多信息，请参阅 [使用 SSH 连接到 Linux 实例](connect-to-linux-instance.md)。

1. 从每个实例的终端窗口，运行 **df -T** 命令以验证是否已挂载 EFS 文件系统。

   ```
   $ df -T
   Filesystem     Type              1K-blocks    Used          Available Use% Mounted on
   /dev/xvda1     ext4                8123812 1949800            6073764  25% /
   devtmpfs       devtmpfs            4078468      56            4078412   1% /dev
   tmpfs          tmpfs               4089312       0            4089312   0% /dev/shm
   efs-dns        nfs4       9007199254740992       0   9007199254740992   0% /mnt/efs
   ```

   请注意，文件系统的名称（在示例输出中显示为 *efs-dns*）具有以下格式。

   ```
   file-system-id.efs.aws-region.amazonaws.com:/
   ```

1. （可选）在该实例的文件系统中创建文件，然后验证您是否可以从另一实例查看该文件。

   1. 在该实例中，运行以下命令来创建文件。

      ```
      $ sudo touch /mnt/efs/test-file.txt
      ```

   1. 在另一个实例中，运行以下命令来查看文件。

      ```
      $ ls /mnt/efs
      test-file.txt
      ```

## 删除 EFS 文件系统
<a name="efs-clean-up"></a>

如果您不再需要文件系统，可将其删除。

**要删除文件系统**

1. 访问 [https://console.aws.amazon.com/efs/](https://console.amazonaws.cn/efs/)，打开 Amazon Elastic File System 控制台。

1. 选择要删除的文件系统。

1. 选择 **Actions**、**Delete file system**。

1. 当系统提示您确认时，输入文件系统 ID 并选择**删除文件系统**。