一、LVS--NAT configuration
1、ENV
OS:RedHat AS3
Packeage:ipvsadm-1.21-9.ipvs108.i386.rpm
2、system architecture
director server:10.64.20.1 eth0 VIP:192.168.1.100 eth1
real server1:10.64.20.110 eth0
real server2:10.64.20.111 eth0
all netmask 255.255.255.0
3. director server configuration:
#install ipvsadm
rom -ivh ipvsadm-1.21-9.ipvs108.i386.rpm
#confiigure ip forward and redirects
echo "1" >/proc/sys/net/ipv4/ip_forward
ifconfig eth0 10.64.20.1
#configure VIP address
sbin/ifconfig eth1 192.168.1.100
#configre ipvsadm
ipvsadm -C
ipvsadm -A -t 10.64.20.113:http -s wrr
ipvsadm -a -t 10.64.20.113:http -r 10.64.20.111 -m
ipvsadm -a -t 10.64.20.113:http -r 10.64.20.110 -m
4. real server1 config
#configure ip
ifconfig eth0: 10.64.20.110
ifconfig gw:10.64.20.1
5. real server2 config
#configure ip
ifconfig eth0: 10.64.20.111
ifconfig gw:10.64.20.1
二、LVS--DR configuration
1、ENV
OS:RedHat AS3
Packeage:ipvsadm-1.21-9.ipvs108.i386.rpm
2、system architecture
director server:10.64.20.112
real server1:10.64.20.110
real server2:10.64.20.111
VIP:10.64.20.113
real server1 and 2 Ip address are configured . eth0
we first assume all servers are finished installed.
3. director server configuration:
#install ipvsadm
rom -ivh ipvsadm-1.21-9.ipvs108.i386.rpm
#confiigure ip forward and redirects
echo "0" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/lo/send_redirects
#configure VIP address
/sbin/ifconfig eth0:0 10.64.20.113 broadcast 10.64.20.113 netmask 255.255.255.255 up
/sbin/route add -host 10.64.20.113 dev eth0:0
#configre ipvsadm
ipvsadm -C
ipvsadm -A -t 10.64.20.113:http -s rr
ipvsadm -a -t 10.64.20.113:http -r 10.64.20.111 -g -w 1
ipvsadm -a -t 10.64.20.113:http -r 10.64.20.110 -g -w 1
4. real server1 config
#configure ip forward
echo "0" >/proc/sys/net/ipv4/ip_forward
#configure VIP . realserver and route
/sbin/ifconfig lo:0 10.64.20.113 broadcast 10.64.20.113 netmask 255.255.255.255 up
/sbin/route add -host 10.64.20.113 dev lo:0
#hidden arp request
arptables -A IN -d 10.64.20.113 -j DROP
arptables -A OUT -o lo -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.113
arptables -A OUT -o eth0 -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.110
arptables -A OUT -o eth1 -d 10.64.20.113 -j mangle --mangle-ip-s (if you have eth1 connect to network)
Windows系统
对于Windows系统的服务器,只要添加一个Loopback的网卡,IP地址设置成虚拟IP(10.64.20.113),子网掩码设置成255.255.255.255,网关地址留空Windows子网掩码无法配置成255.255.255.255,我们可以先按默认的保存配置,然后从注册表修改子网掩码。
从注册表
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces]下找到对应的网卡,将SubnetMask修改成255.255.255.255。然后禁用再启用该网卡即可。
5. real server2 config
#configure ip forward
echo "0" >/proc/sys/net/ipv4/ip_forward
#configure VIP . realserver and route
/sbin/ifconfig lo:0 10.64.20.113 broadcast 10.64.20.113 netmask 255.255.255.255 up
/sbin/route add -host 10.64.20.113 dev lo:0
#hidden arp request
arptables -A IN -d 10.64.20.113 -j DROP
arptables -A OUT -o lo -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.113
arptables -A OUT -o eth0 -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.111
arptables -A OUT -o eth1 -d 10.64.20.113 -j mangle --mangle-ip-s (if you have eth1 connect to network)
6. check with IE.
on Director server check ipvsadm list:
#ipvsadm -L
二、LVS--TUN configuration
1、ENV
OS:RedHat AS3
Packeage:ipvsadm-1.21-9.ipvs108.i386.rpm
2、system architecture
director server:10.64.20.112
real server1:10.64.20.110
real server2:10.64.20.111
VIP:10.64.20.113
real server1 and 2 Ip address are configured . eth0
we first assume all servers are finished installed.
3. Director Server
#!/bin/bash
#set ip_forward . for vs-tun director(1 ., 0 off)
echo "0" >/proc/sys/net/ipv4/ip_forward
#add ethernet device and routing for VIP
/sbin/ifconfig eth0:0 10.64.20.113 broadcast 10.64.20.113 netmask 255.255.255.255 up
/sbin/route add -host 10.64.20.113 dev eth0:0
ipvsadm -C
ipvsadm -A -t 10.64.20.113:http -s rr
ipvsadm -a -t 10.64.20.113:http -r 10.64.20.110 -i -w 1
ipvsadm -a -t 10.64.20.113:http -r 10.64.20.111 -i -w 1
4.real server 1
#!/bin/bash
#set_realserver_ip_forwarding to OFF(1 ., 0 off)
echo "0" >/proc/sys/net/ipv4/ip_forward
#install_readserver_vip
insmod ipip
ifconfig tunl0 10.64.20.113 broadcast 10.64.20.113 netmask 255.255.255.255 up
route add -host 10.64.20.113 dev tunl0
#hiding interface tunl0, will not arp
arptables -A IN -d 10.64.20.113 -j DROP
arptables -A OUT -o tunl0 -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.113
arptables -A OUT -o eth0 -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.110
arptables -A OUT -o eth1 -d 10.64.20.113 -j mangle --mangle-ip-s (if you have eth1 connect to network)
5.real server 2
#!/bin/bash
#set_realserver_ip_forwarding to OFF(1 ., 0 off)
echo "0" >/proc/sys/net/ipv4/ip_forward
#install_readserver_vip
insmod ipip
ifconfig tunl0 10.64.20.113 broadcast 10.64.20.113 netmask 255.255.255.255 up
route add -host 10.64.20.113 dev tunl0
#hiding interface tunl0, will not arp
arptables -A IN -d 10.64.20.113 -j DROP
arptables -A OUT -o tunl0 -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.113
arptables -A OUT -o eth0 -d 10.64.20.113 -j mangle --mangle-ip-s 10.64.20.111
arptables -A OUT -o eth1 -d 10.64.20.113 -j mangle --mangle-ip-s (if you have eth1 connect to network)
6. check with IE.
on Director server check ipvsadm list:
#ipvsadm -L