I have already managed to configure a setup where I have a master and a backup machine, so when the master fails the backup goes back up. And when the master starts again, it takes the master position and the backup takes the backup once again.
My question is how can I configure keepalived so that if one machine fails and the other becomes master, it stays master until it fails itself? Meaning I don't want to have static master and backup, I need them to be interchangeable. When one of them fails the other becomes master and when the first goes back up it becomes the second machine's backup.
The reason I am asking this is because I'm trying to setup mysql replication. So whenever I have a master I want the backup machine to be slaved to that machine and to replicate data, and if the master dies I want there to be a transition which holds the master position so that it can take new data. When the first machine goes back up I want it to replicate the new data and keep listening.
Any tips will be appreciated.
This is my current keepalived configuration
Master:
global_defs {
script_user root root
}
vrrp_script chk_mysql {
script "/home/replication_scripts/checker.sh"
interval 2 # every 2 seconds
rise 2
fall 2
weight 10
}
vrrp_instance ctrl1 {
state MASTER
advert_int 1
interface br-data0
virtual_router_id 100
priority 100
unicast_src_ip 10.3.80.102
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
chk_mysql
}
virtual_ipaddress {
10.3.80.101/16 dev br-data0
}
notify_backup /home/replication_scripts/to_backup.sh
notify_master /home/replication_scripts/to_master.sh
}
Backup:
global_defs {
script_user root root
}
vrrp_script chk_mysql {
script "/home/replication_scripts/checker.sh"
interval 2 # every 2 seconds
fall 2
rise 2
weight 10
}
vrrp_instance ctrl2 {
state BACKUP
interface br-data0
virtual_router_id 100
priority 100
unicast_src_ip 10.3.80.103
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
chk_mysql
}
virtual_ipaddress {
10.3.80.101/16 dev br-data0
}
notify_master /home/replication_scripts/to_master.sh
notify_backup /home/replication_scripts/to_backup.sh
}