gRPC 直接連線

直接連線解決方案可讓 Google Cloud 用戶端程式庫與 Cloud Storage 之間建立經過驗證的直接 gRPC 網路連線,進而降低延遲和連線負擔,使用 gRPC 透過直接連線連線至 Google Cloud 時,透過支援的 Google Cloud 用戶端程式庫發出的要求會直接傳送至 Cloud Storage,略過 Google Front Ends (GFE)

只有從 Compute Engine 虛擬機器 (VM) 發出的要求,才能直接連線。

直接連線需求

使用支援的 Cloud Storage 用戶端程式庫連線至 Cloud Storage 時,系統預設會啟用直接連線,但必須符合下列所有條件,才能使用這項功能:

  • 與 Cloud Storage 互動的 Compute Engine VM 必須附加服務帳戶,即使服務帳戶沒有任何權限也一樣。服務帳戶會在應用程式層傳輸層安全標準 (ALTS) 交握程序中,代表 Compute Engine VM。

  • 與 Cloud Storage 值區互動的 Compute Engine VM 必須與該值區位於同一位置。舉例來說,如果值區位於 us-central1,VM 可以位於 us-central1-a

  • 您的路徑防火牆規則允許 IPv4 流量傳送至 34.126.0.0/18,以及 IPv6 流量傳送至 2001:4860:8040::/42。此外,流量必須能連上端點 storage.googleapis.com:443directpath-pa.googleapis.com:443

    如要瞭解如何檢查是否能連線至這些端點,請參閱「檢查網路設定」。如要瞭解如何設定路徑,請參閱「設定路徑」。

使用 Google Cloud CLI 檢查連線

Google Cloud CLI 可將 2 位元組的物件上傳至 bucket,然後刪除該物件,藉此測試 bucket 的直接連線診斷。本節說明如何使用 Google Cloud CLI 執行直接連線的診斷測試。

事前準備

  1. 請確認您在值區中具備下列 IAM 權限,這些權限可使用 Storage 物件使用者 (roles/storage.objectUser) 角色授予

    • storage.objects.create
    • storage.objects.delete
    • storage.objects.get
  2. gcloud alpha storage diagnose 指令僅適用於 Google Cloud CLI 531.0.0 以上版本。如要使用這項指令,建議升級至最新版 Google Cloud CLI

執行診斷

如要檢查是否可直接連線,請使用 --test-type=DIRECT_CONNECTIVITY 引數執行 gcloud alpha storage diagnose

gcloud alpha storage diagnose --test-type=DIRECT_CONNECTIVITY gs://BUCKET_NAME

更改下列內容:

  • BUCKET_NAME:值區名稱。例如:my-bucket

如果可以建立連線,您會收到類似以下的回應:

Using my-bucket bucket for the diagnostic tests.
Bucket location : US
Bucket storage class : STANDARD
Running diagnostic: Direct Connectivity Diagnostic...
WARNING: This diagnostic is experimental. The output may change, and checks may be added or removed at any time. Please do not rely on the diagnostic being present.
Finished running diagnostic: Direct Connectivity Diagnostic
Generating diagnostic report...
NAME
Direct Connectivity Diagnostic
    ┌────────────────────────────┬─────────────────────────────────────────────────────────────────────────┬──────────┐
    │            NAME            │                           PAYLOAD_DESCRIPTION                           │  RESULT  │
    ├────────────────────────────┼─────────────────────────────────────────────────────────────────────────┼──────────┤
    │ Direct Connectivity Upload │ Able to upload object to bucket using Direct Connectivity network path. │ Success. │
    └────────────────────────────┴─────────────────────────────────────────────────────────────────────────┴──────────┘

檢查網路設定

如果使用 Google Cloud CLI 檢查直接連線時發生 Unable to connect to Traffic Director 錯誤,請按照下列操作說明,確保網路設定允許流量從 VM 傳輸至必要端點。

如要直接連線,必須在 directpath-pa.googleapis.com:443storage.googleapis.com:443 代管服務。如要檢查是否能連線至服務,請對 directpath-pa.googleapis.com:443storage.googleapis.com:443 進行 curl 呼叫。例如:

curl directpath-pa.googleapis.com:443

如果可以建立連線,您會收到空白回應,且沒有錯誤:

curl: (52) Empty reply from server

如果無法建立連線,您會收到類似下列內容的錯誤:

curl: (56) Recv failure: Connection reset by peer