将 Google Cloud 服务与 SAP Business Technology Platform (SAP BTP) 上的 Cloud Foundry 集成

本文中的说明介绍了如何使用 Open Service Broker for Google Cloud (Google Cloud Service Broker) 将 Google Cloud 服务集成到 SAP Business Technology Platform (SAP BTP) 上的 Cloud Foundry 环境中。

Google Cloud Service Broker 可简化向 SAP BTP 上的 Cloud Foundry 环境中运行的应用交付 Google Cloud 服务的过程。通过创建 Google Cloud 资源并管理其相应权限,Google Cloud Service Broker 使您可以轻松从 SAP BTP 应用环境内使用 Google Cloud 服务。

下图简要展示了设置步骤与一些 Google Cloud 服务示例。

通过 SAP BTP 上的 Cloud Foundry 访问 Google Cloud 服务

核心解决方案组件

在 SAP BTP 上为 Cloud Foundry 环境设置 Google Cloud Service Broker 时,需要使用以下组件。

服务 用例
Open Service Broker for Google Cloud 将 Google Cloud 服务集成到 SAP BTP 上的 Cloud Foundry 环境中
Cloud SQL for MySQL 用于 Google Cloud Service Broker 后端存储的数据库
SAP BTP 账号 在选定的 Google Cloud 区域中提供 SAP BTP Cloud Foundry 环境
Google Cloud 项目 提供 Google Cloud 服务
Cloud Foundry CLI 用于配置 Cloud Foundry 的命令行界面

费用

建议与 Google Cloud Service Broker 搭配使用的 Cloud SQL 是收费 Google Cloud 组件。

通过相应的 API 使用 Google Cloud 服务可能也会收费。

请使用价格计算器根据您的预计用量来估算费用。

前提条件

您必须先设置本地开发环境并在 Google Cloud 上创建项目,然后才能在 SAP BTP 上设置 Cloud Foundry 环境。

设置开发环境

  1. 按照 SAP Portal 文档所述,在您的开发工作站上安装 Cloud Foundry 命令行界面 (CLI)。

设置 Google Cloud 项目

如果您还没有已启用结算功能的 Google Cloud 项目,必须先创建一个。

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. 在 Google Cloud Console 中的项目选择器页面上,选择或创建一个 Google Cloud 项目

    转到“项目选择器”

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

  4. 在 Google Cloud Console 中的项目选择器页面上,选择或创建一个 Google Cloud 项目

    转到“项目选择器”

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

设置 Google Cloud 环境

您需要具备一些已启用的 Google Cloud API、一个 Google Cloud 服务账号以及一个用于 Google Cloud Service Broker 的数据库。

启用所需的 Google Cloud APIs

API 管理器 > 库中启用以下 API。

  1. 启用 Cloud Resource Manager API
  2. 启用 Identity and Access Management API
  3. 启用 Cloud SQL Admin API
  4. 为您需要的任何其他受支持的 Google Cloud 服务启用 API。

创建根服务账号

  1. 在 Google Cloud 控制台中,转到服务账号页面。

    转到“服务账号”页面

  2. 选择您的 Google Cloud 项目。

  3. 点击创建服务账号

  4. 服务账号名称字段中输入名称。

  5. 点击创建并继续

  6. 选择角色列表中,点击项目 > 所有者,该角色提供了 Google Cloud Service Broker 使用 Google Cloud 服务所需的权限。

  7. 点击继续

  8. 根据具体情况授予其他用户访问服务账号的权限。

  9. 点击完成

  10. 在 Google Cloud 控制台中的服务账号页面上,点击您刚创建的服务账号的电子邮件地址。

  11. 在服务账号名称下,点击密钥标签页。

  12. 点击添加密钥下拉菜单,然后选择创建新密钥

  13. 确保指定了 JSON 密钥类型。

  14. 点击创建。JSON 密钥文件将自动下载到您的工作站。

  15. 将 JSON 密钥文件转移到安全的位置。

设置备份数据库

Google Cloud Service Broker 需要 MySQL 数据库来存储已预配资源的状态。建议使用 Cloud SQL for MySQL 的第二代实例,该实例可提供完全托管的 MySQL 社区版数据库,此数据库具备自动备份、高可用性和自动维护功能。 但是,您可以使用与 MySQL 协议兼容的任何数据库。

以下步骤通过在 Google Cloud 上使用第二代 Cloud SQL 实例来创建数据库,但应适用于与 MySQL 协议兼容的任何数据库。

创建 Cloud SQL for MySQL 实例

您需要先在 Google Cloud 上创建一个 Cloud SQL for MySQL 实例,然后才能创建数据库。

  1. 在 Google Cloud 控制台中,转到 Cloud SQL 实例页面。

    打开“Cloud SQL 实例”页面

  2. 点击创建实例

    1. 选择 MySQL,再点击下一步
    2. 点击选择第二代
    3. 定义实例 ID
    4. 定义 root 密码
    5. 区域字段中,选择您的 Cloud Foundry 环境所在的区域。
    6. 点击创建

创建数据库

  1. 启动 Cloud SQL 实例后,打开 Cloud Shell。

    打开 Cloud Shell

  2. 连接到 Cloud SQL 实例。

    gcloud sql connect your-cloud-sql-instance --user=root
    

    其中,your-cloud-sql-instance 是您在 Google Cloud 上创建的 Cloud SQL 实例的名称。

  3. 创建一个名为 servicebroker 的数据库。

    CREATE DATABASE servicebroker;
    
  4. 定义 Google Cloud Service Broker 的用户名和密码。

    CREATE USER 'SB_DB_UserName'@'%' IDENTIFIED BY 'SB_DB_Password';
    

    其中:

    • SB_DB_UserName 是用户名,表示作为数据库用户的 Google Cloud Service Broker。
    • SB_DB_Password 是密码,用于向数据库标识 Google Cloud Service Broker。
  5. 设置 Google Cloud Service Broker 的访问权限。

    GRANT ALL PRIVILEGES ON servicebroker.* TO 'SB_DB_UserName'@'%' WITH GRANT OPTION;
    
  6. 设置 SSL 并获取 SSL 证书。

    1. 在 Google Cloud 控制台中,打开 Cloud SQL 实例页面。

      打开“Cloud SQL 实例”页面

    2. 点击 Cloud SQL 实例的名称。

    3. 实例详情页面上,点击连接标签页。

    4. SSL 连接下的 SSL 部分中,点击只允许 SSL 连接。更新可能需要几秒钟的时间。

    5. 配置 SSL 客户端证书下的 SSL 部分中,点击创建客户端证书

    6. 输入名称,然后点击创建

    7. 下载三个证书文件,并将其保存到安全的位置。

  7. 实例详情页面上连接标签页的连接部分中:

    1. 确认已选中公共 IP 框。
    2. 已获授权的网络下,点击添加网络
    3. 网络字段中,输入 0.0.0.0/0
    4. 点击完成
  8. 点击保存以保存授权更改。

在 Google Cloud 基础架构上为 Cloud Foundry 获取 SAP BTP 试用账号

  1. 注册 SAP BTP 试用账号。 您需要一个活跃的 SAP 账号才能获得 SAP BTP 试用账号。
  2. 登录 SAP BTP Cockpit
  3. 在 SAP BTP Cockpit 中,选择屏幕顶部的 Home
  4. 在屏幕左侧的导航窗格中,点击 Regions
  5. Cloud Foundry Environment 下,选择一个使用 Google Cloud 基础架构的区域,如 US-Central (IA)。这样将在 SAP BTP Cloud Foundry 环境中创建组织和空间。

为 Cloud Foundry 安装和配置 Google Cloud Service Broker

为 Cloud Foundry 部署 Google Cloud Service Broker

在开发工作站的终端上:

  1. 从 GitHub 为 Cloud Foundry 安装最新版 Google Cloud Service Broker。

    curl -s https://api.github.com/repos/GoogleCloudPlatform/gcp-service-broker/releases/latest \
    |grep 'tag_name' \
    |cut -d\" -f4 \
    |xargs -I {} curl -sOL "https://github.com/GoogleCloudPlatform/gcp-service-broker/archive/"{}'.tar.gz'
    
  2. 提取 Google Cloud Service Broker 文件。

    tar zxvf *.tar.gz
    
  3. 切换目录。

    cd gcp-service-broker*
    
  4. 登录 SAP BTP Cloud Foundry 环境。

    cf login
    
  5. 输入 API 端点。

    https://api.techkey.hana.ondemand.com
    

    其中,techkey 是 SAP 定义的技术密钥,可标识 API 端点所在的区域。例如,包含 Google Cloud 基础架构的 US Central 区域的技术密钥为 cf.us30。如需查看 SAP BTP Cloud Foundry 环境的所有区域的列表,请参阅 SAP 帮助门户

  6. 输入您的 SAP BTP 账号的用户名和密码。

  7. 将 Google Cloud Service Broker 应用部署到 Cloud Foundry 环境。

    cf push APP_NAME --no-start
    

    其中,APP_NAME 是您为 Google Cloud Service Broker 应用选择的唯一名称。例如 gcp-service-broker-001mycompany-gcp-svc-broker-app

    在 Cloud Foundry 部署了 Google Cloud Service Broker 应用后,您会看到类似如下示例的信息:

    name:              gcp-service-broker-example-app
    requested state:   stopped
    routes:            gcp-service-broker-example-app.cfapps.us30.hana.ondemand.com
    last uploaded:
    stack:
    buildpacks:
    type:           web
    instances:      0/1
    memory usage:   1024M
         state   since                  cpu    memory   disk     details
    #0   down    2018-12-19T23:49:13Z   0.0%   0 of 0   0 of 0
    

为 Cloud Foundry 配置 Google Cloud Service Broker 应用

  1. 登录 SAP BTP Cockpit
  2. 在 SAP BTP Cockpit 中,转到 Trial Home > Regions > Your Google Cloud region > Your global account > Your subaccount > Spaces > Your space
  3. 点击您在上一部分中部署的 Google Cloud Service Broker 应用的名称。
  4. 在左侧菜单中,点击 User-provided variables
  5. 使用添加变量按钮将以下 Google Cloud Service Broker 变量定义为键值对:

    
    CA_CERT
    您在设置备份数据库部分设置 SSL 时下载的服务器证书文件 server-ca.pem 的内容。
    
    CLIENT_CERT
    您在设置备份数据库部分设置 SSL 时下载的客户端证书文件 client-cert.pem 的内容。
    
    CLIENT_KEY
    您在设置备份数据库部分设置 SSL 时下载的客户端秘钥文件 client-key.pem 的内容。
    
    DB_HOST
    Cloud SQL 实例的公共 IP 地址,如 Google Cloud 控制台中您的 Cloud SQL 实例的实例详情页面的连接到此实例部分中所示。
    
    DB_PASSWORD
    您为 Google Cloud Service Broker 定义的密码,用于访问您在设置备份数据库部分配置的数据库。
    
    DB_USERNAME
    您在创建数据库时为 Google Cloud Service Broker 定义的用户名。对于 Cloud SQL 数据库,您可以在 Google Cloud 控制台中 Cloud SQL 实例的实例详情页面用户标签页上的 MySQL 用户账号下面看到该用户名。
    
    ROOT_SERVICE_ACCOUNT_JSON
    您在创建根服务账号时下载的 JSON 密钥文件的内容。
    
    SECURITY_USER_NAME
    您为 service broker 定义的用户名,可在验证 broker 请求的身份时使用。 稍后在您创建 broker 服务时应在 cf create-service-broker 命令中指定相同的用户名。
    
    SECURITY_USER_PASSWORD
    您为 service broker 定义的密码,可在验证 broker 请求的身份时使用。稍后在您创建 broker 服务时应在 cf create-service-broker 命令中指定相同的密码。
    可选环境变量 如需可用于自定义 Google Cloud Service Broker 的可选变量列表,请参阅安装自定义

为 Cloud Foundry 启动 Google Cloud Service Broker 应用

  1. 点击左侧菜单中的 Overview
  2. 如需启动 broker 应用,请点击 Start。在应用启动并运行后,Overview 页面上将显示绿色的 StartedRunning 指示符,如下图所示。

    绿色的 Started 指示符显示 Google Cloud Service Broker 已启动

    绿色的 RUNNING 指示符显示 Google Cloud Service Broker 正在运行

  3. 如果 Google Cloud Service Broker 应用无法启动,或者显示 ErrorCrashed,请从开发工作站中检查应用日志,并相应地调整变量或配置。

    cf logs APP_NAME --recent
    

为 Cloud Foundry 注册 Google Cloud Service Broker

在您的开发工作站上:

  1. 连接到 SAP BTP Cloud Foundry 环境。

    cf login
    
  2. 列出已部署的应用。

    cf apps
    

    您将看到类似以下示例的输出:

    name              requested state   instances   memory   disk   urls
    broker-test-app   started           1/1         1G       1G     broker-test-app.cfapps.us30.hana.ondemand.com
    
  3. 注册 broker service。

    cf create-service-broker BROKER_SERVICE_NAME SECURITY_USER_NAME
    SECURITY_USER_PASSWORD https://BROKER_APPLICATION_ROUTE --space-scoped
    

    其中:

  4. 验证 broker 服务的注册情况。

    cf service-brokers
    

    您应该会看到类似于以下示例的输出:

    name                  url
    broker-service-name   https://broker-service-name.cfapps.us30.hana.ondemand.com
    
  5. 验证 SAP BTP Service Marketplace 中现在是否提供 Google Cloud 服务。

    cf marketplace
    

    以下示例(已经过修改,以便于阅读和适合页面尺寸)展示了 Marketplace 中 Google Cloud 服务列表中的两项服务。

    service          plans                      description
    ...
    google-bigquery  default                    A fast, economical and fully managed data warehouse for large-scale data analytics.
    google-bigtable  three-node-production-hdd  A high performance NoSQL database service for large analytical and operational workloads.
    

    如需查看可用的 Google Cloud 服务列表,请参阅 Open Service Broker for Google Cloud

后续步骤

创建 Google Cloud 服务实例并将其绑定到您的 SAP BTP 应用。

如需详细了解如何创建和绑定 Google Cloud 服务,请参阅以下文档: