Configuring keepalive for MySQL dual master high Availability
1. Installing KeepAlive
2 . Configure KeepAlive
Global_defs {
Notification_email {
[Email protected]
[Email protected]
[Email protected]
}
Router_idmysql_ha
}
Vrrp_script Check_mysqld {
Script "/etc/keepalived/mysqlcheck/keepalived_check_mysql.sh"
Interval 2
}
Vrrp_instance ha_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100
Advert_int 1
Nopreempt
authentication{
Auth_typepass
auth_pass1111
}
Track_script {
Check_mysqld
}
virtual_ipaddress {
192.168.32.100/24 Dev eth0
}
}
Two keepalive of state are set to backup
Check MySQL script keepalived_check_mysql.sh
#!/bin/bash
Mysql=/usr/bin/mysql
Mysql_host=localhost
Mysql_user=root
Mysql_password=www.123
Check_time=3
#mysql is WORKINGMYSQL_OK are 1, MySQL MYSQL_OK is 0
Mysql_ok=1
function Check_mysql_helth () {
$MYSQL-H $MYSQL _host-u $MYSQL _user-p${mysql_password}-e "show status;" >/dev/null 2>&1
If [$ = 0]; then
Mysql_ok=1
Else
Mysql_ok=0
Fi
return $MYSQL _OK
}
While [$CHECK _time-ne 0]
Do
Let "check_time-= 1"
Check_mysql_helth
if [$MYSQL _OK = 1]; Then
Check_time=0
Exit 0
Fi
If [$MYSQL _ok-eq 0] && [$CHECK _time-eq 0]
Then
/etc/init.d/keepalived stop
Exit 1
Fi
Sleep 1
Done
/etc/init.d/keepalived start
Test High Availability: When you turn off DB1 MySQL. His VIP will float to DB2.
Test MySQL master-slave sync function
1. Log on to the remote client through the VIP login test
2. data copy function test
A database was created in DB1. See if you have this database in DB2
This article from "Do not abandon!" Do not give up "blog, be sure to keep this source http://6437769.blog.51cto.com/6427769/1654372
Configuring keepalive for MySQL dual master high Availability