LVS setup + keepalived
Server
#!/bin/bash
VIP=10.132.2.254
RIP1=10.132.2.17
RIP2=10.132.2.18
#./etc/rc.d/init.d/functions
case "$1" in
start )
echo "start LVS of Director Server"
/sbin/ifconfig bond4:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
/sbin/ipvsadm -ln
;;
stop)
echo "close LVS Director Server"
echo 0 >/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
/sbin/ifconfig bond4:0 down
;;
*)
echo "Usage:$0{start|stop}"
exit 1
esac
RS:
#!/bin/bash
VIP=10.132.2.254
RIP1=10.132.2.17
RIP2=10.132.2.18
#./etc/rc.d/init.d/functions
case "$1" in
start )
echo "set RS "
VIP=10.132.2.254
/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
;;
stop)
/sbin/ifdown lo:0
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p
;;
*)
echo "Usage:$0{start|stop}"
exit 1
esac
! Configuration File for keepalived
global_defs {
router_id lvs
}
vrrp_sync_group http {
group {
apache
}
}
vrrp_instance apache {
state MASTER
interface bond4
virtual_router_id 51
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.132.2.254
}
}
virtual_server 10.132.2.254 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
# persistence_timeout 50
protocol TCP
real_server 10.132.2.17 80 {
weight 1
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
real_server 10.132.2.18 80 {
weight 1
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
}