在使用keepalived进行MySQL主备切换时,可以通过以下步骤来启动MySQL:
vrrp_script chk_mysql {
script "/etc/init.d/mysql status"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.1
}
track_script {
chk_mysql
}
}
service keepalived start
这样,keepalived将会监控MySQL的运行状态,并在主服务器出现故障时自动切换到备服务器上提供服务。