Keepalived 双主虚拟路由配置实例

Keepalived 双主虚拟路由配置实例

演示前说明: 

 2台centos7.2 主机:node-00,node-01

VIP1:10.1.38.19预定node-00占有

VIP2:10.1.38.20 预定node-01占有

2台主机安装好keepalived之后,开始编辑配置文件 

node-00的配置如下 

复制代码
! Configuration File for keepalived

global_defs {
   notification_email {
    root@localhost
   }
   notification_email_from keepalived@localhost           #定义来信人
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node-00
   vrrp_mcast_group4 224.0.38.12
}

vrrp_instance VI_1 {
    state MASTER
    interface team0
    virtual_router_id 38
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass x1er44q
    }
    virtual_ipaddress {
        10.1.38.19/16 dev team0
    }

    smtp_alert            #状态切换,使用邮件通知
}

vrrp_instance VI_2 {
    state BACKUP
    interface team0
    virtual_router_id 39
    priority 97
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass x1er44q
    }
    virtual_ipaddress {
        10.1.38.20/16 dev team0
    }
    smtp_alert
}
复制代码

复制要把备注删掉

node-01配置如下

复制代码
! Configuration File for keepalived

global_defs {
   notification_email {
    root@localhost
   }
   notification_email_from keepalived@localhost 
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id node-01
   vrrp_mcast_group4 224.0.38.12
}

vrrp_instance VI_1 {
    state BACKUP
    interface bond0
    virtual_router_id 38
    priority 97
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass x1er44q
    }
    virtual_ipaddress {
        10.1.38.19/16 dev bond0
    }
    smtp_alert
}

vrrp_instance VI_2 {
    state MASTER
    interface bond0
    virtual_router_id 39
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass x1er44q
    }
    virtual_ipaddress {
        10.1.38.20/16 dev bond0
    }
    smtp_alert
}
复制代码

配置完成后,启动服务

#systemctl start keepalived

使用ip命令查看ip地址情况

#ip address show

node-00情况

node-01情况

此时,我们模拟node-00宕机,将node-00的keepalived服务停掉,那么10.1.38.19此ip会流动到node-01上

#systemctl stop keepalived

至此此部分演示完毕。

posted @ 2019-06-19 18:10  豆浆D  阅读(805)  评论(0)    收藏  举报