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

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

  • 创建 Filestore 实例。
  • 在客户端虚拟机实例上装载该实例的文件共享。
  • 在已装载的文件共享上创建文件。
  • 删除 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.

    Go to project selector

  3. 确保您的 Google Cloud 项目已启用结算功能

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

    Go to project selector

  5. 确保您的 Google Cloud 项目已启用结算功能

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

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

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

    转到“Compute Engine 实例”页面

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

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

创建 Filestore 实例

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

    转到“Filestore 实例”页面

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

    • 实例 ID 设置为 nfs-server
    • 实例类型设置为基本
    • 存储类型设置为 HDD
    • 分配容量设置为 1TB
    • 地区设置为 us-central1,将区域设置为 us-central1-c
    • 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 10.0.0.2:/vol1 /mnt/test
    
  6. 更改权限,将文件共享设置为可访问:

    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. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

删除 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. 当系统提示时,再次点击删除

后续步骤