Keepalived+MariaDB10 configuration + dual master + high availability database
Keepalived+MariaDB10 configuration of dual master high availability database
OS
RS
Subnet mask
Routing gateway
Centos6.6
MariaDB10
Keepalived
Eth0:192.168.26.210
255.255.252.0
192.168.25.3
VIP:192.168.27.210
255.255.255.252
Centos6.6
MariaDB10
Keepalived
Eth0:192.168.26.211
255.255.252.0
192.168.25.3
VIP:192.168.27.210
255.255.255.255
Win7 (client)
IP:192.168.26.70
255.255.252.0
192.168.25.3
Install MYSQL on both servers:
Yum-y install MariaDB
Configure the dual master model after installation:
Edit the configuration file 26.210:vim / etc/my.cnf.d/server.cnf
Add the previous parameter settings to the configuration file:
Log-bin=mysql-bin
Server-id = 210,
Relay-log = relay-bin
Edit the configuration file 26.211:vim / etc/my.cnf.d/server.cnf
Log-bin = mysql-bin
Server-id = 211
Relay-log = relay-bin
Start the MYSQL service of two servers: service mysql start
The server sets dual hosts:
26.210:
Mysql
Grant replication slave, replication client on *. * to 'jerry'@'192.168.%.%' identified by' jerrypass'
Change master to master_host='192.168.26.211',master_user='jerrymy',master_password='jerrypass',master_log_file='mysql-bin.000006',master_log_pos=558
Start slave
Show slave status\ G; # View from status IO and SQL running status both YES indicates that the configuration is successful
26.211:
Mysql
Grant replication slave, replication client on *. * to 'jerrymy'@'192.168.%.%' identified by' jerrypass'
Change master to master_host='192.168.26.210',master_user='jerry',master_password='jerrypass',master_log_file='mysql-bin.000007',master_log_pos=540
Start slave
Show slave status\ G; # View from status IO and SQL running status both YES indicates that the configuration is successful
The display status is successful, and then we create a database to test to see if the two hosts are working properly.
The dual master setting was successful.
26.210: install Keepalived
Installation error did not install gcc
Yum-y install gcc
Yum-y install openssl-devel
Compiled successfully after installing the component:
Edit configuration file: vim / etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
Router_id mysql-ha
}
Vrrp_instance VI_1 {
State MASTER
Interface eth0
Virtual_router_id 20
Priority 100
Advert_int 1
Nopreempt
Authentication {
Auth_type PASS
Auth_pass 123456
}
Virtual_ipaddress {
192.168.27.210
}
}
Virtual_server 192.168.27.210 3306 {
Delay_loop 2
Lb_algo rr
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 192.168.26.210 3306 {
Weight 1
Notify_down / etc/keepalived/mysql.sh
TCP_CHECK {
Connect_port 3306
Connect_timeout 3
Nb_get_retry 2
Delay_before_retry 1
}
}
}
Save exit and start the Keepalived service.
Service keepalived start
26.211: install Keepalived.
Edit configuration file 26.211: vim / etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs {
Router_id mysql-ha
}
Vrrp_instance VI_1 {
State BACKUP
Interface eth0
Virtual_router_id 20
Priority 99
Advert_int 1
Nopreempt
Authentication {
Auth_type PASS
Auth_pass 123456
}
Virtual_ipaddress {
192.168.27.210
}
}
Virtual_server 192.168.27.210 3306 {
Delay_loop 2
Lb_algo rr
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 192.168.26.211 3306 {
Weight 1
Notify_down / etc/keepalived/mysql.sh
TCP_CHECK {
Connect_port 3306
Connect_timeout 3
Nb_get_retry 2
Delay_before_retry 1
}
}
}
Save exit start Keepalived on 26.211
Service keepalived start
Test if VIP is available: ping 192.168.27.210-t
You can go back to 26.210 or 211 to create a database to access and test the user's account password.
Grant all on *. * to 'jerrytest'@'192.168.%.%' identified by' jerrypass'
The following is to access the database through VIP to observe access:
VIP is on 26.210 of this server, so we access the database on 26.210.
Let's stop the MYSQL observation on 26.210:
First of all, observe the recovery after the fluctuation of the VIP network.
Database access succeeded:
VIP has been transferred to the mobile 26.211 server.
Let's restore the MYSQL database service observation on 26.210.