实验环境:
ipvsadm-1.26-4.el6.x86_64
system:centos-6.6.x86_64
kernel:2.6.32-504.el6.x86_64
keepalived-1.2.13-4.el6.x86_64
配置DR:
[[email protected] ~]# sysctl -w net.ipv4.conf.all.send_redirects=0 net.ipv4.conf.all.send_redirects = 0 [[email protected] ~]# sysctl -w net.ipv4.conf.default.send_redirects=0 net.ipv4.conf.default.send_redirects = 0 [[email protected] ~]# sysctl -w net.ipv4.conf.eth2.send_redirects=0 net.ipv4.conf.eth2.send_redirects = 0 [[email protected] ~]# service ipvsadm stop [[email protected] ~]# ipvsadm -A -t 192.168.150.200:80 -s rr [[email protected] ~]# ipvsadm -a -t 192.168.150.200:80 -r 192.168.150.129 -g -w 1 [[email protected] ~]# ipvsadm -a -t 192.168.150.200:80 -r 192.168.150.142 -g -w 1 [[email protected] ~]# iptable s -I INPUT -p tcp --dport 80 -j ACCEPT [[email protected] ~]# service ipvsadm save
配置real server:
[[email protected] ~]# vim /etc/sysctl.conf net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.default.arp_ignore=1 net.ipv4.conf.default.arp_announce=2 net.ipv4.conf.lo.arp_ignore=1 net.ipv4.conf.lo.arp_announce=2 [[email protected] ~]# sysctl -p [[email protected] ~]# ifconfig lo:0 192.168.150.200/32 [[email protected] ~]# route add -host 192.168.150.200 dev lo:0 [[email protected] ~]# setenforce 0 [[email protected] ~]# yum install httpd [[email protected] ~]# service httpd start
配置keepalived:
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 220.181.12.11
smtp_connect_timeout 30
router_id haproxy_DEVEL
}
vrrp_instance VI_1 {
state MASTER #另一端为SLAVE
interface eth3 #根据自己网卡情况而定
virtual_router_id 51
priority 100 #另一端为80
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
virtual_ipaddress {
192.168.150.200/24 dev eth3
}
}
virtual_server 192.168.150.200/24 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.150.129 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.150.142 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
[[email protected] ~]# service keepalived start
检测结果:
查看是否正常调度:
查看MASTER,获得vip:192.168.150.200,及检查后端
查看SLAVE,及检查后端服务:
故障转移:
停掉MASTER的keepalived,查看SLAVE是否自动切换为MASTER
[[email protected] ~]# service keepalived stop
检测后端检查:
停掉其中一台后端httpd
[[email protected] ~]# service hdttp stop
转载于:https://blog.51cto.com/dragon123/1602333