keepalived双主模型实验

  • 双主模型对于vrrp来讲实际上也是单主模型,所不同的是在同一组接口上配置了多个虚拟路由器;有几个物理路由就配置几个虚拟路由,所以所谓多主就是让每一个物理节点都工作起来;
    • 注意:配置多个虚拟路由器,每个虚拟路由器都要用独立的专用的VIP!
  • 双主模型在互联网上的工作原理很简单,就是DNS域名解析服务器上为域名配置两条A记录,两个虚拟路由IP分别都指向同一个域名!
    • 就双主而言,因为两个同时工作,DNS也有两条虚拟IP指向同一个域名的A记录,一个节点down掉了也同样能工作,这既起到了高可用功能,也起到了负载均衡的功能;

配置节点一:

[root@host1 keepalived]#vim keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id host1
}

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id host1
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 89
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass nQyVIaY1
    }
    virtual_ipaddress {
        192.168.10.66
    }
}

vrrp_instance VI_2 {           <-- 节点一上的第二个虚拟路由器的配置;
    state BACKUP               <-- 节点一上的第二个虚拟路由器设为BACKUP,MASTER正常时处于就绪监听状态;
    interface ens33            <-- 接口不变
    virtual_router_id 79       <-- 不能跟其他虚拟路由相同;
    priority 95                <-- 因为是BACKUP,优先级要低于节点二的第二个虚拟路由器的MASTER;
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass nRyVIaY2     <-- 这里各虚拟路由器不能相同!
    }
    virtual_ipaddress {
        192.168.10.77          <-- 不同的虚拟路由器,IP地址也肯定不能相同;
    }
}
#
"keepalived.conf" 165L, 3807C written
[root@host1 keepalived]#  

配置节点二:

[root@host2 keepalived]#vim keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id host2
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 89
    priority 95
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass nQyVIaY1
    }
    virtual_ipaddress {
        192.168.10.66
    }
}
vrrp_instance VI_2 {           <-- 节点二上的第二个虚拟路由器的配置;
    state MASTER               <-- 节点二上这里变成MASTER
    interface ens33
    virtual_router_id 79
    priority 100               <-- 优先级高于节点一的第二个虚拟路由器;
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass nRyVIaY2
    }
    virtual_ipaddress {
        192.168.10.77
    }
}
#
"keepalived.conf" 165L, 3807C written
[root@host2 keepalived]#

到这里双主模式就配置好了!

测试:

  • 设定节点二故障:

启动节点一的keepalived服务,关闭节点二的keepalived服务;查看节点一的状态;

keepalived双主模型实验_第1张图片
  • 节点二上也启动keepalived服务:

两个节点都启动keepalived服务,并查看状态和接口IP地址信息;

keepalived双主模型实验_第2张图片
节点一的keepalived服务状态及ens33接口的IP信息
keepalived双主模型实验_第3张图片
节点二的keepalived服务状态及接口ens33的IP信息
  • 设定节点一故障:

关闭节点一的keepalived服务,在节点二上查看keepalived状态;

keepalived双主模型实验_第4张图片
节点二的状态
keepalived双主模型实验_第5张图片
节点一的状态

就像上面测试的,你多来几遍,看看状态,看看设置虚拟路由接口的虚拟IP变化...

你可能感兴趣的:(keepalived双主模型实验)