Linux Virtual Server (LVS) 實作筆記(VS/NAT) (VS/TUN) (VS/DR)

Linux Virtual Server (LVS) 實作筆記
關於 LVS
转自 http://cha.homeip.net/blog/

The Linux Virtual Server Project
LVS项目中的有关中文文档
LVS中文站点
環境:

Load Balancer:
kernel 2.6.x 已內建 LVS 模組
kernel 2.4.x 需打補丁
Fedora Core 3 預設安裝即可使用 LVS 模組, 另以 yum 安裝 ipvsadm 套件
如無法以 yum 安裝 ipvsadm, 可從這個連結下載
 
Real Server:
VS/NAT 可使用任何平台的網路伺服器當 Real Server
VS/TUN 需支援 IP Tunneling
VS/DR 需支援 Non-ARP 網路設備
為簡化測試環境, 本篇 Load Balancer 與 Real Server 皆為 Fedora Core 3

Virtual Server via NAT (VS/NAT)

架構圖
Load Balancer:

eth1 (對外): 10.2.0.1
eth0 (對內): 192.168.1.254
vi /etc/sysctl.conf

net.ipv4.ip_forward = 1

sysctl -p
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
ipvsadm -C
ipvsadm -A -t 10.2.0.1:80 -s rr
ipvsadm -a -t 10.2.0.1:80 -r 192.168.1.1:80 -m
ipvsadm -a -t 10.2.0.1:80 -r 192.168.1.2:80 -m

Real Server:

Default Gateway 指向 Director 的 LAN IP

Virtual Server via IP Tunneling (VS/TUN)

架構圖
Load Balancer:

eth0: 10.2.0.1
eth0:0: 10.2.0.2
vi /etc/sysctl.conf

net.ipv4.ip_forward = 1

sysctl -p
ifconfig eth0:0 10.2.0.2 netmask 255.255.255.255 up
ipvsadm -C
ipvsadm -A -t 10.2.0.2:80 -s rr
ipvsadm -a -t 10.2.0.2:80 -r 10.2.0.11:80 -i
ipvsadm -a -t 10.2.0.2:80 -r 10.2.0.12:80 -i

Real Server:

vi /etc/sysctl.conf

net.ipv4.ip_forward = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

sysctl -p
ifconfig tunl0 10.2.0.2 netmask 255.255.255.255 up
route add -host 10.2.0.2 dev tunl0

ps. 以上是 Real Server 與 Director 在同一個 LAN 的 IP Tunneling, 跨 WAN 的 IP Tunneling 還搞不清楚... Orz

Virtual Server via Direct Routing (VS/DR)

架構圖
Load Balancer:

eth0: 10.2.0.1
eth0:0: 10.2.0.2
vi /etc/sysctl.conf

net.ipv4.ip_forward = 1

sysctl -p
ifconfig eth0:0 10.2.0.2 netmask 255.255.255.255 up
ipvsadm -C
ipvsadm -A -t 10.2.0.2:80 -s rr
ipvsadm -a -t 10.2.0.2:80 -r 10.2.0.11:80 -g
ipvsadm -a -t 10.2.0.2:80 -r 10.2.0.12:80 -g

Real Server:

vi /etc/sysctl.conf

net.ipv4.ip_forward = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

sysctl -p
ifconfig lo:0 10.2.0.2 netmask 255.255.255.255 up
route add -host 10.2.0.2 dev lo:0

Forums:

randomness