首页 > 解决方案 > 创建 Google Dataproc 集群并连接到外部远程 Hive 元存储

问题描述

我正在尝试创建一个 dataproc 集群并指向一个远程 Hive 元存储,以便从该集群访问 Hive 表。我正在使用以下创建集群命令来创建一个连接到远程 Hive 元存储的 Dataproc 2.0 集群:

创建集群命令:

gcloud dataproc clusters create wl1-cluster-1 \
--region us-east1 \
--subnet projects/shared-vpc-admin/regions/us-east1/subnetworks/dev-us-east1-01 \
--enable-component-gateway \
--no-address \
--scopes 'https://www.googleapis.com/auth/cloud-platform' \
--master-machine-type n1-standard-32 \
--master-boot-disk-size 1000 \
--num-workers 10 \
--worker-machine-type n1-standard-32 \
--worker-boot-disk-size 1000 \
--image-version 2.0-debian10 \
--properties 'spark:spark.sql.hive.metastore.version=2.3.0,spark:spark.sql.hive.metastore.jars=maven,hive:hive.metastore.schema.verification=false,hive:javax.jdo.option.ConnectionURL=jdbc:mysql://test-mysql.gcp-dev.glb.us.mycompany.net:3306/metastore,hive:javax.jdo.option.ConnectionUserName=metastore,hive:javax.jdo.option.ConnectionPassword=XXXX' \
--project sample_gcp_project

但它在步骤激活组件配置单元元存储期间失败。

错误信息:

<13>Sep 10 05:47:06 google-dataproc-startup[1734]: <13>Sep 10 05:47:06 activate-component-hive-metastore[3064]: nc: connect to wl1-cluster-1-m port 9083 (tcp) failed: Connection refused
<13>Sep 10 05:47:07 google-dataproc-startup[1734]: <13>Sep 10 05:47:07 activate-component-hive-metastore[3064]: nc: connect to wl1-cluster-1-m port 9083 (tcp) failed: Connection refused
<13>Sep 10 05:47:07 google-dataproc-startup[1734]: <13>Sep 10 05:47:07 activate-component-hive-metastore[3064]: 'nc -v -z -w 1 wl1-cluster-1-m 9083' attempt 23 failed! Sleeping 1s.

几个问题:

  1. 这是在创建集群时连接到远程配置单元元存储的正确且唯一的方法吗?
  2. 我可以从从该集群提交的 Spark 作业访问配置单元元存储,而不是配置连接到远程配置单元元存储的集群。你能指出我正确的方向吗?
  3. 有没有其他方法可以解决这个问题?

标签: apache-sparkhivegoogle-cloud-dataprochive-metastore

解决方案


默认情况下,有一个 Metastore 服务在 Dataproc 集群的(第一个)主节点上运行,默认端口为 9083,Hive Server2 配置为使用它。在/etc/hive/conf/hive-site.xml中,您会发现:

  <property>
    <name>hive.metastore.uris</name>
    <value>thrift://<master-hostname>:9083</value>
  </property>

如果您需要集群的 HiveServer2:

  1. 要使用另一个集群的 Metastore,请设置--properties hive:hive.metastore.uris=thrift://<another-cluster-master-hostname>:9083.

  2. 或要使用托管 Dataproc Metastore 服务,请按照以下说明操作,例如:

gcloud dataproc clusters create example-cluster \
    --dataproc-metastore=projects/PROJECT_ID/locations/LOCATION/services/example-service \
    --region=LOCATION

集群/Metastore 需要在同一个 VPC 网络中,才能通过内部 IP(或主机名)相互通信。

集群中的 Spark 会自动配置为使用 Hive 配置hive.metastore.uris来查找 Metastore,您不需要在 Spark 代码中进行任何其他配置。


推荐阅读