Virtual IP - cra16/overcast GitHub Wiki

์†Œ๊ฐœ

ํด๋ผ์šฐ๋“œ ์ธํ”„๋ผ๋ฅผ ๊ตฌ์ถ•ํ•˜๋ ค๋‹ค ๋ณด๋ฉด, ๊ฐ€์ƒ์˜ IP๋ฅผ ํ• ๋‹นํ•ด์•ผ ํ•  ํ•„์š”๊ฐ€ ์ž์ฃผ ์ƒ๊ธด๋‹ค. ์ด ๋ฌธ์„œ์—์„œ๋Š” ๊ฐ€์ƒ์˜ IP๋ฅผ ํ• ๋‹นํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์—ฐ๊ตฌํ•ด๋ณธ๋‹ค. ๊ธฐ๋ณธ ํ™˜๊ฒฝ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • ์šด์˜์ฒด์ œ: Ubuntu 12.04
  • ํ•˜์ดํผ๋ฐ”์ด์ €: virtualbox
  • ๊ฒŒ์ŠคํŠธ ์šด์˜์ฒด์ œ: Ubuntu 12.04

๊ฐ€์ƒ IP

ํ…Œ์ŠคํŠธ ๋ฐฉ์•ˆ

Virtualbox๋ฅผ ์ด์šฉํ•ด์„œ ๊ฐ€์ƒ IP๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•œ ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•๋“ค์„ ํ…Œ์ŠคํŠธํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค. Guest ์šด์˜์ฒด์ œ์— ๊ฐ€์ƒ IP ์„ค์ •์„ ํ•œ ๋‹ค์Œ์— ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ ํ˜น์€ ๋‹ค๋ฅธ ๊ฒŒ์ŠคํŠธ ์šด์˜์ฒด์ œ์—์„œ ๊ฐ€์ƒ IP๋กœ ๋„คํŠธ์›Œํ‚น์ด ์ž˜ ๋˜๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.

VIP

VIP๋Š” ํ•˜๋‚˜์˜ ํ˜ธ์ŠคํŠธ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ IP ์ฃผ์†Œ๋ฅผ ํ• ๋‹นํ•˜๋Š” ๊ธฐ์ˆ ์ด๋‹ค. ์ด ๊ธฐ์ˆ ์„ ์ด์šฉํ•˜๋ฉด, ํ•˜๋‚˜์˜ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ IP ์ฃผ์†Œ๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋‹ค. ๋ฐ”๊นฅ์—์„œ๋Š” ๋งˆ์น˜ ํ•˜๋‚˜ ์ด์ƒ์˜ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ผ ๊ฒƒ์ด๋‹ค.

VIP๋Š” ํ”ํžˆ HA๋‚˜ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์„ ์œ„ํ•ด์„œ ๋„๋ฆฌ ์‚ฌ์šฉ๋œ๋‹ค.

HA์—์„œ์˜ VIP ์‚ฌ์šฉ

์›น ์„œ๋น„์Šค๋ฅผ ์˜ˆ๋กœ ๋“ค์–ด๋ณด์ž. ์ค‘์š” ์„œ๋น„์Šค์˜ ๊ฒฝ์šฐ์—๋Š” ํ•˜๋‚˜์˜ ์›น ์„œ๋ฒ„์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋”๋ผ๋„ ์›น ์„œ๋น„์Šค์—๋Š” ๋ฌธ์ œ๊ฐ€ ์—†์–ด์•ผ ํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ๋ณดํ†ต์€ ๋‘๋Œ€์˜ ํ˜ธ์ŠคํŠธ๋ฅผ Active - Standby ํ˜•ํƒœ์˜ HA๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. ์ด ๋‘ ํ˜ธ์ŠคํŠธ๋Š” Heartbeat ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์ด์šฉํ•ด์„œ ์„œ๋กœ์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‹ค๊ฐ€ Active ํ˜ธ์ŠคํŠธ์— ์–ด๋–ค ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋ฉด standby๊ฐ€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด ํ˜ธ์ŠคํŠธ๋ฅผ ๋Œ€์‹ ํ•ด์„œ Active ํ˜ธ์ŠคํŠธ๊ฐ€ ๋˜๊ณ , ์„œ๋น„์Šค๋ฅผ ๊ณ„์†ํ•œ๋‹ค.

์ด๋Ÿฐ HA ๊ตฌ์„ฑ์—์„œ ์›ํ• ํ•œ ์›น ์„œ๋น„์Šค๋ฅผ ์œ„ํ•ด์„œ๋Š” ๋‘ ํ˜ธ์ŠคํŠธ๊ฐ€ ๋™์ผํ•œ IP๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์„ ํ•„์š”๊ฐ€ ์žˆ๋‹ค. ์ด๋•Œ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ VIP๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ตฌ์„ฑ์„ ๊ฐ€์ง„๋‹ค.

  • Host A๋Š” Active ์ƒํƒœ๋กœ ์ž‘๋™์„ ํ•œ๋‹ค. ์ด Host A๋Š” ๋ฌผ๋ฆฌ์  ์ธํ„ฐํŽ˜์ด์Šค์˜ ์‹ค์ œ ์•„์ดํ”ผ๊ฐ€ ์•„๋‹Œ VIP๋ฅผ ์ด์šฉํ•ด์„œ ์„œ๋น„์Šค ํ•œ๋‹ค. VIP์˜ ์ฃผ์†Œ๋ฅผ 172.26.5.100์ด๋ผ๊ณ  ๊ฐ€์ •ํ•˜์ž. ์œ ์ €๋Š” 172.26.7.100 ์œผ๋กœ ์ ‘์†ํ•ด์„œ ์„œ๋น„์Šค๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.
  • Host B๋Š” Standby ์ƒํƒœ๋กœ ์ž‘๋™์„ ํ•˜๋Š”๋ฐ, ์ฃผ๊ธฐ์ ์œผ๋กœ Host A์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•œ๋‹ค.
  • ๋งŒ์•ฝ Host A์— ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ์„œ ์„œ๋น„์Šค๋ฅผ ํ•  ์ˆ˜ ์—†๋‹ค๋ฉด Host A์˜ VIP๋ฅผ down ํ•œ ํ›„, Host B์— 172.26.7.100์˜ VIP๋ฅผ up ํ•œ๋‹ค.
  • ์ด์ œ ์œ ์ €๋Š” Host B์— ์ ‘์†ํ•ด์„œ ์„œ๋น„์Šค๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

VIP ์„ค์ •

VIP ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด์„œ ๋‘ ๊ฐœ์˜ ๊ฒŒ์ŠคํŠธ ์šด์˜์ฒด์ œ๋ฅผ ์ค€๋น„ํ–ˆ๋‹ค. ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ๋„คํŠธ์›Œํฌ : 192.168.56.0/24
  • ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ์˜ IP : 192.168.56.1
  • ๊ฒŒ์ŠคํŠธ ์šด์˜์ฒด์ œ์˜ IP
  • Guest01 : 192.168.56.253
  • Guest02 : 192.168.56.254
  • ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉํ•  VIP : 192.168.56.100

Guest01์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด VIP ์„ค์ •์„ ํ–ˆ๋‹ค.

# ifconfig eth0:1 192.168.56.100 netmask 255.255.255.0
# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:7d:10:15  
          inet addr:192.168.56.254  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe7d:1015/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:65 errors:0 dropped:0 overruns:0 frame:0
          TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8590 (8.5 KB)  TX bytes:8090 (8.0 KB)

eth0:1    Link encap:Ethernet  HWaddr 08:00:27:7d:10:15  
          inet addr:192.168.56.100  Bcast:192.168.56.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

VIP๊ฐ€ ์ œ๋Œ€๋กœ ์„ค์ •๋๋Š”์ง€ ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ์—์„œ ping์„ ์ด์šฉํ•ด์„œ ํ…Œ์ŠคํŠธ ํ–ˆ๋‹ค.

# ping 192.168.56.100
PING 192.168.56.100 (192.168.56.100) 56(84) bytes of data.
64 bytes from 192.168.56.100: icmp_req=1 ttl=64 time=0.454 ms
64 bytes from 192.168.56.100: icmp_req=2 ttl=64 time=0.465 ms

ARP ํ…Œ์ด๋ธ” ์ •๋ณด๋ฅผ ํ™•์ธํ•ด ๋ดค๋‹ค.

$ arp -na
? (192.168.56.254) at 08:00:27:7d:10:15 [ether] on vboxnet0
? (192.168.56.100) at 08:00:27:7d:10:15 [ether] on vboxnet0

MAC ์ฃผ์†Œ 08:00:27:7d:10:15์— ๋‘ ๊ฐœ์˜ IP๊ฐ€ ๋งตํ•‘๋ผ ์žˆ๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ tcpdump๋ฅผ ์ด์šฉํ•ด์„œ, ํŒจํ‚ท ์ˆ˜์ค€์—์„œ์˜ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ์„ ํ™•์ธํ–ˆ๋‹ค.

# tcpdump icmp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
11:28:26.771493 IP 192.168.56.1 > 192.168.56.100: ICMP echo request, id 4458, seq 1, length 64
11:28:26.771539 IP 192.168.56.100 > 192.168.56.1: ICMP echo reply, id 4458, seq 1, length 64
11:28:27.769532 IP 192.168.56.1 > 192.168.56.100: ICMP echo request, id 4458, seq 2, length 64
11:28:27.769579 IP 192.168.56.100 > 192.168.56.1: ICMP echo reply, id 4458, seq 2, length 64
11:28:28.767470 IP 192.168.56.1 > 192.168.56.100: ICMP echo request, id 4458, seq 3, length 64

๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ์—์„œ์˜ VIP ์‚ฌ์šฉ

๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋Š” ํŠธ๋ž˜ํ”ฝ์„ ์—ฌ๋Ÿฌ ์ปดํ“จํ„ฐ๋กœ ๋ถ„์‚ฐํ•˜๋Š” ์ปดํ“จํ„ฐ ์‹œ์Šคํ…œ์ด๋‹ค. ํŠธ๋ž˜ํ”ฝ์ด ๋ถ„์‚ฐ๋˜๋Š” ์ปดํ“จํ„ฐ, ์˜ˆ์ปจ๋ฐ ์›น์„œ๋ฒ„๋“ค์€ ์‚ฌ์„ค IP๋กœ ๊ตฌ์„ฑ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋Š” ํผ๋ธ”๋ฆญ ๋„คํŠธ์›Œํฌ์™€ ์‚ฌ์„ค ๋„คํŠธ์›Œํฌ์˜ ๊ฒฝ๊ณ„์— ์žˆ๋Š”๋ฐ, ํผ๋ธ”๋ฆญ ๋„คํŠธ์›Œํฌ์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋Š” VIP๋ฅผ ๊ฐ€์ง„๋‹ค.

ํด๋ผ์ด์–ธํŠธ๊ฐ€ VIP๋กœ ์ ‘๊ทผํ•˜๋ฉด, ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋Š” ์ง€์ •ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋”ฐ๋ผ์„œ ํŠธ๋ž˜ํ”ฝ์„ ๋ถ„์‚ฐํ•œ๋‹ค.

Proxy ARP๋ฅผ ์ด์šฉํ•œ ๊ฐ€์ƒ IP ์ƒ์„ฑ

ARP๋Š” Address Resolution Protocol๋กœ MAC ์ฃผ์†Œ์™€ IP ์ฃผ์†Œ๋ฅผ ๋งตํ•‘ํ•˜๋Š” ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ARP์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ GNS3๋กœ ์•Œ์•„๋ณด๋Š” L2๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜๊ธฐ ๋ฐ”๋ž€๋‹ค.

proxy arp๋Š” ARP ์š”์ฒญ์ด ์™”์„ ๋•Œ ๋Œ€์‹  ์‘๋‹ต์„ ํ•˜๋Š” ๊ธฐ์ˆ ์ด๋‹ค. L2์—์„œ ARP ์š”์ฒญ์„ ๋ธŒ๋กœ๋“œ์บ์ŠคํŒ… ํ•˜๋ฉด, ์š”์ฒญ์„ ๋ฐ›์€ ์šด์˜์ฒด์ œ๋Š” ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค์˜ MAC ์ฃผ์†Œ์™€ IP ์ฃผ์†Œ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๋ณดํ†ต์€ ํ•˜๋‚˜์˜ MAC ์ฃผ์†Œ์— ๋Œ€ํ•ด์„œ ํ•˜๋‚˜์˜ ์ธํ„ฐ๋„ท ์ฃผ์†Œ ์ •๋ณด๋งŒ์„ ์‘๋‹ตํ•˜๋Š”๋ฐ, proxy arp๋ฅผ ์ด์šฉํ•˜๋ฉด ๋‘๊ฐœ ์ด์ƒ์˜ ์ธํ„ฐ๋„ท ์ฃผ์†Œ๋ฅผ ์‘๋‹ตํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์™ธ๋ถ€์—์„œ๋Š” ๋งˆ์น˜ ๋‘ ๊ฐœ์˜ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.

IP ํˆด์„ ์ด์šฉํ•œ IP ์„ค์ •

IP ํˆด์„ ์ด์šฉํ•ด์„œ ์ธํ„ฐํŽ˜์ด์Šค์— ip๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ฒŒ์ŠคํŠธ ์šด์˜์ฒด์ œ์˜ IP ์ •๋ณด๋‹ค.

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:7d:10:15  
          inet addr:192.168.56.254  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe7d:1015/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:70 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6125 (6.1 KB)  TX bytes:7721 (7.7 KB)

eth0์— 192.168.56.253์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

# ip addr add 192.168.56.253 dev eth0

์ œ๋Œ€๋กœ ์ถ”๊ฐ€ ๋๋Š”์ง€ ํ™•์ธ.

$ ip addr show 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:7d:10:15 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.254/24 brd 192.168.56.255 scope global eth0
    inet 192.168.56.253/32 scope global eth0
    inet6 fe80::a00:27ff:fe7d:1015/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 08:00:27:fe:f6:bc brd ff:ff:ff:ff:ff:ff

ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ์—์„œ ์ถ”๊ฐ€ํ•œ IP๋กœ ping์„ ๋‚ ๋ฆฌ๊ณ  arp ํ…Œ์ด๋ธ”์„ ํ™•์ธ ํ–ˆ๋‹ค. ์ž˜ ๋œ๋‹ค.

$ arp -na
? (192.168.56.254) at 08:00:27:7d:10:15 [ether] on vboxnet0
? (192.168.1.254) at 00:1d:93:30:03:b5 [ether] on wlan0
? (192.168.56.253) at 08:00:27:7d:10:15 [ether] on vboxnet0