本頁說明如何在 Compute Engine 虛擬機器 (VM) 上設定反向 Proxy,以便為各種 Oracle 遷移作業提供來源私人連線。
如果您想使用 私人 IP 連線,且來源位於與 建立私人連線設定的虛擬私有雲網路不同的網路,就必須使用反向 Proxy VM。
設定反向 Proxy
如要建立 Compute Engine VM 來代管 Proxy,請按照下列步驟操作:
- 在 Compute Engine 中建立 Linux VM 執行個體。
-
連線至機器後,請建立必要的
iptables
路由來轉送流量。您可以使用下列指令碼。使用下列任何指令資料之前,請先替換以下項目:
- SOURCE_PRIVATE_IP 與來源執行個體的私人 IP 位址。
- PORT 與來源 Oracle 例項監聽連線的通訊埠編號。
#! /bin/bash export DB_ADDR=SOURCE_PRIVATE_IP export DB_PORT=DATABASE_PORT # Enable the VM to receive packets whose destinations do # not match any running process local to the VM echo 1 > /proc/sys/net/ipv4/ip_forward # Ask the Metadata server for the IP address of the VM nic0 # network interface: md_url_prefix="http://169.254.169.254/computeMetadata/v1/instance" vm_nic_ip="$(curl -H "Metadata-Flavor: Google" ${md_url_prefix}/network-interfaces/0/ip)" # Clear any existing iptables NAT table entries (all chains): iptables -t nat -F # Create a NAT table entry in the prerouting chain, matching # any packets with destination database port, changing the destination # IP address of the packet to your source instance IP address: iptables -t nat -A PREROUTING \ -p tcp --dport $DB_PORT \ -j DNAT \ --to-destination $DB_ADDR # Create a NAT table entry in the postrouting chain, matching # any packets with destination database port, changing the source IP # address of the packet to the NAT VM's primary internal IPv4 address: iptables -t nat -A POSTROUTING \ -p tcp --dport $DB_PORT \ -j SNAT \ --to-source $vm_nic_ip # Save iptables configuration: iptables-save
您的 Proxy VM 現已執行。請繼續執行來源連線所需的其他步驟。
後續步驟
進一步瞭解來源連線方法。請參閱 來源連線方法總覽。
如需完整的逐步遷移操作說明,請參閱 Oracle 到 PostgreSQL 適用的 AlloyDB 遷移指南。