使用 Google Cloud 控制台创建 Filestore 实例

本快速入门介绍如何使用此 Google Cloud 控制台在 Filestore 中执行基本操作。在快速入门中,您将执行以下操作:

  • 创建 Filestore 实例。
  • 在 Compute Engine 客户端虚拟机实例上从该实例装载文件共享。
  • 在已装载的文件共享上创建文件。
  • 删除 Filestore 实例。

准备工作

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud新手, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Filestore API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Filestore API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

所需的角色

如需获得完成本快速入门所需的权限,请让您的管理员为您授予项目的以下 IAM 角色:

  • 创建和管理 Filestore 实例:Cloud Filestore Editor (roles/file.editor)
  • 创建和管理 Compute Engine 实例:Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1)
  • 创建、修改和删除网络资源(防火墙规则除外): Compute Network Admin (roles/compute.networkAdmin)
  • 对 IAM 服务账号运行操作: Service Account User (roles/iam.serviceAccountUser)
  • 管理网络和相关 Google Cloud 资源: Network Administrator (roles/iam.networkAdmin)

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

您也可以通过自定义 角色或其他预定义 角色来获取所需的权限。

完成本文档中描述的任务后,您可以通过删除所创建的资源来避免 继续计费。如需了解详情,请参阅 清理

创建一个 Compute Engine 虚拟机实例作为客户端

  1. 在 Google Cloud 控制台中,前往虚拟机实例页面。

    转到“Compute Engine 实例”页面

  2. 点击创建实例,然后按如下所示配置实例。

    • 名称设置为 nfs-client
    • 可用区 设置为 us-central1-c
    • 保留默认启动磁盘。
    • 网络 > 防火墙 部分中,选中允许 HTTP 流量 复选框。
    • 将网络保留为 default
  3. 点击创建 以创建实例。

创建 Filestore 实例

本快速入门介绍如何在启用自定义性能的情况下创建区域 层级的实例。如需详细了解如何创建实例,请参阅创建实例

  1. 在 Google Cloud 控制台中,前往 Filestore 实例 页面。

    前往 Filestore 实例页面

  2. 点击创建实例 ,然后按如下所示配置实例:

    • 实例 ID 设置为 nfs-server
    • 实例类型 设置为区域
    • 容量 中,输入 1 TiB
    • 性能 中,点击自定义性能 开关以启用自定义性能。默认情况下,您会在性能 字段中获得 12,000 IOPS。随容量扩缩性能 复选框处于选中状态,因此,如果您更改容量 字段中的值,性能会相应地扩缩。如需详细了解配置选项,请参阅配置性能

    • 区域 设置为 us-central1

    • VPC 网络 设置为 default

    • 文件共享名称设置为 vol1

    • 分配的 IP 范围设置为使用自动分配的 IP 范围

    • 访问权限控制设置为授予所有客户端访问权限

  3. 点击创建

在客户端上装载 Filestore 文件共享

  1. 在 Google Cloud 控制台中,前往虚拟机实例页面。

    前往“虚拟机实例”页面

  2. 在虚拟机实例列表中,点击 nfs-clientSSH 按钮,打开与该实例连接的终端窗口。

  3. 运行以下命令安装 NFS:

    sudo apt-get -y update &&
    sudo apt-get -y install nfs-common
    
  4. 运行以下命令,为 Filestore 文件共享创建一个装载目录:

    sudo mkdir -p /mnt/test
    
  5. 通过运行 mount 命令并指定 Filestore 实例 IP 地址和文件共享名称来装载文件共享:

    sudo mount MOUNT-POINT-DIRECTORY /mnt/test
    

    其中:

    MOUNT-POINT-DIRECTORY 是 Filestore 文件共享所在目录的路径。例如:10.0.0.2:/vol1

  6. 可选:确认已装载 Filestore 文件共享:

    df -h --type=nfs
    
  7. 更改权限,将文件共享设置为可访问:

    sudo chmod go+rw /mnt/test
    

在文件共享上创建文件

  1. 在连接到 nfs-client 实例的终端窗口中,通过运行以下命令创建名为 testfile 的文件:

    echo 'This is a test' > /mnt/test/testfile
    
  2. 运行以下命令,确认文件已创建:

    ls /mnt/test
    

    并确认 testfile 是否已列出。

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。

删除 Google Cloud 项目

  1. 在 Google Cloud 控制台中,前往 管理资源 页面。

    转到“管理资源”

  2. 在项目列表中,选择要删除的项目,然后点击删除
  3. 在对话框中输入项目 ID,然后点击 关停 以删除项目。

删除 Filestore 实例

  1. 在 Google Cloud 控制台中,前往 Filestore 实例页面。

    前往“Filestore 实例”页面

  2. 点击 nfs-server 实例 ID 以打开“实例详情”页面。

  3. 点击删除

  4. 出现提示时,输入实例 ID。

  5. 点击删除

删除 Compute Engine 实例

  1. 在 Google Cloud 控制台中,前往 Filestore 实例页面。

    前往“虚拟机实例”页面

  2. 选中 nfs-client 实例名称旁边的复选框。

  3. 点击删除

  4. 当系统提示时,再次点击删除

后续步骤