实践双组KeeAlived

master/slave的单主架构,同一时间只有一个Keepalived对外提供服务,此主机繁忙,而另一台主机却很空闲,利用率低下,可以使用master/master的双主架构,解决此问题。
master/master的双主架构:即将两个或以上VIP分别运行在不同的keepalived服务器,以实现服务器并行提供web访问的目的,提高服务器资源利用率

实现master/master的Keepalivde 双主架构
[root@localhost7A ~]# cat  /etc/keepalived/keepalived.conf 
global_defs {
   notification_email {
     root@localhost   
   }
   notification_email_from root@localhost  
   smtp_server 127.0.0.1  
   smtp_connect_timeout 30
   router_id localhost7A
   vrrp_iptables
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_mcast_group4 224.0.100.100
}
vrrp_instance zzhz {
    state MASTER
    interface eth0
    virtual_router_id 88 
    priority 88        
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass centos 
    }
    virtual_ipaddress {
        192.168.80.222/24 dev eth0 label eth0:1
    }
}
vrrp_instance zjol {
    state BACKUP
    interface eth0
    virtual_router_id 66
    priority 60        
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass centos 
    }
    virtual_ipaddress {
        192.168.80.224/24 dev eth0 label eth0:2  #注意接口编号
    }
}

[root@localhost7B ~]# cat /etc/keepalived/keepalived.conf 
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from root@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id localhost7A
   vrrp_iptables
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_mcast_group4 224.0.100.100
}

vrrp_instance zzhz {
    state BACKUP
    interface eth0
    virtual_router_id 88 
    priority 80
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass centos
    }
    virtual_ipaddress {
        192.168.80.222/24 dev eth0 label eth0:1
    }
}
vrrp_instance zjol {
    state MASTER
    interface eth0
    virtual_router_id 66
    priority 66        
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass centos 
    }
    virtual_ipaddress {
        192.168.80.224/24 dev eth0 label eth0:2
    }
}

  

实战案例:利用子配置文件实现master/master的Keepalived双主架构
实现独立子配置文件
当生产环境复杂时,/etc/keepalived/keepalived.conf文件中内容过多,不易管理,可以将不同集群的配置,
比如:不同集群的VIP配置放在独立的子配置文件中include /etc/keepalived/conf.d/*.conf

[root@localhost7A ~]# cat /etc/keepalived/keepalived.conf 
global_defs {
   notification_email {
     root@localhost   
   }
   notification_email_from root@localhost  
   smtp_server 127.0.0.1  
   smtp_connect_timeout 30
   router_id localhost7A
   vrrp_iptables
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_mcast_group4 224.0.100.100
}
include /etc/keepalived/conf.d/*.conf #子配置文件


[root@localhost7A ~]# cat /etc/keepalived/conf.d/zzhz.conf 
vrrp_instance zzhz {
    state MASTER
    interface eth0
    virtual_router_id 88
    priority 88
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass centos
    }
    virtual_ipaddress {
        192.168.80.222/24 dev eth0 label eth0:1
    }
}
[root@localhost7A ~]# cat /etc/keepalived/conf.d/zjol.conf 
vrrp_instance zjol {
    state BACKUP
    interface eth0
    virtual_router_id 66
    priority 60
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass centos
    }
    virtual_ipaddress {
        192.168.80.224/24 dev eth0 label eth0:2  #注意这个接口编号,是eth0:2,
    }
}
另外一台KA主机。
[root@localhost7B ~]# tree  /etc/keepalived/
/etc/keepalived/
├── conf.d
│   ├── zjol.conf
│   └── zzhz.conf
└── keepalived.conf

 

实战案例:多个节点的多主架构实现逻辑结构
第一个节点ka1配置:
Vrrp instance 1:MASTER,优先级100
Vrrp instance 2:BACKUP,优先级80
Vrrp instance 3:BACKUP,优先级60

第二个节点ka2配置:
Vrrp instance 1:BACKUP,优先级60
Vrrp instance 2:MASTER,优先级100
Vrrp instance 3:BACKUP,优先级80

第三个节点ka3配置:
Vrrp instance 1:BACKUP,优先级80
Vrrp instance 2:BACKUP,优先级60
Vrrp instance 3:MASTER,优先级100

  

posted @ 2022-07-28 11:02  yuanbangchen  阅读(37)  评论(0)    收藏  举报