本頁面說明如何在開發管道時,從私人 Cloud Data Fusion 執行個體連線至 Salesforce 等軟體即服務 (SaaS) 應用程式,以及 Amazon S3 等第三方雲端服務。
本指南中會使用「輸出」和「輸出控制項」等字詞:
輸出是指透過公開網際網路 Google Cloud 傳出的網路流量。通常,當您建立管道來讀取或寫入 Salesforce 等 SaaS 服務,或 Amazon S3 等公用雲端服務時,就會發生出口。
輸出控制會使用 Proxy VM 定義輸出流量的防護機制,讓輸出流量傳送至一組預先設定的網域時成功,而其他所有流量則失敗。這可為輸出流量提供更高的安全邊界,並可防止私人執行個體的輸出流量遭到濫用。
下列系統架構圖顯示,在開發管道時,私人 Cloud Data Fusion 執行個體如何連線至公開網際網路:
在這種情況下設計管道時,Cloud Data Fusion 會透過 Cloud Data Fusion 預覽或 Wrangler 中的客戶專案,將出站流量重新導向。這項程序會使用下列資源:
自訂 VPC 網路路徑:自訂 VPC 網路會透過匯入的自訂路徑將流量轉送至閘道 VM,然後使用 VPC 對等互連匯出至租用戶專案的 VPC。
閘道 VM:閘道 VM 會將 Cloud Data Fusion 租用戶專案的傳出流量,透過公用網際網路路由至 SaaS 或第三方雲端服務。 Google Cloud 您可以在客戶專案中管理這個 VM。您可以在高可用性 (HA) 環境中使用內部負載平衡器 (ILB) 進行設定。建議您在同一個 VPC 中,為多個私人 Cloud Data Fusion 執行個體重複使用 VM。
如要瞭解如何在設計和執行環境中設定出口控制,請參閱「在私人執行個體中控制出口」。
事前準備
您可以在 Cloud Data Fusion 6.4 以上版本中,從私人執行個體連線至公開來源。如要使用其中一個版本,您可以建立新的私人 Cloud Data Fusion 執行個體,或將現有執行個體升級至 6.4.0。
為執行個體建立虛擬私有雲端對等互連連線時,請選取「Export routes」。
設定網際網路連線
以下步驟說明如何透過 Wrangler 中的私人 Cloud Data Fusion 執行個體存取 Amazon S3 值區。在 Preview 或 Wrangler 中設計管道時,透過公用網際網路存取任何資料來源時,也適用相同的步驟。
本指南只使用單一 VM,但對於任務關鍵應用程式,建議您建立負載平衡 VM。詳情請參閱「設定高可用性 VM」。
建立網路位址轉譯 (NAT) 閘道
在與 Cloud Data Fusion 私人執行個體相同的區域和虛擬私有雲網路中,建立 Cloud NAT 閘道。
建立閘道 VM 執行個體和防火牆規則
控制台
前往「VM instances」(VM 執行個體) 頁面。
按一下「Create instance」(建立執行個體)。建議使用沒有外部 IP 的 VM。
使用與私人 Cloud Data Fusion 執行個體設定網路對等互連的相同 VPC。如要進一步瞭解此情境中的虛擬私有雲網路對等互連,請參閱「事前準備」。
為與 Cloud Data Fusion 執行個體位於相同網路的執行個體啟用 IP 轉送。
在「Startup script」(開機指令碼) 欄位中輸入下列指令碼:
#! /bin/bash echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -j MASQUERADE echo net.ipv4.ip_forward=1 > /etc/sysctl.d/11-gce-network-security.conf iptables-save
詳情請參閱「執行啟動指令碼」。
如要取得 Cloud Data Fusion 執行個體的已分配 IP 範圍,請前往 Cloud Data Fusion「Instance details」(執行個體詳細資料) 頁面。
gcloud
如要建立閘道 VM 和防火牆規則,請在 Google Cloud CLI 中執行下列指令碼:
export CDF_PROJECT=CDF_PROJECT export GATEWAY_VM=GATEWAY_VM_NAME export ZONE=VM_ZONE export SUBNET=SUBNET export VPC_NETWORK=VPC_NETWORK export COMPUTE_ENGINE_SA=COMPUTE_ENGINE_SA gcloud beta compute --project=$CDF_PROJECT instances create $GATEWAY_VM --zone=$ZONE --machine-type=e2-medium --subnet=$SUBNET --network-tier=PREMIUM --metadata=startup-script=\#\!\ /bin/bash$'\n'echo\ 1\ \>\ /proc/sys/net/ipv4/ip_forward$'\n'iptables\ -t\ nat\ -A\ POSTROUTING\ -s\ 0.0.0.0/0\ -j\ MASQUERADE$'\n'echo\ net.ipv4.ip_forward=1\ \>\ /etc/sysctl.d/11-gce-network-security.conf$'\n'iptables-save --can-ip-forward --no-address --maintenance-policy=MIGRATE --service-account=$COMPUTE_ENGINE_SA --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --tags=http-server,https-server --image=debian-10-buster-v20210316 --image-project=debian-cloud --boot-disk-size=10GB --boot-disk-type=pd-balanced --boot-disk-device-name=$GATEWAY_VM --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any gcloud compute --project=$CDF_PROJECT firewall-rules create egress-allow-http --direction=INGRESS --priority=1000 --network=$VPC_NETWORK --action=ALLOW --rules=tcp:80 --source-ranges=CDF_IP_RANGE --target-tags=http-server gcloud compute --project=$CDF_PROJECT firewall-rules create egress-allow-https --direction=INGRESS --priority=1000 --network=$VPC_NETWORK --action=ALLOW --rules=tcp:443 --source-ranges=CDF_IP_RANGE --target-tags=https-server
更改下列內容:
- CDF_PROJECT:可自訂的專案專屬 ID
- GATEWAY_VM:要設定的 VM 名稱
- ZONE:VM 的可用區
- SUBNET:子網路
- VPC_NETWORK:VM 名稱
- COMPUTE_ENGINE_SA:Compute Engine 服務帳戶名稱
- CDF_IP_RANGE:分配給 Cloud Data Fusion 執行個體的 IP 範圍
使用共用虛擬私有雲
如果您使用共用虛擬私有雲將私人 Cloud Data Fusion 執行個體連結至公開網際網路上的來源,請在主專案中建立閘道 VM,並在該專案中設定虛擬私有雲網路對等互連與租用戶專案。
建立自訂路徑
建立自訂路徑,連線至您建立的閘道 VM 執行個體。
控制台
如要在 Google Cloud 控制台中建立路徑,請參閱「新增靜態路徑」。
設定路徑時:
- 將「Priority」設為大於或等於
1001
。將目的地設為分配給 Cloud Data Fusion 執行個體的 IP 範圍。 - 使用與私人 Cloud Data Fusion 執行個體相同的專案和 VPC。
- 請確認 VPC 網路對等互連設定允許匯出路徑,以便 Cloud Data Fusion 租用戶專案 VPC 透過 VPC 網路對等互連匯入這條自訂路徑。
gcloud
如要在 gcloud CLI 中建立路徑,請按照下列步驟操作:
export ROUTE=ROUTE gcloud beta compute routes create $ROUTE --project=$CDF_PROJECT \ --network=$VPC_NETWORK --priority=1001 \ --destination-range=0.0.0.0/0 \ --next-hop-instance=$GATEWAY_VM \ --next-hop-instance-zone=$ZONE
更改下列內容:
- ROUTE:自訂路徑的名稱。
驗證設定
完成上述步驟後,請確認您可以在預先發布版和 Wrangler 中存取 S3 值區服務 (或其他 SaaS 或公有雲服務)。
設定高可用性的閘道
建議:對於重要應用程式,建議您建立負載平衡 VM。
為健康狀態檢查建立防火牆規則
建立防火牆規則,允許下列作業:
- 所有來源範圍的通訊埠 80 (HTTP) 和 443 (HTTPS)。
來自健康狀態檢查探測器 IP 位址的 TCP、UDP 和 ICMP 流量。例如:
130.211.0.0/22,35.191.0.0/16
。
控制台
建立防火牆規則,允許來自所有來源範圍的通訊埠,以及防火牆規則,允許來自健康狀態檢查探測器 IP 位址 (例如 130.211.0.0/22,35.191.0.0/16
) 的 TCP、UDP 和 ICMP 流量。
請參閱「建立健康狀態檢查」。
gcloud
建立健康狀態檢查的防火牆規則:
export CDF_PROJECT=PROJECT_ID export VPC_NETWORK=VPC_NETWORK gcloud compute --project=$CDF_PROJECT firewall-rules create vpc-allow-http \ --direction=INGRESS --priority=1000 \ --network=$VPC_NETWORK \ --action=ALLOW --rules=tcp:80 \ --source-ranges=CDF_IP_RANGE \ --target-tags=http-server gcloud compute --project=$CDF_PROJECT firewall-rules create vpc-allow-https \ --direction=INGRESS --priority=1000 --network=$VPC_NETWORK \ --action=ALLOW --rules=tcp:443 --source-ranges=CDF_IP_RANGE \ --target-tags=https-server gcloud compute --project=$CDF_PROJECT firewall-rules create allow-health-checks \ --network=$VPC_NETWORK \ --action=allow --direction=ingress \ --target-tags=allow-health-checks \ --source-ranges=130.211.0.0/22,35.191.0.0/16 \ --rules=tcp,udp,icmp
更改下列內容:
- PROJECT_ID:專案的可自訂專屬 ID。
- VPC_NETWORK:虛擬私有雲網路名稱。
- CDF_IP_RANGE:分配給 Cloud Data Fusion 的 IP 位址範圍。
建立閘道 VM 執行個體範本
控制台
在控制台中建立執行個體範本時:
- 請在與 Cloud Data Fusion 執行個體相同的 VPC 中建立。
- 建議:使用具有私人 IP 位址的 VM。
- 啟用 HTTP/HTTPS 通訊埠。
- 啟用 IP 轉送
在「Startup script」(開機指令碼) 欄位中輸入下列指令碼:
#! /bin/bash echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -j MASQUERADE echo net.ipv4.ip_forward=1 > /etc/sysctl.d/11-gce-network-security.conf iptables-save
詳情請參閱「執行啟動指令碼」。
如要取得 Cloud Data Fusion 執行個體的已分配 IP 範圍,請前往 Cloud Data Fusion「Instance details」(執行個體詳細資料) 頁面。
gcloud
建立執行個體範本:
export TEMPLATE_NAME=TEMPLATE_NAME export REGION=REGION export SUBNET=SUBNET export SERVICE_ACCOUNT=SERVICE_ACCOUNT gcloud beta compute --project=$CDF_PROJECT instance-templates create $TEMPLATE_NAME \ --machine-type=e2-medium \ --subnet=projects/$CDF_PROJECT/regions/$REGION/subnetworks/$SUBNET \ --network-tier=PREMIUM --metadata=startup-script=sudo\ bash\ -c\ \"echo\ 1\ \>\ /proc/sys/net/ipv4/ip_forward\"$'\n'sudo\ iptables\ -t\ nat\ -A\ POSTROUTING\ -s\ 0.0.0.0/0\ -j\ MASQUERADE$'\n'sudo\ bash\ -c\ \"echo\ net.ipv4.ip_forward=1\ \>\ /etc/sysctl.d/11-gce-network-security.conf\"$'\n'sudo\ iptables-save \ --can-ip-forward --no-address --maintenance-policy=MIGRATE \ --service-account=$SERVICE_ACCOUNT \ --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append \ --region=$REGION --tags=http-server,https-server,allow-health-checks \ --image=debian-10-buster-v20210316 \ --image-project=debian-cloud --boot-disk-size=10GB \ --boot-disk-type=pd-balanced \ --boot-disk-device-name=$TEMPLATE_NAME \ --no-shielded-secure-boot --no-shielded-vtpm \ --no-shielded-integrity-monitoring \ --reservation-affinity=any
建立健康狀態檢查
這個閘道 VM 執行個體上沒有任何服務在執行,因此您可以使用通訊埠 22
進行健康狀態檢查。
控制台
請參閱「建立健康狀態檢查」。
gcloud
建立健康狀態檢查:
export HEATH_CHECK=HEALTH_CHECK_NAME gcloud beta compute health-checks create tcp $HEATH_CHECK --project=$CDF_PROJECT \ --port=22 --proxy-header=NONE --no-enable-logging \ --check-interval=5 --timeout=5 \ --unhealthy-threshold=2 --healthy-threshold=2
建立執行個體群組
使用先前步驟中建立的健康狀態檢查,建立執行個體群組:
控制台
請參閱「建立代管執行個體群組」一文。
gcloud
建立執行個體群組:
export INSTANCE_GROUP=INSTANCE_GROUP gcloud beta compute --project=$CDF_PROJECT instance-groups managed create $INSTANCE_GROUP \ --base-instance-name=$INSTANCE_GROUP \ --template=$TEMPLATE_NAME --size=1 --zone=$ZONE \ --health-check=test --initial-delay=300 gcloud beta compute --project "$CDF_PROJECT" instance-groups managed set-autoscaling "$INSTANCE_GROUP" \ --zone "$ZONE" --cool-down-period "60" \ --max-num-replicas "10" --min-num-replicas "1" \ --target-cpu-utilization "0.6" --mode "on"
建立負載平衡器
從上一個步驟建立的執行個體群組建立 TCP 負載平衡器 (ILB)。
將自訂路徑新增至負載平衡器
將自訂路徑新增至與 Cloud Data Fusion 執行個體位於相同 VPC 的內部負載平衡器 (ILB)。
控制台
前往「VPC 網路」頁面。
在「路徑」分頁中,按一下「建立路徑」。
gcloud
將自訂路徑新增至內部負載平衡器:
export ROUTE=ROUTE_NAME export ILB_FRONTEND=<ip_of_ilb_frontend> gcloud beta compute routes create $ROUTE --project=$CDF_PROJECT \ --network=$VPC_NETWORK --priority=1001 \ --destination-range=0.0.0.0/0 \ --next-hop-ilb=$ILB_FRONTEND \ --next-hop-ilb-region=$REGION
疑難排解
在預覽或 Wrangler 中收到連線逾時錯誤
設定出口控管時,您可能會收到 Connection Timeout
錯誤。
如要修正這個問題,請確認已完成下列設定:
執行個體群組健康狀態檢查失敗
請確認有防火牆規則,允許來自 130.211.0.0/22,35.191.0.0/16
來源範圍的 TCP、UDP 和 ICMP 流量。
在 Dataproc 中執行時,管道失敗
如要在執行期間存取公開網際網路,請在與 Dataproc 叢集相同的區域和網路中啟用 Cloud NAT。
後續步驟
- 瞭解如何控制私人 Cloud Data Fusion 執行個體的傳出連線,只允許特定網域。
- 進一步瞭解 Cloud Data Fusion 中的網路。