Apache Kafka 是一个开源分布式流式传输平台,用于实时数据流水线和数据集成。它提供了一个高效且可扩缩的流式传输系统,可用于各种应用,包括:
- 实时分析
- 流处理
- 日志汇总
- 分布式消息传递
- 事件流处理
目标
在带有 ZooKeeper 的 Managed Service for Apache Spark 高可用性集群(在本教程中称为“Managed Service for Apache Spark Kafka 集群”)上安装 Kafka。
创建虚构的客户数据,然后将该数据发布到 Kafka 主题。
在 Cloud Storage 中创建 Hive Parquet 和 ORC 表,以接收流式传输的 Kafka 主题数据。
提交 PySpark 作业,以订阅 Kafka 主题并以 Parquet 和 ORC 格式将该主题流式传输到 Cloud Storage。
对流式传输的 Hive 表数据运行查询,以统计流式传输的 Kafka 消息数量。
费用
在本文档中,您将使用 Google Cloud的以下收费组件:
如需根据您的预计使用情况来估算费用,请使用价格计算器。
完成本文档中描述的任务后,您可以通过删除所创建的资源来避免继续计费。如需了解详情,请参阅清理。
准备工作
如果尚未创建 Google Cloud 项目,请创建一个。
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Dataproc, Compute Engine, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.- 在 Google Cloud 控制台中,前往 Cloud Storage 存储分区页面。
- 点击 创建。
- 在创建存储桶页面上,输入您的存储桶信息。要转到下一步,请点击继续。
- 在开始使用部分中,执行以下操作:
- 在选择数据存储位置部分,执行以下操作:
- 在选择数据存储方式部分中,执行以下操作:
- 在选择如何控制对对象的访问权限部分中,选择存储桶是否强制执行禁止公开访问,然后为存储桶对象选择访问权限控制方法。
- 在选择如何保护对象数据部分中,执行以下操作:
- 点击创建。
教程步骤
请执行以下步骤创建 Managed Service for Apache Spark Kafka 集群,以 Parquet 或 ORC 格式将 Kafka 主题读入 Cloud Storage。
将 Kafka 安装脚本复制到 Cloud Storage
kafka.sh 初始化操作脚本会在 Managed Service for Apache Spark 集群上安装 Kafka。
浏览代码。