一、keepalived+lvs-DR模式配置高可用负载均衡
拓扑如下:
二、服务器ip配置信息
1. ip_lb 主机(master) :
2.ip_lb_2 主机 (backup)
3.web1 主机
4.web2 主机
三、在master和backup分别查看是否有ipvsadm软件
1. 检查ipvsadm是否安装成功.可以直接输入
[root@localhost ~]# ipvsadm
#global define
global_defs {
router_id LVS_T1
}
vrrp_sync_group bl_group {
group {
bl_one
}
}
vrrp_instance bl_one {
state MASTER
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 38
priority 150
advert_int 3
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.96.100
}
}
virtual_server 192.168.96.100 8099 {
delay_loop 3
lb_algo rr
lb_kind DR
persistence_timeout 1
protocol TCP
real_server 192.168.96.33 8099 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8099
}
}
real_server 192.168.96.4 8099 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8099
}
}
}
#global define
global_defs {
router_id LVS_T2
}
vrrp_sync_group bl_group {
group {
bl_one
}
}
vrrp_instance bl_one {
state BACKUP
interface eth0
lvs_sync_daemon_interface eth0
virtual_router_id 38
priority 120
advert_int 3
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.96.100
}
}
virtual_server 192.168.96.100 8099 {
delay_loop 3
lb_algo rr
lb_kind DR
persistence_timeout 1
protocol TCP
real_server 192.168.96.33 8099 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8099
}
}
real_server 192.168.96.4 8099 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8099
}
}
}
#! /bin/sh
# descript : start real server DR
VIP=192.168.96.100
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of RealServer DR"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS of RealServer DR"
echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage : $0 {start|stop}"
exit 1
esac
#! /bin/sh
for((i=1;i<=100;i++));do
curl http://192.168.96.100:8099 >> /tmp/q;
done