在 SAP Business Technology Platform (SAP BTP) 上,將 Google Cloud 服務與 Cloud Foundry 整合

在這裡的說明中,會示範如何使用適用於 Google Cloud 的 Open Cloud Broker (Google Cloud Service Broker),將 Google Cloud服務整合到 SAP Business Technology Platform(SAP BTP) 上的 Cloud Foundry 環境中。

將 Google Cloud 服務提交至於 SAP BTP 上的 Cloud Foundry 環境內執行的應用程式時,可由Google Cloud Service Broker 來簡化這個過程。Service Broker 可建立 Google Cloud 資源並管理對應的權限,如此就能在 SAP BTP 應用程式環境中輕鬆使用 Google Cloud 服務。Google Cloud

下圖是高層級的設定步驟視圖,內有一些Google Cloud 服務範例。

從 SAP BTP 上的 Cloud Foundry 存取 Google Cloud 服務

核心解決方案元件

在 SAP BTP 上的 Cloud Foundry 設定Google Cloud Service Broker 時,必須提供下列元件。

服務 用途
開啟 Google Cloud的 Service Broker 將 Google Cloud 服務整合到 SAP BTP 的 Cloud Foundry 環境中
MySQL 適用的 Cloud SQL Google Cloud Service Broker 的後端儲存空間資料庫
SAP BTP 帳戶 在所選 Google Cloud 區域提供 SAP BTP Cloud Foundry 環境
Google Cloud 專案 提供 Google Cloud 服務
Cloud Foundry CLI 用來設定 Cloud Foundry 的指令列介面

費用

Cloud SQL 建議與 Google Cloud Service Broker Google Cloud 搭配使用,屬於需收費的元件。

透過各自 API 所使用的 Google Cloud 服務也可能需要收費。

使用 Pricing Calculator 可根據您的預測使用量來產生預估費用。

必要條件

您必須先設定本機開發環境並在 Google Cloud上建立專案,才能在 SAP BTP 上設定 Cloud Foundry 環境。

設定開發環境

  1. 依照 SAP Portal 說明文件,在開發工作站上安裝 Cloud Foundry 指令列介面 (CLI)。

設定 Google Cloud 專案

如果您還沒有已啟用計費功能的 Google Cloud 專案,則必須建立一個。

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

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

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. 設定 Google Cloud 環境

    您必須啟用特定的 Google Cloud API、 Google Cloud 服務帳戶和Google Cloud Service Broker 的資料庫。

    啟用必要的 Google Cloud API

    API Manager > Library (資料庫) 中啟用下列 API。

    1. 啟用 Cloud Resource Manager API
    2. 啟用 Identity and Access Management API
    3. 啟用 Cloud SQL Admin API
    4. 啟用其他需要的支援 Google Cloud 服務的 API。

    建立根服務帳戶

    1. 前往 Google Cloud 控制台的「Service accounts」(服務帳戶) 頁面。

      前往「Service Accounts」(服務帳戶) 頁面

    2. 選取 Google Cloud 專案。

    3. 按一下「Create Service Account」(建立服務帳戶)

    4. 在「Service account name」(服務帳戶名稱) 欄位中輸入名稱。

    5. 按一下「建立並繼續」

    6. 在「Select a role」(選取角色) 清單中,按一下「Project」(專案) >「Owner」(擁有者),提供 Google Cloud Service Broker 搭配 Google Cloud 服務使用的必要權限。

    7. 按一下「繼續」

    8. 視情況授予其他使用者服務帳戶的存取權。

    9. 按一下 [完成]

    10. 在 Google Cloud 控制台的「Service accounts」(服務帳戶) 頁面中,按一下您剛才建立的服務帳戶電子郵件地址。

    11. 在服務帳戶名稱下方,按一下「金鑰」分頁標籤。

    12. 點選「新增金鑰」下拉式選單,然後選取「建立新的金鑰」

    13. 請確認所指定的是 JSON 金鑰類型。

    14. 按一下「建立」,系統會自動將 JSON 金鑰檔案下載至您的工作站。

    15. 將 JSON 金鑰檔案移動到安全的位置。

    設定備用資料庫

    Google Cloud Service Broker 需要 MySQL 資料庫來儲存已佈建資源的狀態。建議使用 MySQL 適用的第二代 Cloud SQL 執行個體,因為這是全代管的 MySQL Community Edition 資料庫,可自動備份、具備高可用性,又能自動維護。不過,您可以使用任何與 MySQL 通訊協定相容的資料庫。

    下列步驟會在 Google Cloud上使用第二代 Cloud SQL 執行個體建立資料庫,但應適用於任何與 MySQL 通訊協定相容的資料庫。

    建立 MySQL 適用的 Cloud SQL 執行個體

    在建立資料庫之前,需要在 Google Cloud上為 MySQL 執行個體建立 Cloud SQL。

    1. 前往 Google Cloud 控制台的「Cloud SQL Instances」頁面。

      開啟「Cloud SQL Instances」(Cloud SQL 執行個體) 頁面

    2. 點選「建立執行個體」

      1. 選取 [MySQL],然後點選 [Next] (下一步)
      2. 按一下 [Choose Second Generation] (選擇第二代)
      3. 定義執行個體 ID
      4. 定義根密碼
      5. 在「Region」(地區) 欄位中,選擇 Cloud Foundry 環境所在的地區。
      6. 按一下 [Create] (建立)。

    建立資料庫

    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 Instances」(Cloud SQL 執行個體) 頁面。

        開啟「Cloud SQL Instances」(Cloud SQL 執行個體) 頁面

      2. 按一下 Cloud SQL 執行個體的名稱。

      3. 在「Instance details」(執行個體詳細資料) 頁面上,按一下 [Connections] (連線) 分頁標籤。

      4. 在「SSL connections」(SSL連線) 下的「SSL」區段中,按一下 [Allow only SSL Connections] (僅允許 SSL 連線)。更新可能需要幾秒鐘的時間才能完成。

      5. 在「SSL」區段的「Configure SSL client certificates」(設定 SSL 用戶端憑證) 下,按一下 [Create a client certificate] (建立用戶端憑證)

      6. 輸入名稱後按一下 [Create] (建立)

      7. 下載三個憑證檔案並將其儲存到安全的位置。

    7. 在「Instance details」(執行個體詳細資料) 頁面上 [Connections] (連線) 分頁標籤的 [Connectivity] (連線能力) 區段:

      1. 確認已選取 [Public IP] (公開 IP) 方塊。
      2. 在「Authorized networks」(已授權的網路) 下,按一下 [Add network] (新增網路)
      3. 在「Network」(網路) 欄位中輸入 0.0.0.0/0
      4. 按一下 [完成]
    8. 按一下 [Save] (儲存) 以儲存授權變更。

    取得適用於 Google Cloud 基礎架構上的 Cloud Foundry 的 SAP BTP 試用帳戶

    1. 註冊 SAP BTP 試用帳戶。 您必須擁有有效的 SAP 帳戶,才能取得 SAP BTP 試用帳戶。
    2. 登入 SAP BTP Cockpit
    3. 在 SAP BTP 主控台中,選擇畫面頂端的「Home」
    4. 在螢幕畫面左側的導航窗格中,按一下 [Region]
    5. 在「Cloud Foundry Environment」下,選擇要使用Google Cloud 基礎架構的地區,例如 US-Central (IA)。如此會在 SAP BTP Cloud Foundry 環境中建立機構和空間。

    安裝及設定 Google Cloud Service Broker for Cloud Foundry

    部署 Google Cloud Cloud Foundry 適用的 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基礎架構) 的技術金鑰為 cf.us30。如要查看 SAP BTP Cloud Foundry 環境的所有地區清單,請參閱 SAP 說明入口網站

    6. 輸入 SAP BTP 帳戶的使用者名稱和密碼。

    7. 將 Google Cloud 服務代理程式應用程式部署到 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. 使用「Add variable」(新增變數) 按鈕,將下列 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 執行個體的「Instance details」(執行個體詳細資料) 的「Connect to this instance」(連線至此執行個體) 區段所示。
      DB_PASSWORD
      您為 Google Cloud Service Broker 所定義的密碼,用來存取您在設定備用資料庫時所設定的資料庫。
      DB_USERNAME
      您在建立資料庫時為 Google Cloud Service Broker 所定義的使用者名稱。針對 Cloud SQL 資料庫的使用者名稱,您可以在 Google Cloud 控制台中 Cloud SQL 執行個體的「Instance details」(執行個體詳細資料) 頁面上,位於「Users」(使用者) 分頁標籤的「MySQL user accounts」(MySQL 使用者帳戶)下查看。
      ROOT_SERVICE_ACCOUNT_JSON
      您在建立根服務帳戶時所下載的 JSON 金鑰檔案內容。
      SECURITY_USER_NAME
      定義服務代理程式在驗證代理要求時所要使用的使用者名稱。稍後在建立代理服務時,請在 cf create-service-broker 指令中指定相同的使用者名稱。
      SECURITY_USER_PASSWORD
      定義服務代理程式在驗證代理請求時使用的密碼。稍後在建立代理服務時,請在 cf create-service-broker 指令中指定相同的密碼。
      可選的環境變數 如需可用來自訂 Google Cloud Service Broker 的可選變數清單,請參閱「安裝自訂內容」。

    啟動 Cloud Foundry 的 Google Cloud Service Broker 應用程式

    1. 按一下左側選單中的 [Overview]
    2. 要啟動代理應用程式,請按一下 [Start]。在應用程式啟動並執行後,「Overview」頁面上將顯示綠色的「Started」和「Running」指標,如下圖所示。

      綠色的「Started」指標顯示 Google Cloud Service Broker 已啟動

      綠色的「RUNNING」指標顯示 Google Cloud Service Broker 在執行中

    3. 如果 Google Cloud Service Broker 應用程式無法啟動或顯示「Error」或「Crashed」,請檢查開發工作站中的應用程式記錄,並據此調整變數或設定。

      cf logs APP_NAME --recent
      

    註冊 Google Cloud Cloud Foundry 適用的 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. 註冊代理程式服務。

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

      其中:

    4. 驗證代理程式服務的註冊內容。

      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
      

      以下範例是針對可讀性和頁面篇幅而編輯過的,顯示市集中 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 服務清單,請參閱「開啟 Google Cloud Platform 服務代理程式 Google Cloud」。

    後續步驟

    建立 Google Cloud 服務執行個體,並將其繫結至您的 SAP BTP 應用程式。

    如要進一步瞭解如何建立及繫結 Google Cloud服務,請參閱: