准备四台服务器,准备好基础环境
10.0.0.20  dr1    负载均衡器
10.0.0.23  dr2    负载均衡器
10.0.0.21  rs1     web1
10.0.0.22  rs2     web2
其中两台做dr模式负载均衡,两台做web服务器,测试两台dr搭建成功
搭建keepalived:
1、在两台dr上安装Keepalived
2.修改配置文件(清空原有配置文件)
[root@localhost keepalived-1.2.1]# cd /etc/keepalived/
[root@localhost keepalived]# vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id Director1    //两边是一样的
}

vrrp_instance VI_1 {
state MASTER //另外一台机器是BACKUP
interface eth0 //心跳网卡  DIP那一块网卡
virtual_router_id 51
priority 50 //优先级
advert_int 1 //检查间隔,单位秒
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.122.254/24 dev eth0   //VIP随便自己定义  只要是同一个网段就可以
}
}

virtual_server 192.168.122.254 80 { //LVS 配置,VIP
delay_loop 3                                         //服务论询的时间间隔
lb_algo rr                    //LVS 调度算法
lb_kind DR                    // LVS 集群模式
protocol TCP
real_server 192.168.122.30 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
real_server 192.168.122.40 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
}
3、拷贝修改好的dr上的keepalived.conf到另外一台上
4、拷贝后,修改配置文件
state     BACKUP
priority 100
5、两个dr上启动keepalived服务
rhel6:
   # service keepalived start
   rhel7:
   # systemctl start keepalived

6、测试
1)观察lvs路由条目
2)观察vip地址在哪台机器上
3)客户端浏览器访问vip
4)关闭master上的keepalived服务,再次访问vip