๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ์—์„œ ์†Œ์Šค ๋น„๊ณต๊ฐœ IP ์—ฐ๊ฒฐ ์‚ฌ์šฉ

์ด ํŽ˜์ด์ง€์—์„œ๋Š” ์ด๊ธฐ์ข… Oracle ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์˜ ์†Œ์Šค ๋น„๊ณต๊ฐœ ์—ฐ๊ฒฐ์„ ์šฉ์ดํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด Compute Engine ๊ฐ€์ƒ ๋จธ์‹  (VM)์— ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

๋น„๊ณต๊ฐœ ์—ฐ๊ฒฐ ๊ตฌ์„ฑ์„ ๋งŒ๋“œ๋Š” Virtual Private Cloud ๋„คํŠธ์›Œํฌ์™€ ๋‹ค๋ฅธ Virtual Private Cloud ๋„คํŠธ์›Œํฌ์— ์žˆ๋Š” ์†Œ์Šค์™€ ํ•จ๊ป˜ ๋น„๊ณต๊ฐœ IP ์—ฐ๊ฒฐ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ VM์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์„ค์ •

ํ”„๋ก์‹œ๋ฅผ ํ˜ธ์ŠคํŒ…ํ•  Compute Engine VM์„ ๋งŒ๋“ค๋ ค๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ๋”ฐ๋ฅด์„ธ์š”.

  1. Compute Engine์—์„œ Linux VM ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
  2. ๋จธ์‹ ์— ์—ฐ๊ฒฐํ•œ ํ›„ ํŠธ๋ž˜ํ”ฝ์„ ์ „๋‹ฌํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ iptables ๋ผ์šฐํŒ…์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‹ค์Œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์•„๋ž˜์˜ ๋ช…๋ น์–ด ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— ๋‹ค์Œ์„ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.

    • SOURCE_PRIVATE_IP๋ฅผ ์†Œ์Šค ์ธ์Šคํ„ด์Šค์˜ ๋น„๊ณต๊ฐœ IP ์ฃผ์†Œ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    • PORT์„ ์†Œ์Šค Oracle ์ธ์Šคํ„ด์Šค๊ฐ€ ์—ฐ๊ฒฐ์„ ๋ฆฌ์Šจํ•˜๋Š” ํฌํŠธ ๋ฒˆํ˜ธ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    #! /bin/bash
    
    export DB_ADDR=SOURCE_PRIVATE_IP
    export DB_PORT=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

    ์ด์ œ ํ”„๋ก์‹œ VM์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์†Œ์Šค ์—ฐ๊ฒฐ์— ํ•„์š”ํ•œ ๋‚˜๋จธ์ง€ ๋‹จ๊ณ„๋ฅผ ๊ณ„์† ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ๋‹จ๊ณ„