keepalived高可用(centos7)

keepalived起初是为了LVS设计的,专门用来监控集群系统中各个服务结点的状态,后来加入VRRP的功能,VRRP是虚拟路器冗余协议,VRRP出现的目的就是为了解决静态路由器单点故障问题。

故障切换原理:

keepalived 主备之间的故障切换是通过VRRP协议来实现

在keepalived主正常工作时,他会不断的向备节点广播心跳信息,告诉备节点自己还活着。当主节点发生故障时,备节点就检测不到主的心跳,进而就会接管主的ip资源及服务时,当主节点恢复正常时,备节点会默认释放主节点故障时自身接管的ip资源及服务,恢复到原来备用角色。

1、安装keepalived

两台:一台主一台备

yum install http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release-7-1.noarch.rpm
yum install keepalived

 2、配置

将配置文件备份

cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

主的配置

vim  /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL1
}

vrrp_instance VI_1 {
    state MASTER
    interface ens160
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.88.11
    }
}

备的配置

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL2
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens160
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.88.11
    }
}

启动服务

systemctl start keepalived

3、测试故障切换

主(140)正常时 vip在主上绑定

keepalived高可用(centos7)_第1张图片

 停止主的keepalived模拟宕机 vip就会漂移到备(144)上

systemctl stop keepalived

keepalived高可用(centos7)_第2张图片

 

你可能感兴趣的:(网络,服务器,运维)