LVS+keepalived+DR 负载均衡高可用

畅聊架构 2019-12-04

准备两台web服务器,准备好测试页面,以便查看结果。(centos6)

1、下载相关服务,并关闭防火墙和SElinux

yum -y install httpd (一般自带都有)

yum -y install keepalived (master和slave)

yum -y install ipvsadm (master)

service iptables stop

setenforce 0

2、分别在两台web服务器添加一下测试页面添加不同内容

vim /var/www/html/index.html

3、修改keepalived配置文件

vim /etc/keepalived/keepalived.conf

如图(添加了VIP和真实服务器并改为DR模式,TCP_CHECK健康检查)

LVS+keepalived+DR 负载均衡高可用

4、将master的keepalived.conf复制到slave上 并再次修改保存

scp (master ip):/etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf

vim /etc/keepalived/keepalived.conf

(将master改为BACKUP,priority速度改为100以下,以防速度同步不出效果)

LVS+keepalived+DR 负载均衡高可用

 5、进去网络配置拷贝一份网卡并修改保存

LVS+keepalived+DR 负载均衡高可用

vim ifcfg-lo:0

 LVS+keepalived+DR 负载均衡高可用

6、在两台web服务器添加回环口并查看

LVS+keepalived+DR 负载均衡高可用

LVS+keepalived+DR 负载均衡高可用

在master查看

LVS+keepalived+DR 负载均衡高可用

7、开启keepalived,查看vip是否生成,关闭后是否自动漂移到从上,实现高可用

LVS+keepalived+DR 负载均衡高可用

LVS+keepalived+DR 负载均衡高可用

9、最后用浏览器访问VIP,是否来回展示两个测试页面,实现负载均衡。

LVS+keepalived+DR 负载均衡高可用

LVS+keepalived+DR 负载均衡高可用

相关推荐