The active-active scenario is possible using keepalived. You need to configure multiple vrrp_instance
s such as:
vrrp_sync_group G1 { # must be before vrrp_instance declaration
group {
vserver1
}
group {
vserver2
}
}
# The primary server
vrrp_instance vserver1 {
interface eth0
state MASTER
virtual_router_id 1
priority 100
advert_int 3
authentication {
auth_type PASS
auth_pass mypass
}
virtual_ipaddress {
VIP1/24 # default CIDR mask is /32
}
}
# The backup server
vrrp_instance vserver2 {
interface eth0
state backup
virtual_router_id 2
priority 50
advert_int 3
authentication {
auth_type PASS
auth_pass mypapas
}
virtual_ipaddress {
VIP2/24 # default CIDR mask is /32
}
}
The important point to have similar config on the 2nd node, but with different state
and priority
. In the shown example, you need to change these lines to make the other node MASTER
for VIP2 and BACKUP
for VIP1. By default each machine will have its VIP and when a failure occurs both VIPs as assigned to the remaining machine.
Of course, it can be done similarly for 3 machines. You need to define three vrrp_instance
s instead of two.