real_server 192.168.19.29 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
real_server 192.168.19.34 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
virtual_server 192.168.19.151 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.19.29 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
real_server 192.168.19.34 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
keep2上:
vim /etc/keepalived/keepalived.conf
----------------------------------------------
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 31
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass abcd
}
virtual_ipaddress {
192.168.19.150
}
}
vrrp_instance VI_2 {
state MASTER
interface eth0
virtual_router_id 41
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass abcd
}
virtual_ipaddress {
192.168.19.151
}
}
virtual_server 192.168.19.150 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.19.29 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
real_server 192.168.19.34 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
virtual_server 192.168.19.151 80 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.19.29 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
real_server 192.168.19.34 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
3.两台机器启动keepalived:
service keepalived start
ipvsadm -L -n //用LVS工具查看keepalived运行
ip addr show //查看VIP
两台机器上LVS规则都已经生效,且2个VIP分别运行在2个节点:
keep1上:
keep2上:
分别打开测试页面进行测试:
停掉任何一个节点,资源都会自动转移:
至此,演示完毕,谢谢!
CentOS 6.3下Haproxy+Keepalived+Apache配置笔记
Haproxy + KeepAlived 实现WEB群集 on CentOS 6