keepalived高可用配置【抢占式】

keepalived-学习目录

1、环境准备

keepalived-01 192.168.10.14 【Master】
keepalived-02 192.168.10.13 【Backup】

2、keepalived配置【抢占式】

2.1、Master的配置【keepalived-01】

cat << 'CAT_END' >/usr/local/keepalived/etc/keepalived/keepalived.conf
global_defs {
   router_id kp01
}
vrrp_instance VI_1 {
    state MASTER
    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.2、Backup的配置【keepalived-02】

cat << 'CAT_END' >/usr/local/keepalived/etc/keepalived/keepalived.conf
global_defs {
   router_id kp02
}
vrrp_instance VI_1 {
    state BACKUP
    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.3、master 与 backup 配置的区别

Keepalived配置区别    Master配置     Backup节配置
route_id(唯一标识)    kp01           kp02
state(角色状态)       MASTER         BACKUP
priority(优先级)      150            100

3、启动keepalived服务

3.1、keepalived-01、keepalived-02执行

systemctl enable keepalived
systemctl start keepalived

3.2、查询vip是否创建

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

4、keepalived高可用地址漂移

检查keepalived的虚拟VIP地址能否漂移

4.1、在keepalived-01 Master进行操作

# VIP还存在
keepalived-01 ~]# ip addr | grep 200
    inet 192.168.10.200/32 scope global ens33

# 停止keepalived服务
keepalived-01 ~]# systemctl stop keepalived

# VIP不在了
keepalived-01 ~]# ip addr | grep 200

4.2、在keepalived-02 Backup进行操作【地址已经漂移到backup】

# 发现VIP地址已经漂移至Backup主机上
keepalived-02 ~]# ip addr | grep 200 inet 192.168.10.200/32 scope global ens33

4.3、在keepalived-01 Master操作启动keepalived

# 启动Master上的Keepalived,会发现VIP被强行抢占回来keepalived
keepalived-01 ~]# systemctl start keepalived keepalived-01 ~]# ip addr | grep 200 inet 192.168.10.200/32 scope global ens33

 

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