cent os 4.4 架设的lvs/nat模式

建了两个负载群,用虚拟机做的,测试都没有问题,全都可以访问。

VIP1=192.168.26.122
VIP2=192.168.26.123
DIP=192.168.40.22

负载均衡地址
eth0=192.168.26.121/24
GW=192.168.26.1
eth1=192.168.40.20/24

客户端地址
RIP1=192.168.40.11
RIP2=192.168.40.12

客户端需修改默认网关到负载均衡上的DIP

一、打开ip_forward功能
vi /etc/sysctl.conf
修改
net.ipv4.ip_forward = 1

二 添加虚拟IP
ifconfig eth0:0 192.168.26.122 broadcast 192.168.26.122 netmask 255.255.255.255 up
route add -host 192.168.26.122 dev eth0:0

ifconfig eth0:1 192.168.26.123 broadcast 192.168.26.123 netmask 255.255.255.255 up
route add -host 192.168.26.123 dev eth0:1

ifconfig eth1:1 192.168.20.22 broadcast 192.168.40.22 netmask 255.255.255.255 up
route add -host 192.168.40.22 dev eth1:1

三 添加相应策略

#!/bin/bash
ipvsadm -C
ipvsadm -A -t 192.168.26.122:80 -s wlc
ipvsadm -a -t 192.168.26.122:80 -r 192.168.40.11:80 -m
ipvsadm -a -t 192.168.26.122:80 -r 192.168.40.13:80 -m
ipvsadm -a -t 192.168.26.122:80 -r 192.168.40.22:80 -m
ipvsadm -A -t 192.168.26.123:80 -s wlc
ipvsadm -a -t 192.168.26.123:80 -r 192.168.40.12:80 -m
ipvsadm -a -t 192.168.26.123:80 -r 192.168.40.22:80 -m