keepalived双主模型配置

keepalived 双主模型

双主模型是两台服务器互为主备,即一台为主备,另一台为备主,让两台服务器并行运行,也可以实现减轻单台keepalived主机上的压力。 双主模型需要注意此时需要有2个VIP地址

2台主机

server hostname ip
keepalived ka1 192.168.99.103
keepalived ka2 192.168.99.104

  1. ka1的配置
[ka1]$ cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
           root@localhost
   }
   notification_email_from root@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka1
   vrrp_skip_check_adv_addr
#   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 11
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
        unicast_src_ip 192.168.99.103
        unicast_peer {
        192.168.99.104
        }
    virtual_ipaddress {
                192.168.0.100 dev eth0 label eth0:1
    }
}
virtual_server 192.168.0.100 80 {
        delay_loop 3
        lb_algo wrr
        lb_kind DR
        protocol TCP
        real_server 192.168.99.105 80 {
                weight 1
                TCP_CHECK {
                connect_port 80
                        connect_timeout 4
                        retry 3
                        delay_before_retry 3
                }
        }
        real_server 192.168.99.106 80 {
                weight 1
                TCP_CHECK {
                connect_port 80
                connect_timeout 50
                retry 3
                delay_before_retry 3
                }
        }
}
  1. ka2的配置
[ka2]$ vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
       root@localhost
   }
   notification_email_from root@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka2
   vrrp_skip_check_adv_addr
#vrrp_strict
#vrrp_mcast_group4 224.100.100.100
   vrrp_iptables
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 11
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123
    }
    unicast_src_ip 192.168.99.104
    unicast_peer {
    192.168.99.103
    }
    virtual_ipaddress {
        192.168.0.100 dev eth0 label eth0:1
        192.168.0.101 dev eth0 label eth0:2
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 22
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123
    }
    unicast_src_ip 192.168.99.104
    unicast_peer {
        192.168.99.103
    }
    virtual_ipaddress {
        192.168.0.200 dev eth0 label eth0:3
        192.168.0.201 dev eth0 label eth0:4
    }
}
  1. ka1,和ka2都启动
[ka1]$ systemctl restart keepalived
[ka2]$ systemctl restart keepalived

ka1和ka2各有2个ip,因为各是各自的主服务器。
keepalived双主模型配置_第1张图片

keepalived双主模型配置_第2张图片

如果我们down掉其中一个(ka2),其上面的ip就会漂移到另一台主机上。这个ka1上就会有4个ip。重新把ka2启动,ip就会回到ka2上。
keepalived双主模型配置_第3张图片

你可能感兴趣的:(keepalived高可用集群)