patternsqlMinor
Client to use the slave when the master is down in MySQL replication
Viewed 0 times
theslavereplicationclientmasterdownmysqlwhenuse
Problem
Is it possible for the client to use the slave when the master is down in mysql replication?
I have already setup a simple mysql replication having a master and a slave.
The client connects to the master to access the database, any changes made to the master server is replication onto the slave. How shall I configure that when the master server is down, the client automatically connects to the slave server?
I am using MySQL Server 5.1 and MySQL workbench 5.2 CE. I edited the my.ini files for both master and slave.
The client uses a J2EE application.
What additional commands must I input in the master my.ini file to make the changes?
Also is there a way to increase or decrease the time interval between replications?
I have already setup a simple mysql replication having a master and a slave.
The client connects to the master to access the database, any changes made to the master server is replication onto the slave. How shall I configure that when the master server is down, the client automatically connects to the slave server?
I am using MySQL Server 5.1 and MySQL workbench 5.2 CE. I edited the my.ini files for both master and slave.
The client uses a J2EE application.
What additional commands must I input in the master my.ini file to make the changes?
Also is there a way to increase or decrease the time interval between replications?
Solution
Since you have Master/Slave, you may want to implement the use of two things
Circular Replication
Circular Replication is nothing more than first setting up Master/Slave then performing the same steps using the Slave as the Master's Master and the Master as the Slave's Slave. It just entails
Database Virtual IP (aka DBVIP)
There are products you can download and install to setup a DBVIP. One such product I use is
Since those products can perform automatic failover, you do not want to do that in the event a Slave is some number of seconds behind in replication lag.
You should perform manual failovers.
Here is a poor man's approach to implementing DBVIP management.
Suppose you have this setup
Create the Script called /usr/local/sbin/MyAppDBVIP like this
Create the Script called /usr/local/sbin/dbvip-up
Create the Script called /usr/local/sbin/dbvip-down
Make sure all scripts are executable
Make sure these script exist on both DB Servers
Simply run dbvip on whichever server you choose. .
So the failover process and protocol are the following:
- Circular Replication
- Database Virtual IP (aka DBVIP)
Circular Replication
Circular Replication is nothing more than first setting up Master/Slave then performing the same steps using the Slave as the Master's Master and the Master as the Slave's Slave. It just entails
- explicitly user a different server_id on each DB Server
- enabling binary logging on both DB servers
- making sure the replication user is defined on both DB servers
Database Virtual IP (aka DBVIP)
There are products you can download and install to setup a DBVIP. One such product I use is
ucarp. Another product is Linux Heartbeat. I normally do not use such things with MySQL Circular Replication or Master/Slave. Why?Since those products can perform automatic failover, you do not want to do that in the event a Slave is some number of seconds behind in replication lag.
You should perform manual failovers.
Here is a poor man's approach to implementing DBVIP management.
Suppose you have this setup
- DB Server1 has IP 10.1.2.30
- DB Server2 has IP 10.1.2.40
- You want to use DBVIP 10.1.2.50
Create the Script called /usr/local/sbin/MyAppDBVIP like this
echo echo 10.1.2.50 > /usr/local/sbin/MyAppDBVIPCreate the Script called /usr/local/sbin/dbvip-up
DBVIP=`/usr/local/sbin/MyAppDBVIP`
ip addr add ${DBVIP}/24 dev eth1Create the Script called /usr/local/sbin/dbvip-down
DBVIP=`/usr/local/sbin/MyAppDBVIP`
ip addr del ${DBVIP}/24 dev eth1Make sure all scripts are executable
chmod +x /usr/local/sbin/MyAppDBVIP
chmod +x /usr/local/sbin/dbvip-up
chmod +x /usr/local/sbin/dbvip-downMake sure these script exist on both DB Servers
Simply run dbvip on whichever server you choose. .
So the failover process and protocol are the following:
- Run
dbvip-downon the DB Server that has the DBVIP. If you cannot
- Run
dbvip-upon the DB Server that you want to have the DBVIP
- Just remember you should not run
dbvip-upon both machines
- After running
dbvip-up, restart apache, JBoss, or any other app server contacting MySQL via the old Master
Code Snippets
echo echo 10.1.2.50 > /usr/local/sbin/MyAppDBVIPDBVIP=`/usr/local/sbin/MyAppDBVIP`
ip addr add ${DBVIP}/24 dev eth1DBVIP=`/usr/local/sbin/MyAppDBVIP`
ip addr del ${DBVIP}/24 dev eth1chmod +x /usr/local/sbin/MyAppDBVIP
chmod +x /usr/local/sbin/dbvip-up
chmod +x /usr/local/sbin/dbvip-downContext
StackExchange Database Administrators Q#13192, answer score: 3
Revisions (0)
No revisions yet.