企业集群高可用方案——keepalived双实例双主实战

上节是单实例,主备模式的高可用VIP漂移,keepalived还支持多实例,双向主备模式。
服务器配置:

A业务在lb01上是主模式,在lb02上是备模式
B业务在lb01上是备模式,在lb02上是主模式
lb01 192.168.178.124 VIP:192.168.178.150(绑定A业务www.chaoge.com)
lb02 192.168.178.125 VIP:192.168.178.151(绑定B业务bbs.chaoge.com)

1.修改配置文件
lb01修改/etc/keeplived/keeplived.conf

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
	192.168.178.150/24 dev ens33 label ens33:1
    }
}


vrrp_instance VI_2 {
       state BACKUP
       interface ens33
       virtual_router_id 52
       priority 50
       advert_int 1
       authentication {
           auth_type PASS
           auth_pass 1111
       }
    
       virtual_ipaddress {
           192.168.178.151/24 dev ens33 label ens33:2
       }
}

lb02修改/etc/keeplived/keeplived.conf

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.178.150/24 dev ens33 lable ens33:1
    }
}

vrrp_instance VI_2 {
       state MASTER
       interface ens33
       virtual_router_id 52
       priority 100
       advert_int 1
       authentication {
           auth_type PASS
           auth_pass 1111
       }

       virtual_ipaddress {
           192.168.178.151/24 dev ens33 label ens33:2
       }
}

2.两台机器重启服务

systemctl restart keepalived

3.发现lb01得到了150的IP地址

[root@lb01 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:86:8b:7c brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.126/24 brd 192.168.178.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.178.150/24 scope global secondary ens33:1
       valid_lft forever preferred_lft forever
    inet6 fe80::e5af:8c6a:7d60:5b42/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::39a9:ff6a:b6ce:4fb7/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::88a:b623:3d8:4616/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever

4.发现lb02得到了151的IP地址

[root@lb02 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:a9:91:e4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.127/24 brd 192.168.178.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet 192.168.178.151/24 scope global secondary ens33:2
       valid_lft forever preferred_lft forever
    inet6 fe80::e5af:8c6a:7d60:5b42/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::39a9:ff6a:b6ce:4fb7/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::88a:b623:3d8:4616/64 scope link tentative noprefixroute dadfailed 
       valid_lft forever preferred_lft forever

5.记住如下因素即可,谁是vrrp实例的master,谁就优先得到vip

  • 1b01 得到的是vrrpl的vip因此是150
  • 1b02是 vzrp2的master,因此得到的是151

总结

  • Lb01、lb02主备节点都已经实现了各自服务提供的VIP服务
  • 任意节点宕机,VIP都能够实现漂移工作
  • 在实际工作下,可以把业务网站的域名解析到VIP上提供服务,例如Nginx的负载均衡,实现高可用性负载均衡
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>