LVS负载均衡集群之DR模式
一、环境
4台虚拟机:1台Client、1台DirectorServer、2台RealServer。IP地址分别如下:
Client:192.168.12.22
DS:VIP:192.168.12.100,DIP:192.168.12.10
RealServer1:192.168.12.80
RealServer2:192.168.12.81
二、安装配置RealServer
RealServer1:
yum -y install httpd
chkconfig httpd on
echo "RealServer1" >> /var/www/html/index.html
service httpd start
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
RealServer2:
yum -y install httpd
chkconfig httpd on
echo "RealServer2" >> /var/www/html/index.html
service httpd start
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
三、安装配置DirectorServer
/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth0:1
yum -y install ipvsadm
ipvsadm -A -t 192.168.12.100:80 -s wlc
ipvsadm -a -t 192.168.12.100:80 -r 192.168.12.80 -g -w 1
ipvsadm -a -t 192.168.12.100:80 -r 192.168.12.81 -g -w 1
service ipvsadm save
ipvsadm -L -n
参数说明:
-A 添加集群服务;
-t TCP协议;
-s 指定调度算法;
-g 指定为DR模式;
-w 权重;
四、Client访问测试
ab -c 10 -n 1000 http://192.168.12.100/index.html