Keepalived is set to not preemptible resources, and keepalived is used to preemptible resources.
When keepalived is used for HA, it is often used to switch between a preemptible master and backup.
Example:
Generally, if the master service dies, the backup will become the master, but when the master service is ready, the master will seize the VIP, in this way, two switching operations will be difficult for busy websites. Therefore, we need to add nopreempt to the configuration file for non-preemption. However, this parameter can only be used when the state is backup, therefore, when using HA, it is best to set both the master and backup states to backup to allow them to compete through priority.
Note: after this configuration, we should pay attention to the order in which the keepalived service is started. If I want to make A backup, The keepalived service of A cannot be started first.
The following are examples of master and slave database configuration in the MHA architecture:
Master Database
[Root @ mysqltest ~] # More/etc/keepalived. conf
#20140916
#! /Bin/bash
Global_defs {
Router_id mysqlmha
}
Vrrp_script check_run {
Script "/etc/keepalived/check_mysql.sh"
Interval 1
}
Vrrp_instance VI_1 {
State BACKUP -- the status is specified as backup.
Interface eth0
Virtual_router_id 151
Priority100
Advert_int 1
Nopreempt -- set nopreempt to prevent resource Preemption
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Check_run
}
Virtual_ipaddress {
192.168.66.53
}
}
Slave Database
[Root @ ceshi ~] # More/etc/keepalived. conf
! Configuration File for keepalived
Global_defs {
Router_id mysqlmha
}
Vrrp_script check_run {
Script "/etc/keepalived/check_mysql.sh"
Interval 1
}
Vrrp_instance VI_1 {
State BACKUP
Interface eth0
Virtual_router_id 151
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Check_run
}
Virtual_ipaddress {
192.168.66.53
}
}