เชื่อมต่อ AlloyDB กับ Oracle ผ่าน Google VPN

1. บทนำ

ในบางครั้ง คุณอาจโอนเวิร์กโหลดจากฐานข้อมูล Oracle ไปยัง AlloyDB ไม่ได้ด้วยเหตุผลหลายประการ ในกรณีดังกล่าว หากต้องการทำให้ข้อมูลพร้อมใช้งานใน AlloyDB สำหรับการรายงานหรือการประมวลผลเพิ่มเติม เราสามารถใช้ประโยชน์จาก Oracle FDW (Foreign Data Wrapper) ได้ Oracle FDW ช่วยให้คุณค้นหาข้อมูลจากฐานข้อมูล Oracle ระยะไกลและแสดงข้อมูลระยะไกลผ่านมุมมองต่างๆ ทำให้ดูเหมือนว่าข้อมูลนั้นอยู่ใน AlloyDB

ในโค้ดแล็บนี้ คุณจะได้เรียนรู้วิธีใช้ FDW ของ Oracle เพื่อเชื่อมต่อฐานข้อมูล AlloyDB กับฐานข้อมูล Oracle ที่ติดตั้งใช้งานในเครือข่ายแยกต่างหากโดยใช้บริการ VPN

f920b8427b6fccb3.png

แผนภาพด้านบนแสดงคลัสเตอร์ AlloyDB และอินสแตนซ์ GCE instance-1 ทางด้านซ้ายที่ทําให้ใช้งานได้ใน VPC เดียวกับเครือข่าย default และอินสแตนซ์ GCE ora-xe-01 ที่ทําให้ใช้งานได้ใน VPC อื่นที่มีชื่อเครือข่าย $PROJECT_ID-vpc-02 VPC แรกและ VPC ที่ 2 เชื่อมต่อกันโดยใช้ Cloud VPN ที่มีเส้นทางที่สร้างไว้แล้ว ซึ่งช่วยให้อินสแตนซ์ Oracle และ AlloyDB สื่อสารกันได้

AlloyDB ไปยัง Oracle ผ่าน VPN AlloyDB ไปยัง Oracle ผ่าน VPN

ดูข้อมูลเพิ่มเติมเกี่ยวกับส่วนขยาย Oracle FDW ได้ที่นี่

ข้อกำหนดเบื้องต้น

  • ความเข้าใจพื้นฐานเกี่ยวกับ Google Cloud Console
  • ทักษะพื้นฐานในอินเทอร์เฟซบรรทัดคำสั่งและ Google Shell
  • มีความรู้พื้นฐานเกี่ยวกับฐานข้อมูล PostgreSQL และ Oracle

สิ่งที่คุณจะได้เรียนรู้

  • วิธีติดตั้งใช้งานคลัสเตอร์ AlloyDB
  • วิธีเชื่อมต่อกับ AlloyDB
  • วิธีกำหนดค่าและติดตั้งใช้งานฐานข้อมูล Oracle ตัวอย่าง
  • วิธีตั้งค่า VPN ระหว่างเครือข่าย VPC 2 เครือข่าย
  • วิธีกำหนดค่าส่วนขยาย Oracle FDW

สิ่งที่คุณต้องมี

  • บัญชี Google Cloud และโปรเจ็กต์ Google Cloud
  • เว็บเบราว์เซอร์ เช่น Chrome

2. การตั้งค่าและข้อกำหนด

การตั้งค่าสภาพแวดล้อมแบบเรียนรู้ด้วยตนเอง

  1. ลงชื่อเข้าใช้ Google Cloud Console แล้วสร้างโปรเจ็กต์ใหม่หรือใช้โปรเจ็กต์ที่มีอยู่ซ้ำ หากยังไม่มีบัญชี Gmail หรือ Google Workspace คุณต้องสร้างบัญชี

fbef9caa1602edd0.png

a99b7ace416376c4.png

5e3ff691252acf41.png

  • ชื่อโปรเจ็กต์คือชื่อที่แสดงสำหรับผู้เข้าร่วมโปรเจ็กต์นี้ ซึ่งเป็นสตริงอักขระที่ Google APIs ไม่ได้ใช้ คุณอัปเดตได้ทุกเมื่อ
  • รหัสโปรเจ็กต์จะไม่ซ้ำกันในโปรเจ็กต์ Google Cloud ทั้งหมดและเปลี่ยนแปลงไม่ได้ (เปลี่ยนไม่ได้หลังจากตั้งค่าแล้ว) Cloud Console จะสร้างสตริงที่ไม่ซ้ำกันโดยอัตโนมัติ ซึ่งโดยปกติแล้วคุณไม่จำเป็นต้องสนใจว่าสตริงนั้นคืออะไร ใน Codelab ส่วนใหญ่ คุณจะต้องอ้างอิงรหัสโปรเจ็กต์ (โดยทั่วไปจะระบุเป็น PROJECT_ID) หากไม่ชอบรหัสที่สร้างขึ้น คุณอาจสร้างรหัสแบบสุ่มอีกรหัสหนึ่งได้ หรือคุณอาจลองใช้ชื่อของคุณเองและดูว่ามีชื่อนั้นหรือไม่ คุณจะเปลี่ยนแปลงรหัสนี้หลังจากขั้นตอนนี้ไม่ได้ และรหัสจะคงอยู่ตลอดระยะเวลาของโปรเจ็กต์
  • โปรดทราบว่ายังมีค่าที่ 3 ซึ่งคือหมายเลขโปรเจ็กต์ที่ API บางตัวใช้ ดูข้อมูลเพิ่มเติมเกี่ยวกับค่าทั้ง 3 นี้ได้ในเอกสารประกอบ
  1. จากนั้นคุณจะต้องเปิดใช้การเรียกเก็บเงินใน Cloud Console เพื่อใช้ทรัพยากร/API ของ Cloud การทำตาม Codelab นี้จะไม่มีค่าใช้จ่ายมากนัก หรืออาจไม่มีค่าใช้จ่ายเลย หากต้องการปิดทรัพยากรเพื่อหลีกเลี่ยงการเรียกเก็บเงินนอกเหนือจากบทแนะนำนี้ คุณสามารถลบทรัพยากรที่สร้างขึ้นหรือลบโปรเจ็กต์ได้ ผู้ใช้ Google Cloud รายใหม่มีสิทธิ์เข้าร่วมโปรแกรมช่วงทดลองใช้ฟรีมูลค่า$300 USD

เริ่มต้น Cloud Shell

แม้ว่าคุณจะใช้งาน Google Cloud จากระยะไกลจากแล็ปท็อปได้ แต่ใน Codelab นี้คุณจะใช้ Google Cloud Shell ซึ่งเป็นสภาพแวดล้อมบรรทัดคำสั่งที่ทำงานในระบบคลาวด์

จาก Google Cloud Console ให้คลิกไอคอน Cloud Shell ในแถบเครื่องมือด้านขวาบน

55efc1aaa7a4d3ad.png

การจัดสรรและเชื่อมต่อกับสภาพแวดล้อมจะใช้เวลาเพียงไม่กี่นาที เมื่อเสร็จแล้ว คุณควรเห็นข้อความคล้ายกับตัวอย่างต่อไปนี้

7ffe5cbb04455448.png

เครื่องเสมือนนี้มาพร้อมเครื่องมือพัฒนาซอฟต์แวร์ทั้งหมดที่คุณต้องการ โดยมีไดเรกทอรีหลักแบบถาวรขนาด 5 GB และทำงานบน Google Cloud ซึ่งช่วยเพิ่มประสิทธิภาพเครือข่ายและการตรวจสอบสิทธิ์ได้อย่างมาก คุณสามารถทำงานทั้งหมดใน Codelab นี้ได้ภายในเบราว์เซอร์ คุณไม่จำเป็นต้องติดตั้งอะไร

3. ก่อนเริ่มต้น

เปิดใช้ API

เอาต์พุต:

ใน Cloud Shell ให้ตรวจสอบว่าได้ตั้งค่ารหัสโปรเจ็กต์แล้ว

gcloud config set project [YOUR-PROJECT-ID]
PROJECT_ID=$(gcloud config get-value project)

เปิดใช้บริการที่จำเป็นทั้งหมด

gcloud services enable alloydb.googleapis.com \
                       compute.googleapis.com \
                       cloudresourcemanager.googleapis.com \
                       servicenetworking.googleapis.com \
                       vpcaccess.googleapis.com

ผลลัพธ์ที่คาดหวัง

student@cloudshell:~ (gleb-test-short-004)$ gcloud services enable alloydb.googleapis.com \
                       compute.googleapis.com \
                       cloudresourcemanager.googleapis.com \
                       servicenetworking.googleapis.com \
                       vpcaccess.googleapis.com 
Operation "operations/acf.p2-404051529011-664c71ad-cb2b-4ab4-86c1-1f3157d70ba1" finished successfully.

กำหนดค่าภูมิภาคเริ่มต้นเป็น us-central1 หรือภูมิภาคอื่นๆ ที่คุณต้องการ ใน Lab นี้ เราจะใช้ภูมิภาค us-central1

gcloud config set compute/region us-central1

4. ติดตั้งใช้งานคลัสเตอร์ AlloyDB

ก่อนสร้างคลัสเตอร์ AlloyDB เราต้องจัดสรรช่วง IP ส่วนตัวใน VPC เพื่อให้ใช้กับอินสแตนซ์ AlloyDB ในอนาคต หลังจากนั้นเราจะสร้างคลัสเตอร์และอินสแตนซ์ได้

สร้างช่วง IP ส่วนตัว

เราต้องกำหนดค่าการเข้าถึงบริการส่วนตัวใน VPC สำหรับ AlloyDB สมมติว่าเรามีเครือข่าย VPC "เริ่มต้น" ในโปรเจ็กต์และจะใช้สำหรับการดำเนินการทั้งหมด

สร้างช่วง IP ส่วนตัว

gcloud compute addresses create psa-range \
    --global \
    --purpose=VPC_PEERING \
    --prefix-length=16 \
    --description="VPC private service access" \
    --network=default

สร้างการเชื่อมต่อส่วนตัวโดยใช้ช่วง IP ที่จัดสรร

gcloud services vpc-peerings connect \
    --service=servicenetworking.googleapis.com \
    --ranges=psa-range \
    --network=default

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ gcloud compute addresses create psa-range \
    --global \
    --purpose=VPC_PEERING \
    --prefix-length=16 \
    --description="VPC private service access" \
    --network=default
Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/addresses/psa-range].

student@cloudshell:~ (test-project-402417)$ gcloud services vpc-peerings connect \
    --service=servicenetworking.googleapis.com \
    --ranges=psa-range \
    --network=default
Operation "operations/pssn.p24-4470404856-595e209f-19b7-4669-8a71-cbd45de8ba66" finished successfully.

student@cloudshell:~ (test-project-402417)$

สร้างคลัสเตอร์ AlloyDB

สร้างคลัสเตอร์ AlloyDB ในภูมิภาคเริ่มต้นโดยทำดังนี้

export PGPASSWORD=`openssl rand -hex 12`
export REGION=us-central1
export ADBCLUSTER=alloydb-aip-01
gcloud alloydb clusters create $ADBCLUSTER \
    --password=$PGPASSWORD \
    --network=default \
    --region=$REGION

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ export PGPASSWORD=`openssl rand -base64 12`
export REGION=us-central1
export ADBCLUSTER=alloydb-aip-01
gcloud alloydb clusters create $ADBCLUSTER \
    --password=$PGPASSWORD \
    --network=default \
    --region=$REGION
Operation ID: operation-1697655441138-6080235852277-9e7f04f5-2012fce4
Creating cluster...done.                                                                                                                                                                                                                                                           

จดรหัสผ่าน PostgreSQL ไว้ใช้ในอนาคต

echo $PGPASSWORD

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ echo $PGPASSWORD
bbefbfde7601985b0dee5723

สร้างอินสแตนซ์หลักของ AlloyDB

สร้างอินสแตนซ์หลักของ AlloyDB สำหรับคลัสเตอร์ของเรา

export REGION=us-central1
gcloud alloydb instances create $ADBCLUSTER-pr \
    --instance-type=PRIMARY \
    --cpu-count=2 \
    --region=$REGION \
    --cluster=$ADBCLUSTER

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ gcloud alloydb instances create $ADBCLUSTER-pr \
    --instance-type=PRIMARY \
    --cpu-count=2 \
    --region=$REGION \
    --availability-type ZONAL \
    --cluster=$ADBCLUSTER
Operation ID: operation-1697659203545-6080315c6e8ee-391805db-25852721
Creating instance...done.                                                                                                                                                                                                                                                     

5. เชื่อมต่อกับ AlloyDB

หากต้องการใช้ AlloyDB และเรียกใช้คำสั่งต่างๆ เช่น สร้างฐานข้อมูล เปิดใช้ส่วนขยาย และอื่นๆ เราต้องมีสภาพแวดล้อมการพัฒนา ซึ่งอาจเป็นเครื่องมือมาตรฐานใดก็ได้ที่ใช้ได้กับ PostgreSQL ในกรณีของเรา เราจะใช้ไคลเอ็นต์มาตรฐานสำหรับ PostgreSQL ที่ติดตั้งในกล่อง Linux

AlloyDB ได้รับการติดตั้งใช้งานโดยใช้การเชื่อมต่อแบบส่วนตัวเท่านั้น ดังนั้นเราจึงต้องใช้ VM ที่ติดตั้งไคลเอ็นต์ PostgreSQL เพื่อทำงานกับฐานข้อมูล

ติดตั้งใช้งาน GCE VM

สร้าง VM ของ GCE ในภูมิภาคและ VPC เดียวกันกับคลัสเตอร์ AlloyDB

ใน Cloud Shell ให้เรียกใช้คำสั่งต่อไปนี้

export ZONE=us-central1-a
gcloud compute instances create instance-1 \
    --zone=$ZONE \
    --scopes=https://www.googleapis.com/auth/cloud-platform

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ export ZONE=us-central1-a
student@cloudshell:~ (test-project-402417)$ gcloud compute instances create instance-1 \
    --zone=$ZONE \
    --scopes=https://www.googleapis.com/auth/cloud-platform
Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/zones/us-central1-a/instances/instance-1].
NAME: instance-1
ZONE: us-central1-a
MACHINE_TYPE: n1-standard-1
PREEMPTIBLE: 
INTERNAL_IP: 10.128.0.2
EXTERNAL_IP: 34.71.192.233
STATUS: RUNNING

ติดตั้งไคลเอ็นต์ Postgres

ติดตั้งซอฟต์แวร์ไคลเอ็นต์ PostgreSQL ใน VM ที่ติดตั้งใช้งาน

เชื่อมต่อกับ VM โดยใช้คำสั่งต่อไปนี้

gcloud compute ssh instance-1 --zone=us-central1-a

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ gcloud compute ssh instance-1 --zone=us-central1-a
Updating project ssh metadata...working..Updated [https://www.googleapis.com/compute/v1/projects/test-project-402417].                                                                                                                                                         
Updating project ssh metadata...done.                                                                                                                                                                                                                                              
Waiting for SSH key to propagate.
Warning: Permanently added 'compute.5110295539541121102' (ECDSA) to the list of known hosts.
Linux instance-1 5.10.0-26-cloud-amd64 #1 SMP Debian 5.10.197-1 (2023-09-29) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
student@instance-1:~$ 

ติดตั้งคำสั่งเรียกใช้ซอฟต์แวร์ภายใน VM โดยทำดังนี้

sudo apt-get update
sudo apt-get install --yes postgresql-client

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ sudo apt-get update
sudo apt-get install --yes postgresql-client
Get:1 https://packages.cloud.google.com/apt google-compute-engine-bullseye-stable InRelease [5146 B]
Get:2 https://packages.cloud.google.com/apt cloud-sdk-bullseye InRelease [6406 B]   
Hit:3 https://deb.debian.org/debian bullseye InRelease  
Get:4 https://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Get:5 https://packages.cloud.google.com/apt google-compute-engine-bullseye-stable/main amd64 Packages [1930 B]
Get:6 https://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:7 https://deb.debian.org/debian bullseye-backports InRelease [49.0 kB]
...redacted...
update-alternatives: using /usr/share/postgresql/13/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up postgresql-client (13+225) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+deb11u7) ...

เชื่อมต่อกับอินสแตนซ์

เชื่อมต่อกับอินสแตนซ์หลักจาก VM โดยใช้ psql

ในแท็บ Cloud Shell เดียวกันกับเซสชัน SSH ที่เปิดไปยัง VM ของอินสแตนซ์-1

ใช้ค่ารหัสผ่าน AlloyDB (PGPASSWORD) ที่จดไว้และรหัสคลัสเตอร์ AlloyDB เพื่อเชื่อมต่อกับ AlloyDB จาก GCE VM โดยทำดังนี้

export PGPASSWORD=<Noted password>
ADBCLUSTER=<your AlloyDB cluster name>
REGION=us-central1
INSTANCE_IP=$(gcloud alloydb instances describe $ADBCLUSTER-pr --cluster=$ADBCLUSTER --region=$REGION --format="value(ipAddress)")
export INSTANCE_IP=<AlloyDB Instance IP>
psql "host=$INSTANCE_IP user=postgres sslmode=require"

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ export PGPASSWORD=CQhOi5OygD4ps6ty
student@instance-1:~$ ADBCLUSTER=alloydb-aip-01
student@instance-1:~$ REGION=us-central1
student@instance-1:~$ INSTANCE_IP=$(gcloud alloydb instances describe $ADBCLUSTER-pr --cluster=$ADBCLUSTER --region=$REGION --format="value(ipAddress)")
gleb@instance-1:~$ psql "host=$INSTANCE_IP user=postgres sslmode=require"
psql (13.13 (Debian 13.13-0+deb11u1), server 14.7)
WARNING: psql major version 13, server major version 14.
         Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=> 

6. สร้างฐานข้อมูล Oracle ตัวอย่าง

เราจะติดตั้งใช้งานฐานข้อมูล Oracle ตัวอย่างใน VPC แยกต่างหากเพื่อจำลองสถานการณ์เมื่อมีการติดตั้งใช้งานในองค์กรหรือในสภาพแวดล้อมอื่นๆ ที่แยกจาก VPC ของคลัสเตอร์ AlloyDB

สร้าง VPC ที่ 2

ใช้แท็บที่เปิดอยู่ของ Cloud Shell หรือเทอร์มินัลบรรทัดคำสั่งที่มี Google Cloud SDK แล้วเรียกใช้คำสั่งต่อไปนี้

PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1
gcloud compute networks create $PROJECT_ID-vpc-02 --project=$PROJECT_ID --description=Custom\ VPC\ for\ $PROJECT_ID\ project --subnet-mode=custom --mtu=1460 --bgp-routing-mode=regional
gcloud compute networks subnets create $PROJECT_ID-vpc-02-$REGION --project=$PROJECT_ID --range=10.110.0.0/24 --stack-type=IPV4_ONLY --network=$PROJECT_ID-vpc-02 --region=$REGION

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1
gcloud compute networks create $PROJECT_ID-vpc-02 --project=$PROJECT_ID --description=Custom\ VPC\ for\ $PROJECT_ID\ project --subnet-mode=custom --mtu=1460 --bgp-routing-mode=regional
gcloud compute networks subnets create $PROJECT_ID-vpc-02-$REGION --project=$PROJECT_ID --range=10.110.0.0/24 --stack-type=IPV4_ONLY --network=$PROJECT_ID-vpc-02 --region=$REGION
Your active configuration is: [cloudshell-3726]
Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/networks/test-project-402417-vpc-02].
NAME: test-project-402417-vpc-02
SUBNET_MODE: CUSTOM
BGP_ROUTING_MODE: REGIONAL
IPV4_RANGE: 
GATEWAY_IPV4: 

Instances on this network will not be reachable until firewall rules
are created. As an example, you can allow all internal traffic between
instances as well as SSH, RDP, and ICMP by running:

$ gcloud compute firewall-rules create <FIREWALL_NAME> --network test-project-402417-vpc-02 --allow tcp,udp,icmp --source-ranges <IP_RANGE>
$ gcloud compute firewall-rules create <FIREWALL_NAME> --network test-project-402417-vpc-02 --allow tcp:22,tcp:3389,icmp

Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/subnetworks/test-project-402417-vpc-02-us-central1].
NAME: test-project-402417-vpc-02-us-central1
REGION: us-central1
NETWORK: test-project-402417-vpc-02
RANGE: 10.110.0.0/24
STACK_TYPE: IPV4_ONLY
IPV6_ACCESS_TYPE: 

กำหนดค่ากฎไฟร์วอลล์ขั้นต่ำใน VPC ที่ 2 สำหรับการวินิจฉัยพื้นฐานและการเชื่อมต่อ SSH

gcloud compute firewall-rules create $PROJECT_ID-vpc-02-allow-icmp --project=$PROJECT_ID --network=$PROJECT_ID-vpc-02 --description=Allows\ ICMP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=icmp
gcloud compute firewall-rules create $PROJECT_ID-vpc-02-allow-ssh --project=$PROJECT_ID --network=$PROJECT_ID-vpc-02 --description=Allows\ TCP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network\ using\ port\ 22. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=tcp:22

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ gcloud compute firewall-rules create $PROJECT_ID-vpc-02-allow-icmp --project=$PROJECT_ID --network=$PROJECT_ID-vpc-02 --description=Allows\ ICMP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=icmp
gcloud compute firewall-rules create $PROJECT_ID-vpc-02-allow-ssh --project=$PROJECT_ID --network=$PROJECT_ID-vpc-02 --description=Allows\ TCP\ connections\ from\ any\ source\ to\ any\ instance\ on\ the\ network\ using\ port\ 22. --direction=INGRESS --priority=65534 --source-ranges=0.0.0.0/0 --action=ALLOW --rules=tcp:22
Creating firewall...working..Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/test-project-402417-vpc-02-allow-icmp].                                                                                         
Creating firewall...done.                                                                                                                                                                                                                     
NAME: test-project-402417-vpc-02-allow-icmp
NETWORK: test-project-402417-vpc-02
DIRECTION: INGRESS
PRIORITY: 65534
ALLOW: icmp
DENY: 
DISABLED: False
Creating firewall...working..Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/test-project-402417-vpc-02-allow-ssh].                                                                                          
Creating firewall...done.                                                                                                                                                                                                                     
NAME: test-project-402417-vpc-02-allow-ssh
NETWORK: test-project-402417-vpc-02
DIRECTION: INGRESS
PRIORITY: 65534
ALLOW: tcp:22
DENY: 
DISABLED: False

กำหนดค่ากฎไฟร์วอลล์ใน VPC เริ่มต้นและ VPC ที่ 2 เพื่ออนุญาตการเชื่อมต่อระหว่างซับเน็ตภายในกับพอร์ตฐานข้อมูล

ALLOYDB_NET_IP_RANGES=$(gcloud compute networks subnets list --network=default --filter="region:us-central1" --format="value(ipCidrRange)"),$(gcloud compute addresses list --filter="name:psa-range AND network:default" --format="value(address_range())")
gcloud compute firewall-rules create default-allow-postgres --project=$PROJECT_ID --network=default --description=Allows\ Postgres\ connections\ from\ local\ networks\ to\ postgres\ instance\ on\ the\ network\ using\ port\ 5432. --direction=INGRESS --priority=65534 --source-ranges=10.110.0.0/24 --action=ALLOW --rules=tcp:5432
gcloud compute firewall-rules create $PROJECT_ID-vpc-02-allow-oracle --project=$PROJECT_ID --network=$PROJECT_ID-vpc-02 --description=Allows\ Oracle\ connections\ from\ local\ networks\ to\ Oracle\ instance\ on\ the\ network\ using\ port\ 1521. --direction=INGRESS --priority=65534 --source-ranges=$ALLOYDB_NET_IP_RANGES --action=ALLOW --rules=tcp:1521

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ ALLOYDB_NET_IP_RANGES=$(gcloud compute networks subnets list --network=default --filter="region:us-central1" --format="value(ipCidrRange)"),$(gcloud compute addresses list --filter="name:psa-range AND network:default" --format="value(address_range())")
gcloud compute firewall-rules create default-allow-postgres --project=$PROJECT_ID --network=default --description=Allows\ Postgres\ connections\ from\ local\ networks\ to\ postgres\ instance\ on\ the\ network\ using\ port\ 5432. --direction=INGRESS --priority=65534 --source-ranges=10.110.0.0/24 --action=ALLOW --rules=tcp:5432
gcloud compute firewall-rules create $PROJECT_ID-vpc-02-allow-oracle --project=$PROJECT_ID --network=$PROJECT_ID-vpc-02 --description=Allows\ Oracle\ connections\ from\ local\ networks\ to\ Oracle\ instance\ on\ the\ network\ using\ port\ 1521. --direction=INGRESS --priority=65534 --source-ranges=$ALLOYDB_NET_IP_RANGES --action=ALLOW --rules=tcp:1521
Creating firewall...working..Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/default-allow-postgres].                                                                                                  
Creating firewall...done.                                                                                                                                                                                                                     
NAME: default-allow-postgres
NETWORK: default
DIRECTION: INGRESS
PRIORITY: 65534
ALLOW: tcp:5432
DENY: 
DISABLED: False
Creating firewall...working..Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/test-project-402417-vpc-02-allow-oracle].                                                                                       
Creating firewall...done.                                                                                                                                                                                                                     
NAME: test-project-402417-vpc-02-allow-oracle
NETWORK: test-project-402417-vpc-02
DIRECTION: INGRESS
PRIORITY: 65534
ALLOW: tcp:1521
DENY: 
DISABLED: False

ทําให้ GCE VM ใช้งานได้ใน VPC ที่ 2

การติดตั้งใช้งาน GCE VM โดยใช้เครือข่ายย่อย VPC ที่ 2 สำหรับสภาพแวดล้อม Oracle ตัวอย่าง เราจะใช้อินสแตนซ์การคำนวณนี้เป็นสภาพแวดล้อม Oracle สำหรับการทดสอบ ระบบจะติดตั้งไบนารีฐานข้อมูล Oracle XE ไว้ที่นี่ และจะใช้อินสแตนซ์เป็นทั้งเซิร์ฟเวอร์และไคลเอ็นต์สำหรับงานที่เฉพาะเจาะจงของ Oracle

ใช้ Cloud Shell หรือเทอร์มินัลเดียวกันเพื่อเรียกใช้คำสั่งสร้าง VM

SERVER_NAME=ora-xe-01
PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1
ZONE=us-central1-a
MACHINE_TYPE=e2-standard-2
SUBNET=$PROJECT_ID-vpc-02-$REGION
DISK_SIZE=50
gcloud compute instances create $SERVER_NAME --project=$PROJECT_ID --zone=$ZONE --machine-type=$MACHINE_TYPE --network-interface=subnet=$SUBNET --create-disk=auto-delete=yes,boot=yes,size=$DISK_SIZE,image=projects/debian-cloud/global/images/$(gcloud compute images list --filter="family=debian-11 AND family!=debian-11-arm64" \
    --format="value(name)"),type=pd-ssd

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ SERVER_NAME=ora-xe-01
PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1
ZONE=us-central1-a
MACHINE_TYPE=e2-standard-2
SUBNET=$PROJECT_ID-vpc-02-$REGION
DISK_SIZE=50
gcloud compute instances create $SERVER_NAME --project=$PROJECT_ID --zone=$ZONE --machine-type=$MACHINE_TYPE --network-interface=subnet=$SUBNET --create-disk=auto-delete=yes,boot=yes,size=$DISK_SIZE,image=projects/debian-cloud/global/images/$(gcloud compute images list --filter="family=debian-11 AND family!=debian-11-arm64" \
    --format="value(name)"),type=pd-ssd
Your active configuration is: [cloudshell-3726]
Created [https://www.googleapis.com/compute/v1/projects/test-project-402417/zones/us-central1-a/instances/ora-xe-01].
WARNING: Some requests generated warnings:
 - Disk size: '50 GB' is larger than image size: '10 GB'. You might need to resize the root repartition manually if the operating system does not support automatic resizing. See https://cloud.google.com/compute/docs/disks/add-persistent-disk#resize_pd for details.

NAME: ora-xe-01
ZONE: us-central1-a
MACHINE_TYPE: e2-standard-2
PREEMPTIBLE: 
INTERNAL_IP: 10.110.0.2
EXTERNAL_IP: 34.121.117.216
STATUS: RUNNING

สร้าง Oracle XE

เราจะใช้ Oracle Express Edition (XE) ในการทดสอบ โปรดทราบว่าการใช้คอนเทนเนอร์ Oracle XE อยู่ภายใต้ข้อกำหนดของใบอนุญาตข้อกำหนดและเงื่อนไขการใช้งานฟรีของ Oracle

เชื่อมต่อกับ VM ที่สร้างขึ้นโดยใช้ SSH โดยใช้คำสั่งต่อไปนี้

gcloud compute ssh $SERVER_NAME --zone=$ZONE

ในเซสชัน SSH ให้ติดตั้งแพ็กเกจที่จำเป็นสำหรับการติดตั้งใช้งานประเภท Docker ของ Oracle XE คุณอ่านเกี่ยวกับตัวเลือกการติดตั้งใช้งานอื่นๆ ได้ในเอกสารประกอบของ Oracle

sudo apt-get update
sudo apt-get -y install ca-certificates curl gnupg lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER

เอาต์พุตของคอนโซลที่คาดไว้ (แก้ไขแล้ว)

student@ora-xe-01:~$ sudo apt-get update
sudo apt-get -y install ca-certificates curl gnupg lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo usermod -aG docker $USER
Get:1 https://packages.cloud.google.com/apt google-compute-engine-bullseye-stable InRelease [5146 B]
Get:2 https://packages.cloud.google.com/apt cloud-sdk-bullseye InRelease [6406 B] 
...
Setting up git (1:2.30.2-1+deb11u2) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+deb11u7) ...
student@ora-xe-01:~$ 

เชื่อมต่อกับ VM อีกครั้งโดยออกจากระบบแล้วเชื่อมต่อใหม่

exit
gcloud compute ssh $SERVER_NAME --zone=$ZONE

เอาต์พุตของคอนโซลที่คาดไว้

student@ora-xe-01:~$ exit
logout
Connection to 34.132.87.73 closed.
student@cloudshell:~ (test-project-002-410214)$ gcloud compute ssh $SERVER_NAME --zone=$ZONE
Linux ora-xe-01 5.10.0-26-cloud-amd64 #1 SMP Debian 5.10.197-1 (2023-09-29) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Jan  4 14:51:25 2024 from 34.73.112.191
student@ora-xe-01:~$

ในเซสชัน SSH ใหม่ไปยัง ora-xe-01 ให้เรียกใช้

ORACLE_PWD=`openssl rand -hex 12`
echo $ORACLE_PWD
docker run -d --name oracle-xe -p 1521:1521 -e ORACLE_PWD=$ORACLE_PWD container-registry.oracle.com/database/express:21.3.0-xe

เอาต์พุตของคอนโซลที่คาดไว้

student@ora-xe-01:~$ ORACLE_PWD=`openssl rand -hex 12`
echo $ORACLE_PWD
docker run -d --name oracle-xe -p 1521:1521 -e ORACLE_PWD=$ORACLE_PWD container-registry.oracle.com/database/express:21.3.0-xe

e36e191b6c298ce6e02a614c
Unable to find image 'container-registry.oracle.com/database/express:21.3.0-xe' locally
21.3.0-xe: Pulling from database/express
2318ff572021: Pull complete 
c6250726c822: Pull complete 
33ac5ea7f7dd: Pull complete 
753e0fae7e64: Pull complete 
Digest: sha256:dcf137aab02d5644aaf9299aae736e4429f9bfdf860676ff398a1458ab8d23f2
Status: Downloaded newer image for container-registry.oracle.com/database/express:21.3.0-xe
9f74e2d37bf49b01785338495e02d79c55c92e4ddd409eddcf45e754fd9044d9

บันทึกค่า ORACLE_PWD เพื่อใช้ในภายหลังสำหรับการเชื่อมต่อกับฐานข้อมูลในฐานะผู้ใช้ระบบและ sys

ติดตั้งสคีมาตัวอย่าง

สร้างชุดข้อมูลตัวอย่างในฐานข้อมูลที่ติดตั้งโดยใช้สคีมาตัวอย่าง HR มาตรฐาน

ในเซสชัน SSH เดียวกัน ให้ทำดังนี้

git clone https://github.com/oracle-samples/db-sample-schemas.git
curl -O https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
sudo apt-get install -y unzip openjdk-17-jdk
unzip sqlcl-latest.zip
echo 'export PATH=$HOME/sqlcl/bin:$PATH' >>.bashrc 
exec $SHELL

เอาต์พุตของคอนโซลที่คาดไว้

student@ora-xe-01:~$ git clone https://github.com/oracle-samples/db-sample-schemas.git
curl -O https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
sudo apt-get install -y unzip openjdk-17-jdk
unzip sqlcl-latest.zip
echo 'export PATH=$HOME/sqlcl/bin:$PATH' >>.bashrc 
exec $SHELL
Cloning into 'db-sample-schemas'...
remote: Enumerating objects: 624, done.
remote: Counting objects: 100% (104/104), done.
...
  inflating: sqlcl/lib/sshd-contrib.jar  
  inflating: sqlcl/lib/sshd-putty.jar  
  inflating: sqlcl/lib/dbtools-sqlcl-distribution.jar  
student@ora-xe-01:~$

ในเซสชัน SSH เดียวกัน ให้ทำดังนี้

ORACLE_PWD=<your noted password from the previous step>
cd db-sample-schemas/human_resources/
sql system/$ORACLE_PWD@localhost/XEPDB1 @hr_install.sql

ป้อนรหัสผ่านสำหรับสคีมา HR (รหัสผ่านที่รัดกุมใดก็ได้) และยอมรับตารางพื้นที่เริ่มต้นที่แนะนำในข้อความแจ้ง

เอาต์พุตของคอนโซลที่คาดไว้

student@ora-xe-01:~$ ORACLE_PWD=e36e191b6c298ce6e02a614c
student@ora-xe-01:~$ cd db-sample-schemas/human_resources/
sql system/$ORACLE_PWD@localhost/XEPDB1 @hr_install.sql


SQLcl: Release 23.3 Production on Wed Jan 03 14:38:14 2024

Copyright (c) 1982, 2024, Oracle.  All rights reserved.

Last Successful login time: Wed Jan 03 2024 14:38:17 +00:00

Connected to:
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0


Thank you for installing the Oracle Human Resources Sample Schema.
This installation script will automatically exit your database session
at the end of the installation or if any error is encountered.
The entire installation will be logged into the 'hr_install.log' log file.

Enter a password for the user HR: ************************


Enter a tablespace for HR [USERS]: 
Do you want to overwrite the schema, if it already exists? [YES|no]: 
******  Creating REGIONS table ....

Table REGIONS created.
... 
Table             provided    actual 
______________ ___________ _________ 
regions                  5         5 
countries               25        25 
departments             27        27 
locations               23        23 
employees              107       107 
jobs                    19        19 
job_history             10        10 

Thank you!                                                  
___________________________________________________________ 
The installation of the sample schema is now finished.      
Please check the installation verification output above.    
                                                            
You will now be disconnected from the database.             
                                                            
Thank you for using Oracle Database!                        
                                                            
Disconnected from Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0

สร้างผู้ใช้สำหรับ Oracle FDW

เพื่อความสะดวก เราจะสร้างผู้ใช้ POSTGRES ซึ่งเหมือนกับผู้ใช้ PostgreSQL เริ่มต้น

เชื่อมต่อกับฐานข้อมูล Oracle ในฐานะผู้ใช้ SYS

sql sys/$ORACLE_PWD@localhost/XEPDB1 as sysdba

ในเซสชัน SQL ในฐานะผู้ใช้ SYS ให้ดำเนินการ (แทนที่ POSTGRES_ORA_PWD ด้วยรหัสผ่านสำหรับผู้ใช้)

create user postgres identified by POSTGRES_ORA_PWD;

และให้สิทธิ์ที่จำเป็นแก่ผู้ใช้

grant connect, select any table to postgres;
grant select on v_$SQL_PLAN to postgres;
grant select on v_$SQL to postgres;

เอาต์พุตของคอนโซลที่คาดไว้

student@ora-xe-01:~/db-sample-schemas/human_resources$ sql sys/$ORACLE_PWD@localhost/XEPDB1 as sysdba


SQLcl: Release 23.3 Production on Wed Jan 03 14:42:37 2024

Copyright (c) 1982, 2024, Oracle.  All rights reserved.

Connected to:
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0

SQL> create user postgres identified by VeryStrongPassword0011##;

User POSTGRES created.

SQL> grant connect, select any table to postgres;

Grant succeeded.

SQL> grant select on v_$SQL_PLAN to postgres;

Grant succeeded.

SQL> grant select on v_$SQL to postgres;

Grant succeeded.

SQL> 

7. สร้าง VPN ระหว่าง VPC

ทรัพยากรที่ทําให้ใช้งานได้ในแต่ละ VPC จะเห็นเฉพาะที่อยู่ IP ภายในสําหรับเครือข่ายนั้นๆ และเชื่อมต่อกับทรัพยากรภายในใน VPC อื่นไม่ได้ Google Cloud VPN จะสร้างบริดจ์ระหว่าง VPC 2 รายการและอนุญาตให้ VM ที่มีฐานข้อมูล Oracle เชื่อมต่อและรับการเชื่อมต่อจากอินสแตนซ์ AlloyDB การเชื่อมต่อ VPN มีหลายคอมโพเนนต์ เช่น เราเตอร์ Cloud, เกตเวย์, อุโมงค์ VPN และเซสชัน BGP ในที่นี้ เราจะดูการสร้างและการกำหนดค่าคอมโพเนนต์ทั้งหมดที่จำเป็นสำหรับ VPN ที่มีความพร้อมใช้งานสูงระหว่าง VPC 2 รายการ คุณอ่านข้อมูลเพิ่มเติมเกี่ยวกับ Google Cloud VPN ได้ในเอกสารประกอบ

สร้างเราเตอร์และเกตเวย์

สร้าง Cloud Router และเกตเวย์ VPN ในทั้ง 2 VPC

ใน Cloud Shell หรือเทอร์มินัลที่มี Cloud SDK ให้เรียกใช้คำสั่งต่อไปนี้

PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1
gcloud compute routers create $PROJECT_ID-vpc-01-router --project=$PROJECT_ID --region=$REGION --network=default --asn=64520 --advertisement-mode=custom --set-advertisement-groups=all_subnets
gcloud compute routers create $PROJECT_ID-vpc-02-router --project=$PROJECT_ID --region=$REGION --network=$PROJECT_ID-vpc-02 --asn=64521 --advertisement-mode=custom --set-advertisement-groups=all_subnets

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ PROJECT_ID=$(gcloud config get-value project)
REGION=us-central1
gcloud compute routers create $PROJECT_ID-vpc-01-router --project=$PROJECT_ID --region=$REGION --network=default --asn=64520 --advertisement-mode=custom --set-advertisement-groups=all_subnets
gcloud compute routers create $PROJECT_ID-vpc-02-router --project=$PROJECT_ID --region=$REGION --network=$PROJECT_ID-vpc-02 --asn=64521 --advertisement-mode=custom --set-advertisement-groups=all_subnets
Your active configuration is: [cloudshell-18870]
Creating router [test-project-402417-vpc-01-router]...done.                                                                                                                                                                                         
NAME: test-project-402417-vpc-01-router
REGION: us-central1
NETWORK: default
Creating router [test-project-402417-vpc-02-router]...done.                                                                                                                                                                                         
NAME: test-project-402417-vpc-02-router
REGION: us-central1
NETWORK: test-project-402417-vpc-02

สร้างเกตเวย์ VPN ในทั้ง 2 VPC ดังนี้

PROJECT_ID=$(gcloud config get-value project)
gcloud compute vpn-gateways create $PROJECT_ID-vpc-01-vpn-gtw --project=$PROJECT_ID --region=$REGION --network=default
gcloud compute vpn-gateways create $PROJECT_ID-vpc-02-vpn-gtw --project=$PROJECT_ID --region=$REGION --network=$PROJECT_ID-vpc-02

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ gcloud compute vpn-gateways create $PROJECT_ID-vpc-01-vpn-gtw --project=$PROJECT_ID --region=$REGION --network=default
gcloud compute vpn-gateways create $PROJECT_ID-vpc-02-vpn-gtw --project=$PROJECT_ID --region=$REGION --network=$PROJECT_ID-vpc-02
Creating VPN Gateway...done.                                                                                                                                                                                                                  
NAME: test-project-402417-vpc-01-vpn-gtw
INTERFACE0: 35.242.106.28
INTERFACE1: 35.220.86.122
INTERFACE0_IPV6: 
INTERFACE1_IPV6: 
NETWORK: default
REGION: us-central1
Creating VPN Gateway...done.                                                                                                                                                                                                                  
NAME: test-project-402417-vpc-02-vpn-gtw
INTERFACE0: 35.242.116.197
INTERFACE1: 35.220.68.53
INTERFACE0_IPV6: 
INTERFACE1_IPV6: 
NETWORK: test-project-402417-vpc-02
REGION: us-central1
student@cloudshell:~ (test-project-402417)$ 

สร้างอุโมงค์ข้อมูล VPN

เราจะสร้างการกำหนดค่า HA ด้วยอุโมงค์ข้อมูล VPN 2 คู่สำหรับแต่ละ VPC

ใน Cloud Shell หรือเทอร์มินัลที่มี SDK ให้เรียกใช้คำสั่งต่อไปนี้

PROJECT_ID=$(gcloud config get-value project)
SHARED_SECRET=`openssl rand -base64 24`
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-01-vpn-tunnel-01 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-02-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-01-router --vpn-gateway=$PROJECT_ID-vpc-01-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=0
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-01-vpn-tunnel-02 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-02-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-01-router --vpn-gateway=$PROJECT_ID-vpc-01-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=1
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-02-vpn-tunnel-01 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-01-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-02-router --vpn-gateway=$PROJECT_ID-vpc-02-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=0
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-02-vpn-tunnel-02 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-01-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-02-router --vpn-gateway=$PROJECT_ID-vpc-02-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=1

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ SHARED_SECRET=`openssl rand -base64 24`
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-01-vpn-tunnel-01 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-02-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-01-router --vpn-gateway=$PROJECT_ID-vpc-01-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=0
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-01-vpn-tunnel-02 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-02-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-01-router --vpn-gateway=$PROJECT_ID-vpc-01-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=1
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-02-vpn-tunnel-01 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-01-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-02-router --vpn-gateway=$PROJECT_ID-vpc-02-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=0
gcloud compute vpn-tunnels create $PROJECT_ID-vpc-02-vpn-tunnel-02 --shared-secret=$SHARED_SECRET  --peer-gcp-gateway=$PROJECT_ID-vpc-01-vpn-gtw --ike-version=2 --router=$PROJECT_ID-vpc-02-router --vpn-gateway=$PROJECT_ID-vpc-02-vpn-gtw --project=$PROJECT_ID --region=$REGION --interface=1
Creating VPN tunnel...done.                                                                                                                                                                                                                   
NAME: test-project-402417-vpc-01-vpn-tunnel-01
REGION: us-central1
GATEWAY: test-project-402417-vpc-01-vpn-gtw
VPN_INTERFACE: 0
PEER_ADDRESS: 35.242.116.197
Creating VPN tunnel...done.                                                                                                                                                                                                                   
NAME: test-project-402417-vpc-01-vpn-tunnel-02
REGION: us-central1
GATEWAY: test-project-402417-vpc-01-vpn-gtw
VPN_INTERFACE: 1
PEER_ADDRESS: 35.220.68.53
Creating VPN tunnel...done.                                                                                                                                                                                                                   
NAME: test-project-402417-vpc-02-vpn-tunnel-01
REGION: us-central1
GATEWAY: test-project-402417-vpc-02-vpn-gtw
VPN_INTERFACE: 0
PEER_ADDRESS: 35.242.106.28
Creating VPN tunnel...done.                                                                                                                                                                                                                   
NAME: test-project-402417-vpc-02-vpn-tunnel-02
REGION: us-central1
GATEWAY: test-project-402417-vpc-02-vpn-gtw
VPN_INTERFACE: 1
PEER_ADDRESS: 35.220.86.122

สร้างเซสชัน BGP

เซสชัน Border Gateway Protocol (BGP) อนุญาตการกำหนดเส้นทางแบบไดนามิกโดยการแลกเปลี่ยนข้อมูลเกี่ยวกับเส้นทางที่มีอยู่ระหว่าง VPC

สร้างคู่ BGP Peer คู่แรกในเครือข่ายแรก (ค่าเริ่มต้น) ระบบจะใช้ที่อยู่ IP สำหรับเพียร์กับ BGP ที่สร้างขึ้นใน VPC ที่ 2

ใน Cloud Shell หรือเทอร์มินัลที่มี SDK ให้เรียกใช้คำสั่งต่อไปนี้

PROJECT_ID=$(gcloud config get-value project)
gcloud compute routers add-interface $PROJECT_ID-vpc-01-router --interface-name=$PROJECT_ID-vpc-01-router-bgp-if-0 --vpn-tunnel=$PROJECT_ID-vpc-01-vpn-tunnel-01 --region=$REGION
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-01-router --peer-name=$PROJECT_ID-vpc-01-vpn-tunnel-01-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-0 --peer-asn=64521 --region=$REGION
gcloud compute routers add-interface $PROJECT_ID-vpc-01-router --interface-name=$PROJECT_ID-vpc-01-router-bgp-if-1 --vpn-tunnel=$PROJECT_ID-vpc-01-vpn-tunnel-02 --region=$REGION
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-01-router --peer-name=$PROJECT_ID-vpc-01-vpn-tunnel-02-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-1 --peer-asn=64521 --region=$REGION

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ gcloud compute routers add-interface $PROJECT_ID-vpc-01-router --interface-name=$PROJECT_ID-vpc-01-router-bgp-if-0 --vpn-tunnel=$PROJECT_ID-vpc-01-vpn-tunnel-01 --region=$REGION
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-01-router --peer-name=$PROJECT_ID-vpc-01-vpn-tunnel-01-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-0 --peer-asn=64521 --region=$REGION
gcloud compute routers add-interface $PROJECT_ID-vpc-01-router --interface-name=$PROJECT_ID-vpc-01-router-bgp-if-1 --vpn-tunnel=$PROJECT_ID-vpc-01-vpn-tunnel-02 --region=$REGION
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-01-router --peer-name=$PROJECT_ID-vpc-01-vpn-tunnel-02-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-1 --peer-asn=64521 --region=$REGION
Updated [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/routers/test-project-402417-vpc-01-router].
Creating peer [test-project-402417-vpc-01-vpn-tunnel-01-bgp] in router [test-project-402417-vpc-01-router]...done.                                                                                                                                        
Updated [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/routers/test-project-402417-vpc-01-router].
Creating peer [test-project-402417-vpc-01-vpn-tunnel-02-bgp] in router [test-project-402417-vpc-01-router]...done.                                                                                                                                        
student@cloudshell:~ (test-project-402417)$

เพิ่ม BGP ใน VPC ที่ 2

REGION=us-central1
PROJECT_ID=$(gcloud config get-value project)
gcloud compute routers add-interface $PROJECT_ID-vpc-02-router --interface-name=$PROJECT_ID-vpc-02-router-bgp-if-0 --vpn-tunnel=$PROJECT_ID-vpc-02-vpn-tunnel-01 --ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[0].peerIpAddress)" --region=$REGION) --mask-length=30 --region=$REGION 
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-02-router --peer-name=$PROJECT_ID-vpc-02-vpn-tunnel-01-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-0 --peer-ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[0].ipAddress)" --region=$REGION) --peer-asn=64520 --region=$REGION
gcloud compute routers add-interface $PROJECT_ID-vpc-02-router --interface-name=$PROJECT_ID-vpc-02-router-bgp-if-1 --vpn-tunnel=$PROJECT_ID-vpc-02-vpn-tunnel-02 --ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[1].peerIpAddress)" --region=$REGION) --mask-length=30 --region=$REGION
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-02-router --peer-name=$PROJECT_ID-vpc-02-vpn-tunnel-02-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-1 --peer-ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[1].ipAddress)" --region=$REGION) --peer-asn=64520 --region=$REGION

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ REGION=us-central1
PROJECT_ID=$(gcloud config get-value project)
gcloud compute routers add-interface $PROJECT_ID-vpc-02-router --interface-name=$PROJECT_ID-vpc-02-router-bgp-if-0 --vpn-tunnel=$PROJECT_ID-vpc-02-vpn-tunnel-01 --ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[0].peerIpAddress)" --region=$REGION) --mask-length=30 --region=$REGION 
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-02-router --peer-name=$PROJECT_ID-vpc-02-vpn-tunnel-01-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-0 --peer-ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[0].ipAddress)" --region=$REGION) --peer-asn=64520 --region=$REGION
gcloud compute routers add-interface $PROJECT_ID-vpc-02-router --interface-name=$PROJECT_ID-vpc-02-router-bgp-if-1 --vpn-tunnel=$PROJECT_ID-vpc-02-vpn-tunnel-02 --ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[1].peerIpAddress)" --region=$REGION) --mask-length=30 --region=$REGION
gcloud compute routers add-bgp-peer $PROJECT_ID-vpc-02-router --peer-name=$PROJECT_ID-vpc-02-vpn-tunnel-02-bgp --interface=$PROJECT_ID-vpc-01-router-bgp-if-1 --peer-ip-address=$(gcloud compute routers describe $PROJECT_ID-vpc-01-router --format="value(bgpPeers[1].ipAddress)" --region=$REGION) --peer-asn=64520 --region=$REGION
Your active configuration is: [cloudshell-18870]
Updated [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/routers/test-project-402417-vpc-02-router].
Creating peer [test-project-402417-vpc-02-vpn-tunnel-01-bgp] in router [test-project-402417-vpc-02-router]...done.                                                                                                                                        
Updated [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/routers/test-project-402417-vpc-02-router].
Creating peer [test-project-402417-vpc-02-vpn-tunnel-02-bgp] in router [test-project-402417-vpc-02-router]...done.

เพิ่มเส้นทางที่กำหนดเองไปยัง BGP

ตอนนี้เราต้องโฆษณาช่วง IP ส่วนตัวของบริการไปยัง BGP

ใน Cloud Shell ให้เรียกใช้คำสั่งต่อไปนี้

PROJECT_ID=$(gcloud config get-value project)
gcloud compute routers update $PROJECT_ID-vpc-01-router --add-advertisement-ranges=$(gcloud compute addresses list --filter="name:psa-range AND network:default" --format="value(address_range())") --region=$REGION
gcloud compute networks peerings update servicenetworking-googleapis-com --network=default --import-custom-routes --export-custom-routes

เอาต์พุตของคอนโซลที่คาดไว้ (แก้ไขแล้ว)

PROJECT_ID=$(gcloud config get-value project)
gcloud compute routers update $PROJECT_ID-vpc-01-router --add-advertisement-ranges=$(gcloud compute addresses list --filter="name:psa-range AND network:default" --format="value(address_range())") --region=$REGION
gcloud compute networks peerings update servicenetworking-googleapis-com --network=default --import-custom-routes --export-custom-routes
...

8. กำหนดค่า Oracle FDW ใน AlloyDB

ตอนนี้เราสามารถสร้างฐานข้อมูลทดสอบและกำหนดค่าส่วนขยาย Oracle FDW ได้แล้ว เราจะใช้ VM อินสแตนซ์-1 ที่สร้างขึ้นในขั้นตอนที่ 2 และรหัสผ่านที่จดไว้สำหรับคลัสเตอร์ AlloyDB

สร้างฐานข้อมูล

เชื่อมต่อกับ GCE VM ของอินสแตนซ์-1 โดยใช้คำสั่งต่อไปนี้

ZONE=us-central1-a
gcloud compute ssh instance-1 --zone=$ZONE  

ในเซสชัน SSH ให้เรียกใช้คำสั่งต่อไปนี้

export PGPASSWORD=<Noted password>
REGION=us-central1
ADBCLUSTER=alloydb-aip-01
INSTANCE_IP=$(gcloud alloydb instances describe $ADBCLUSTER-pr --cluster=$ADBCLUSTER --region=$REGION --format="value(ipAddress)")
psql "host=$INSTANCE_IP user=postgres" -c "CREATE DATABASE quickstart_db"

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ export PGPASSWORD=6dd7fKHnMId8RM97
student@instance-1:~$ REGION=us-central1
ADBCLUSTER=alloydb-aip-01
INSTANCE_IP=$(gcloud alloydb instances describe $ADBCLUSTER-pr --cluster=$ADBCLUSTER --region=$REGION --format="value(ipAddress)")
psql "host=$INSTANCE_IP user=postgres" -c "CREATE DATABASE quickstart_db"
CREATE DATABASE
student@instance-1:~$  

กำหนดค่าส่วนขยาย FDW ของ Oracle

เปิดใช้ส่วนขยาย FDW ของ Oracle ในฐานข้อมูลที่สร้างขึ้นใหม่

ในเซสชัน SSH เดียวกัน ให้เรียกใช้คำสั่งต่อไปนี้

psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "create extension if not exists oracle_fdw cascade"

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ psql "host=$INSTANCE_IP user=postgres dbname=quickstart_db" -c "create extension if not exists oracle_fdw cascade"
CREATE EXTENSION
student@instance-1:~$ 

กำหนดค่า Oracle FDW

เราจะทำงานในเซสชัน SSH เดียวกันต่อไปเพื่อกำหนดค่า Oracle FDW ให้ทำงานกับสคีมาตัวอย่าง HR ในฐานข้อมูล Oracle

สร้างการกำหนดค่าเซิร์ฟเวอร์ FDW โดยใช้ที่อยู่ IP ภายในสำหรับ VM ของ Oracle XE ใน VPC ที่ 2

ในเซสชัน SSH เดียวกันกับอินสแตนซ์-1 ให้เรียกใช้คำสั่งต่อไปนี้

ORACLE_SERVER_IP=$(gcloud compute instances list --filter="name=(ora-xe-01)" --format="value(networkInterfaces[0].networkIP)")
psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "create server ora_xe foreign data wrapper oracle_fdw options (dbserver '$ORACLE_SERVER_IP:1521/xepdb1')"

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ ORACLE_SERVER_IP=$(gcloud compute instances list --filter="name=(ora-xe-01)" --format="value(networkInterfaces[0].networkIP)")
psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "create server ora_xe foreign data wrapper oracle_fdw options (dbserver '$ORACLE_SERVER_IP:1521/xepdb1')"
CREATE SERVER 

ให้สิทธิ์การใช้งานในเซิร์ฟเวอร์ที่สร้างแก่ผู้ใช้ postgres

psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "grant usage on foreign server ora_xe to postgres"

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "grant usage on foreign server ora_xe to postgres"
GRANT

สร้างการแมประหว่างผู้ใช้ใน PostgreSQL กับผู้ใช้ฐานข้อมูล Oracle โดยใช้รหัสผ่านที่เราตั้งค่าไว้สำหรับผู้ใช้ในฐานข้อมูล Oracle ใช้รหัสผ่านที่จดไว้สำหรับผู้ใช้ Oracle POSTGRES ที่เราสร้างไว้ก่อนหน้านี้ (POSTGRES_ORA_PWD)

POSTGRES_ORA_PWD=<your password for the oracle user postgres>
psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "CREATE USER MAPPING FOR postgres SERVER ora_xe OPTIONS ( USER 'postgres', PASSWORD '$POSTGRES_ORA_PWD')"

เอาต์พุตของคอนโซลที่คาดไว้

student@instance-1:~$ POSTGRES_ORA_PWD=VeryStrongPassword0011##
student@instance-1:~$ psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "CREATE USER MAPPING FOR postgres SERVER ora_xe OPTIONS ( USER 'postgres', PASSWORD '$POSTGRES_ORA_PWD')"
CREATE USER MAPPING

9. ใช้ Oracle FDW กับสคีมา HR

ตอนนี้เราใช้ Oracle FDW กับข้อมูลในฐานข้อมูล Oracle ได้แล้ว

นำเข้าคำจำกัดความของสคีมา HR ของ Oracle

เรายังคงทำงานบน VM ไคลเอ็นต์ Postgres โดยใช้ psql เพื่อทำงานกับ AlloyDB

ในเซสชัน SSH ของ VM ให้เรียกใช้คำสั่งต่อไปนี้

psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "create schema ora_exe_hr";
psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "import foreign schema \"HR\" from server ora_xe into ora_exe_hr";

ผลลัพธ์ที่คาดหวัง (แก้ไข)

student@instance-1:~$ psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "create schema ora_exe_hr";
psql -h $INSTANCE_IP -U postgres -d quickstart_db -c "import foreign schema \"HR\" from server ora_xe into ora_exe_hr";
CREATE SCHEMA
IMPORT FOREIGN SCHEMA
student@instance-1:~$ 

ทดสอบ Oracle FDW

มาเรียกใช้คำสั่ง SQL ตัวอย่างกัน

เชื่อมต่อกับฐานข้อมูล ในเซสชัน SSH ของ VM ให้เรียกใช้คำสั่งต่อไปนี้

psql -h $INSTANCE_IP -U postgres -d quickstart_db

เรียกใช้คำสั่ง SELECT ในเซสชัน PSQL

select * from ora_exe_hr.countries limit 5;

ผลลัพธ์ที่คาดไว้

student@instance-1:~$ psql -h $INSTANCE_IP -U postgres -d quickstart_db
psql (13.13 (Debian 13.13-0+deb11u1), server 14.7)
WARNING: psql major version 13, server major version 14.
         Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

quickstart_db=> select * from ora_exe_hr.countries limit 5;
 country_id | country_name | region_id 
------------+--------------+-----------
 AR         | Argentina    |        20
 AU         | Australia    |        40
 BE         | Belgium      |        10
 BR         | Brazil       |        20
 CA         | Canada       |        20
(5 rows)

quickstart_db=>

ซึ่งจะแสดงผลลัพธ์และหมายความว่าการกำหนดค่าของเราทำงานได้อย่างถูกต้อง

คุณสามารถทดลองใช้ตารางที่เหลือได้

10. ล้างข้อมูลในสภาพแวดล้อม

ตอนนี้เมื่อทำทุกอย่างเสร็จแล้ว เราก็สามารถล้างข้อมูลสภาพแวดล้อมโดยการทำลายคอมโพเนนต์เพื่อป้องกันการเรียกเก็บเงินที่ไม่จำเป็น

ทำลายอินสแตนซ์และคลัสเตอร์ AlloyDB เมื่อคุณทำแล็บเสร็จแล้ว

ลบคลัสเตอร์ AlloyDB และอินสแตนซ์ทั้งหมด

ระบบจะทำลายคลัสเตอร์ด้วยตัวเลือก force ซึ่งจะลบอินสแตนซ์ทั้งหมดที่เป็นของคลัสเตอร์ด้วย

ใน Cloud Shell ให้กำหนดตัวแปรโปรเจ็กต์และตัวแปรสภาพแวดล้อมหากคุณถูกตัดการเชื่อมต่อและสูญเสียการตั้งค่าก่อนหน้านี้ทั้งหมด

gcloud config set project <your project id>
export REGION=us-central1
export ADBCLUSTER=alloydb-aip-01
export PROJECT_ID=$(gcloud config get-value project)

ลบคลัสเตอร์

gcloud alloydb clusters delete $ADBCLUSTER --region=$REGION --force

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-001-402417)$ gcloud alloydb clusters delete $ADBCLUSTER --region=$REGION --force
All of the cluster data will be lost when the cluster is deleted.

Do you want to continue (Y/n)?  Y

Operation ID: operation-1697820178429-6082890a0b570-4a72f7e4-4c5df36f
Deleting cluster...done.   

ลบข้อมูลสำรองของ AlloyDB

ลบข้อมูลสำรอง AlloyDB ทั้งหมดสำหรับคลัสเตอร์

for i in $(gcloud alloydb backups list --filter="CLUSTER_NAME: projects/$PROJECT_ID/locations/$REGION/clusters/$ADBCLUSTER" --format="value(name)" --sort-by=~createTime) ; do gcloud alloydb backups delete $(basename $i) --region $REGION --quiet; done

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-001-402417)$ for i in $(gcloud alloydb backups list --filter="CLUSTER_NAME: projects/$PROJECT_ID/locations/$REGION/clusters/$ADBCLUSTER" --format="value(name)" --sort-by=~createTime) ; do gcloud alloydb backups delete $(basename $i) --region $REGION --quiet; done
Operation ID: operation-1697826266108-60829fb7b5258-7f99dc0b-99f3c35f
Deleting backup...done.                                                                                                                                                                                                                                                            

ตอนนี้เราสามารถทำลาย VM ได้แล้ว

ลบ VM ใน GCE

ใน Cloud Shell ให้เรียกใช้คำสั่งต่อไปนี้

export GCEVM=instance-1
export ZONE=us-central1-a
gcloud compute instances delete $GCEVM \
    --zone=$ZONE \
    --quiet

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-001-402417)$ export GCEVM=instance-1
export ZONE=us-central1-a
gcloud compute instances delete $GCEVM \
    --zone=$ZONE \
    --quiet
Deleted 

ลบ VM ด้วย Oracle XE

ใน Cloud Shell ให้เรียกใช้คำสั่งต่อไปนี้

SERVER_NAME=ora-xe-01
ZONE=us-central1-a
gcloud compute instances delete $SERVER_NAME \
    --zone=$ZONE \
    --quiet

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ SERVER_NAME=ora-xe-01
ZONE=us-central1-a
gcloud compute instances delete $SERVER_NAME \
    --zone=$ZONE \
    --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/zones/us-central1-a/instances/ora-xe-01].
student@cloudshell:~ (test-project-402417)$

ลบ VPN

ใน Cloud Shell ให้เรียกใช้คำสั่งต่อไปนี้

REGION=us-central1
PROJECT_ID=$(gcloud config get-value project)
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-01-vpn-tunnel-01 --region=$REGION --quiet
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-01-vpn-tunnel-02 --region=$REGION --quiet
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-02-vpn-tunnel-01 --region=$REGION --quiet
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-02-vpn-tunnel-02 --region=$REGION --quiet
gcloud compute routers delete $PROJECT_ID-vpc-02-router --region=$REGION --quiet
gcloud compute routers delete $PROJECT_ID-vpc-01-router --region=$REGION --quiet
gcloud compute vpn-gateways delete $PROJECT_ID-vpc-01-vpn-gtw --region=$REGION --quiet
gcloud compute vpn-gateways delete $PROJECT_ID-vpc-02-vpn-gtw --region=$REGION --quiet

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ REGION=us-central1
PROJECT_ID=$(gcloud config get-value project)
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-01-vpn-tunnel-01 --region=$REGION --quiet
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-01-vpn-tunnel-02 --region=$REGION --quiet
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-02-vpn-tunnel-01 --region=$REGION --quiet
gcloud compute vpn-tunnels delete $PROJECT_ID-vpc-02-vpn-tunnel-02 --region=$REGION --quiet
gcloud compute routers delete $PROJECT_ID-vpc-02-router --region=$REGION --quiet
gcloud compute routers delete $PROJECT_ID-vpc-01-router --region=$REGION --quiet
gcloud compute vpn-gateways delete $PROJECT_ID-vpc-01-vpn-gtw --region=$REGION --quiet
gcloud compute vpn-gateways delete $PROJECT_ID-vpc-02-vpn-gtw --region=$REGION --quiet
Your active configuration is: [cloudshell-18870]
Deleting VPN tunnel...done.                                                                                                                                                                                                                   
Deleting VPN tunnel...done.                                                                                                                                                                                                                   
Deleting VPN tunnel...done.                                                                                                                                                                                                                   
Deleting VPN tunnel...done.                                                                                                                                                                                                                   
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/routers/test-project-402417-vpc-02-router].
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/regions/us-central1/routers/test-project-402417-vpc-01-router].
Deleting VPN Gateway...done.                                                                                                                                                                                                                  
Deleting VPN Gateway...done.
student@cloudshell:~ (test-project-402417)$ 

ลบ VPC ที่ 2

ใน Cloud Shell ให้เรียกใช้คำสั่งต่อไปนี้

REGION=us-central1
PROJECT_ID=$(gcloud config get-value project)
gcloud compute firewall-rules delete $PROJECT_ID-vpc-02-allow-icmp --quiet
gcloud compute firewall-rules delete $PROJECT_ID-vpc-02-allow-ssh --quiet
gcloud compute firewall-rules delete default-allow-postgres --quiet
gcloud compute firewall-rules delete $PROJECT_ID-vpc-02-allow-oracle --quiet
gcloud compute networks subnets delete $PROJECT_ID-vpc-02-$REGION --region=$REGION --quiet
gcloud compute networks delete $PROJECT_ID-vpc-02 --quiet

เอาต์พุตของคอนโซลที่คาดไว้

student@cloudshell:~ (test-project-402417)$ gcloud compute firewall-rules delete $PROJECT_ID-vpc-02-allow-icmp --quiet
gcloud compute firewall-rules delete $PROJECT_ID-vpc-02-allow-ssh --quiet
gcloud compute firewall-rules delete default-allow-postgres --quiet
gcloud compute firewall-rules delete $PROJECT_ID-vpc-02-allow-oracle --quiet
gcloud compute networks subnets delete $PROJECT_ID-vpc-02-$REGION --region=$REGION --quiet
gcloud compute networks delete $PROJECT_ID-vpc-02 --quiet
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/test-project-402417-vpc-02-allow-icmp].
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/test-project-402417-vpc-02-allow-ssh].
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/default-allow-postgres].
Deleted [https://www.googleapis.com/compute/v1/projects/test-project-402417/global/firewalls/test-project-402417-vpc-02-allow-oracle].
gcloud compute networks subnets delete $PROJECT_ID-vpc-02-$REGION --region=$REGION --quiet
gcloud compute networks delete $PROJECT_ID-vpc-02 --quiet

11. ขอแสดงความยินดี

ขอแสดงความยินดีที่ทำ Codelab เสร็จสมบูรณ์

สิ่งที่เราได้พูดถึง

  • วิธีติดตั้งใช้งานคลัสเตอร์ AlloyDB
  • วิธีเชื่อมต่อกับ AlloyDB
  • วิธีกำหนดค่าและติดตั้งใช้งานฐานข้อมูล Oracle ตัวอย่าง
  • วิธีตั้งค่า VPN ระหว่างเครือข่าย VPC 2 เครือข่าย
  • วิธีกำหนดค่าส่วนขยาย Oracle FDW

12. แบบสำรวจ

เอาต์พุต:

คุณจะใช้บทแนะนำนี้อย่างไร

อ่านผ่านๆ อ่านและทำแบบฝึกหัด