负载均衡实现故障vip自动漂移

Posted dhzg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了负载均衡实现故障vip自动漂移相关的知识,希望对你有一定的参考价值。

环境说明演示vip自动漂移
192.168.237.50
192.168.237.51
vip: 192.168.237.5

keepalived开源软件实现
keepalived可以实现当vip挂的时候,自动漂移,基于vrrp虚拟路由冗余协议
主备,vrrp去宣告


keepalived主服务器的配置/usr/local/keepalived/etc/keepalived/keepalived.conf
vrrp_instance VI_1 
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 2
    authentication 
        auth_type PASS
        auth_pass 666666
    
    virtual_ipaddress 
        192.168.237.5/24
    



vrrp_instance配置,配置vip
state 配置主或者备
interface 配置vip使用的物理网卡
virtual_router_id 虚拟路由id
priority 权重配置,主的权重比备的高
advert_int 主每2s发个vrrp包,说明自己正常
authentication 认证信息
virtual_ipaddress 配置vip


检查配置,启动keepalived
/usr/local/keepalived/sbin/keepalived -t -f /usr/local/keepalived/etc/keepalived/keepalived.conf
/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf


keepalived备服务器的配置/usr/local/keepalived/etc/keepalived/keepalived.conf
vrrp_instance VI_1 
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 99
    advert_int 2
    authentication 
        auth_type PASS
        auth_pass 666666
    
    virtual_ipaddress 
        192.168.237.5/24
    



抓包可以看到vrrp协议


验证keepalived的vip自动漂移

存在问题
主起来后又会接管vip
vip的频繁漂移对于我们不太有利

以上是关于负载均衡实现故障vip自动漂移的主要内容,如果未能解决你的问题,请参考以下文章

Keepalived 之 双主模式+DNS轮询机制 实现高负载

nginx负载均衡+keepalived三主(多主)配置

使用Nginx实现负载均衡

Nginx + Keepalived

双机高可用负载均衡MySQL(读写分离主从自动切换)架构设计

负载均衡故障处理-无法访问网站