Linux | Keepalived+LVS/DR 高可用集群

实验环境:Centos6.7

搭建高可用LVS负载均衡服务器

LVS/DR环境搭建

硬件环境:host62,host63, host68分发器,关闭防火墙、SELINUX
keepalived实验中仅需装包,配置开机自启

#host65/68:
# 手动添加VIP Keepalived不做
# ifconfig eth0:1 192.168.4.100/32
# 安装LVS
yum install -y ipvsadm
# 创建VS虚拟服务,轮询算法
ipvsadm -A -t 192.168.4.100:80 -s rr
# 添加RS,DR模式
ipvsadm -a -t 192.168.4.100:80 -r 192.168.4.62 -g
ipvsadm -a -t 192.168.4.100:80 -r 192.168.4.63 -g
# 保存配置
service ipvsadm save
# 启动服务
service ipvsadm start
# 查看数据包
ipvsadm -Ln

LRS环境设置

web62、63为LVS做准备配置

# 配置VIP到本地回环lo:1
ifconfig lo:1 192.168.4.100/32
# 写到开机自动执行配置
echo "ifconfig lo:1 192.168.4.100/32" >> /etc/rc.local
# web环境搭建
yum install -y httpd
service httpd start
chkconfig httpd on

Keepalived + LVS/DR

环境要求:分发器65、68 不需手动绑定VIP,只需装包、设置自启
原理:Keeplalived自动检测主VS状态,自动配置ipvsadm

#host65/68:
# 安装keepalived
yum install -y keepalived

#host65[主]/68[b备]
rpm -qc keepalived
vim /etc/keepalived/keepalived.conf
---
...上面配置不用改
vrrp_instance VI_1 {
    state MASTER [68:BACKUP]
    interface eth0    virtual_router_id 51
    priority 150 [68:100]
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.4.100    
        }
}
#ipvsadm -A -t...=
virtual_server 192.168.4.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    # persistence_timeout 50 
    #50s内对同一Client只分发一台web
    protocol TCP
    connect_timeout 3
    nb_get_retry 3    
    delay_before_retry 3
#ipvsadm -a -t ...=    
    real_server 192.168.4.62 80 {
        weight 1        
        }
    real_server 192.168.4.63 80 {        
        weight 1
        }
    }
}
#下面多余行删除

65改完后scp到68,修改描述值、优先级

scp /etc/keepalived/keepalived.conf 192.168.4.68:/etc/keepalived/

启动Keepalived,Client验证配置

service keepalived start
chkconfig keepalived on

测试

curl 192.168.4.100

本文链接:

https://blog.zhigu34.cn/archives/72.html
1 + 1 =
快来做第一个评论的人吧~