keepalived+lvs 来实现负载均衡
设备:2台realserver ; 2台(keepalived+lvs)
注:此处的虚拟IP为: 192.168.159.200
第一步:
在realserver主机上运行 这样做的目的是为了把虚拟VIP 隐藏
一:
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
ifconfig lo:0 192.168.159.200 netmask 255.255.255.255 broadcast 192.168.159.200
二:
route add -host 192.168.159.200 dev lo:0 realserver //添加路由
第二步:
设2台keepalived+lvs 分别为A和B A作为MASTER B作为BACKUP
设置keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
goldbin@126.com
}
notification_email_from test@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.159.200/24 dev eth0 label eth0:0
}
}
virtual_server 192.168.159.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.159.32 80 {
weight 1
HTTP_GET {
url {
path /index.html
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
real_server 192.168.159.33 80 {
weight 1
HTTP_GET {
url {
path /index.html
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
}
第三步:
启动realserver的httpd服务 和 2台keepalived服务
访问的时候 访问虚拟IP 此处为 192.168.159.200