First, address planning
vip:10.10.0.228
Mastera ip:10.10.0.224
Masterb ip:10.10.0.226
Second, MySQL dual hot-hot standby master-master
1. Install MySQL (compile or yum install)
2, configure Mastera, modify the configuration file, add the following content
# VIM/ETC/MY.CNF
Log-bin=mysql-bin
Log=/home/mysqld.log
server-id=1
Binlog-do-db=data1
auto-increment-increment=2
auto-increment-offset=2
Configure Masterb, modify the configuration file, add the following content
# VIM/ETC/MY.CNF
Log-bin=mysql-bin
Log=/home/mysqld.log
server-id=2
Binlog-do-db=data1
auto-increment-increment=2
auto-increment-offset=2
3. Authorized users
Mastera:
mysql> grant replication Slave on * * to [e-mail protected] identified by ' 123456 ';
mysql> flush Privileges;
Masterb:
mysql> grant replication Slave on * * to [e-mail protected] identified by ' 123456 ';
mysql> flush Privileges;
4. Prepare to copy
Mastera:
Mysql> Show Master Status\g
Masterb:
Mysql> Show Master Status\g
5. Configure synchronization
Mastera:
mysql> Change Master to master_host= ' 10.10.0.226 ', master_user= ' user ',
Master_password= ' 123456 ', master_log_file= ' mysql-bin.000010 ', master_log_pos=106;
Masterb:
mysql> Change Master to master_host= ' 10.10.0.224 ', master_user= ' user ',
Master_password= ' 123456 ', master_log_file= ' mysql-bin.000010 ', master_log_pos=106;
6. Test verification Synchronization
Mastera:
mysql>show Slave Status \g
Slave_io_running:yes These two indicate yes for OK
Slave_sql_running:yes
Master B:
mysql>show Slave Status \g
Slave_io_running:yes These two indicate yes for OK
Slave_sql_running:yes
Master A:
Create a database
mysql> create databases data1;
Master B:
mysql> show databases;
Can discover database data1
Master B:
Create a table in the small database, T1:
mysql> CREATE TABLE T1 select * from Mysql.user;
Master A :
See data1 below for T1 this form:
Mysql> Show tables;
Iii. configuring keepalived for High Availability
Mastera:
# yum Install Keepalived-y
# vim/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_slave
}
Vrrp_script Check_mysqld {
Script "/etc/keepalived/check_slave.pl 127.0.0.1"
Interval 2
Weight 21
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Check_mysqld
}
virtual_ipaddress {
10.10.0.228/12 Dev eth0 label eth0:0
}
}
Masterb:
1, installation keepalived
# yum Install Keepalived-y
2. Configuration
# vim/etc/keepalived/keepalived.conf
! Configuration File for Keepalived
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_slave
}
Vrrp_script Check_mysqld {
Script "/etc/keepalived/check_slave.pl 127.0.0.1"
Interval 2
Weight 21
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 80
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Check_mysqld
}
virtual_ipaddress {
10.10.0.228/12 Dev eth0 label eth0:0
}
}
3. Create a monitoring script in Mastera and masterb to monitor MySQL service startup and MySQL synchronization is normal
# vim/etc/keepalived/check_slave.sh
#!/bin/bash
mysql=$ (mysql-n-s-e "SELECT 10")
If [$?-ne 0] | | ["$Mysql"-ne "10"]
Then
Service keepalived Stop
Exit 1
Else
Slavestatus= ($ (mysql-e "show slave status\g;" | grep "_behind|_running" |awk ' {print $NF} '))
if ["$SlaveStatus [0]" = "No"] | | ["${slavestatus[1]}" = "No"]
Then
Service keepalived Stop
Fi
Fi
4. Start keepalived
# service Keepalived Start
can refer to
http://emg2012.blog.51cto.com/3705315/1616393
This article is from the "ngames" blog, make sure to keep this source http://ngames.blog.51cto.com/3187187/1630595
keepalived for MySQL dual master high availability