将自行管理的 MySQL Metastore 迁移到 Dataproc Metastore
本页面介绍如何通过创建 MySQL 转储文件并将元数据导入现有的 Dataproc Metastore 服务,将外部自行管理的 MySQL Metastore 迁移到 Dataproc Metastore。
开始前须知
- 登录您的 Google Cloud 帐号。如果您是 Google Cloud 新手,请创建一个帐号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
-
在 Google Cloud Console 中的项目选择器页面上,选择或创建一个 Google Cloud 项目。
-
确保您的 Cloud 项目已启用结算功能。了解如何检查项目是否已启用结算功能。
-
在 Google Cloud Console 中的项目选择器页面上,选择或创建一个 Google Cloud 项目。
-
确保您的 Cloud 项目已启用结算功能。了解如何检查项目是否已启用结算功能。
-
启用 Dataproc Metastore API。
访问权限控制机制
如果您使用的是 VPC Service Controls,则只能从与 Dataproc Metastore 服务位于同一服务边界的 Cloud Storage 存储分区导入数据。
如需创建服务,您必须请求包含
metastore.services.create
IAM 权限的 IAM 角色。如需导入元数据,您必须请求包含metastore.imports.create
IAM 权限的 IAM 角色。Dataproc Metastore 特定角色roles/metastore.admin
和roles/metastore.editor
具有创建和导入权限。您可以使用
roles/owner
和roles/editor
旧版角色为用户或组授予创建和导入权限。Dataproc Metastore 服务代理 (
service-CUSTOMER_PROJECT_NUMBER@gcp-sa-metastore.iam.gserviceaccount.com
) 和导入元数据的用户必须对用于导入的 Cloud Storage 对象(SQL 转储文件)拥有storage.objects.get
权限。
如需获取和设置 IAM 政策,您可以执行以下操作:
- Google Cloud Console:请参阅通过 Google Cloud Console 进行访问权限控制。
- REST API:请参阅通过 API 进行访问权限控制。
gcloud
命令行:请参阅通过 Google Cloud CLI 进行访问权限控制。
如需了解详情,请参阅 Dataproc Metastore IAM 和访问权限控制。
创建 Dataproc Metastore 服务
以下说明演示了如何创建随后可以迁移到的 Dataproc Metastore 服务:
控制台
在 Cloud Console 中,打开创建服务页面:
在服务名称字段中,输入
example-service
。选择数据位置。 如需了解如何选择区域,请参阅 Cloud 位置。
对于其他服务配置选项,请使用提供的默认值。
要创建并启动此服务,请点击提交按钮。
您的新服务会显示在“服务”列表中。
gcloud
运行以下 gcloud metastore services create
命令以创建服务:
gcloud metastore services create example-service \ --location=LOCATION
将 LOCATION
替换为您打算在其中创建服务的 Compute Engine 地区。确保相应地区提供 Dataproc Metastore。
REST
按照 API 说明使用 API Explorer 创建服务。
准备迁移
现在,您必须创建 MySQL 转储文件并将其放入 Cloud Storage 存储分区中,以准备存储在 Hive Metastore 数据库中的元数据。
有关准备迁移的步骤,请参阅准备导入。
导入元数据
现在您已准备好转储文件,请将其导入您的 Dataproc Metastore 服务。
如需了解将元数据导入 example-service
服务的步骤,请参阅执行导入。
创建并附加 Dataproc 集群
将元数据导入 Dataproc Metastore example-service
服务后,创建并连接使用该服务作为其 Hive Metastore 的 Dataproc 集群。
清理
为避免系统因本页面使用的资源向您的 Google Cloud 帐号收取费用,请按照以下步骤操作。
- 在 Cloud Console 中,转到管理资源页面。
- 如果您打算删除的项目已附加到某个组织,请展开名称列中的组织列表。
- 在项目列表中,选择要删除的项目,然后点击删除。
- 在对话框中输入项目 ID,然后点击关闭以删除项目。
或者,您也可以删除本教程中使用的资源:
删除 Dataproc Metastore 服务。
控制台
在 Cloud Console 中,打开 Dataproc Metastore 页面:
选中服务名称左侧的
example-service
复选框。在 Dataproc Metastore 页面顶部,点击删除以删除服务。
在对话框中,点击删除以确认删除。
您的服务不会再显示在“服务”列表中。
gcloud
运行以下
gcloud metastore services delete
命令可删除服务:gcloud metastore services delete example-service \ --location=LOCATION
将
LOCATION
替换为您在其中创建了服务的 Compute Engine 区域。REST
按照 API 说明,使用 API Explorer 删除服务。
所有删除操作都会立即成功。