keepalived高可用配置【非抢占式】

keepalived-学习目录

1、抢占式问题点

通常master服务故障后backup会变成master,但是当master服务又恢复的时候,master会抢占VIP,这样就会发生两次切换对业务繁忙的网站来说并不是太友好,
此时我们可以配置keepalived为非抢占式(前提两台主机的硬件配置信息一致)

2、keepalived配置【非抢占式】

2.1、配置步骤

1、两个节点的state都必须配置为BACKUP(官方建议)
2、两个节点都在vrrp_instance中添加nopreempt参数
3、其中一个节点的优先级必须要高于另外一个节点的优先级。
两台服务器都角色状态启用nopreempt后,必须修改角色状态统一为BACKUP,唯一的区分就是优先级。

2.2、keepalived-01配置

cat << 'CAT_END' >/usr/local/keepalived/etc/keepalived/keepalived.conf 
global_defs {
   router_id kp01
}
vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface ens33
    virtual_router_id 50
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.200
    }
}
CAT_END

2.3、keepalived-02配置

cat << 'CAT_END' >/usr/local/keepalived/etc/keepalived/keepalived.conf 
global_defs {
   router_id kp02
}
vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface ens33
    virtual_router_id 50
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.200
    }
}
CAT_END

2.4、配置完成,重启keepalived服务

systemctl restart keepalived

3、测试地址是否漂移

3.1、停止master vip地址

keepalived-01 ~]# ip addr | grep 200
    inet 192.168.10.200/32 scope global ens33
keepalived-01 ~]# systemctl stop keepalived keepalived-01 ~]# ip addr | grep 200

3.2、查询vip是否漂移至backup

keepalived-02 ~]# ip addr | grep 200
    inet 192.168.10.200/32 scope global ens33

3.3、启动master节点,发现vip不会再抢占过来,还是在backup主机上

keepalived-01 ~]# systemctl start keepalived
keepalived-01 ~]# ip addr | grep 200

 

posted @ 2023-05-05 20:32  小粉优化大师  阅读(241)  评论(0编辑  收藏  举报