4

I want to setup 2 node master-master replication. Im aware of the point of failiures in this replication. Its a huge database around 1.5TB. Heavy OLTP is going on. But its mandatory to implement right now.

I have 2 servers.

 1. Master1 
 2. Master2

Initially what I did is,

Master1:

  • Make changes my.cnf for replication.

  • Take mysqldump with --master-data=2 (For getting exact binlog position)

Master2:

  • Restore dump to Master2.

  • Make changes on my.cnf.

  • set replication to Master1 (Change master='Master1').

  • Start Slave.

Now Master1 is replicating to Master2.

Then I need to replicate the Master2 to Master1. Just take the binlog position and set replication on Master1 will work, but the problem is binog file and position is changing frequently. So before execute the Change master command on Master1 the binog get changed.

How can I achive this without downtime.

2 Answers 2

2

I am glad you were able to mysqldump 1.5TB database. You are sure patient.

Now for the reality check. You will some downtime for reboots and pausing.

No need to mysqldump anymore.

STEP 01

Did you put this line in /etc/my.cnf on both Master1 and Master2 ?

log-slave-updates

If you not sure, run this on both Master1 and Master

select @@global.log_slave_updates;

If you get this on both Master1 and Master2

mysql> select @@global.log_slave_updates;
+----------------------------+
| @@global.log_slave_updates |
+----------------------------+
|                          1 |
+----------------------------+
1 row in set (0.00 sec)

then goto STEP 02.

This needs to be in /etc/my.cnf on both Master1 and Master2.

If you did not, please add it and restart mysqld on both Master1 and Master2.

STEP 02

Did you enable binary logging on Master2 ?

You should have a line in Master1's /etc/my.cnf like this

log-bin = ....

Please make sure Master2 has it.

If you are not sure if it has it, login to MySQL on Master2 and run

mysql> show binary logs;

If it echoes

mysql> show binary logs;
ERROR 1381 (HY000): You are not using binary logging

Then, add that log-bin line to /etc/my.cnf in Master2 and restart mysql in Master2.

Once log-slave-updates and log-bin have been enabled on both Master1 and Master2, you are ready to setup replication in the other direction

STEP 03

On Master2

STOP SLAVE;
FLUSH TABLES;
FLUSH LOGS;
SHOW BINARY LOGS;

STEP 04

On Master1

CHANGE MASTER TO
    MASTER_HOST='IP or Hostname of Master2',
    MASTER_PORT=3306,
    MASTER_USER='...',
    MASTER_PASSWORD='...',
    MASTER_LOG_FILE='First Binary Log On Master2',
    MASTER_LOG_POS=4
;
SHOW SLAVE STATUS\G

STEP 05

Test Connectivity from Master1 to Master2

On Master1

START SLAVE IO_THREAD;
DO SLEEP(10);
SHOW SLAVE STATUS\G

Look for Slave_IO_Running. It should be 'Yes'.

Run SHOW SLAVE STATUS\G like 3-5 times. Relay_Log_Space should be increasing.

STEP 06

Start processing SQL from Relay Logs

Run this on Master1

START SLAVE SQL_THREAD;
DO SLEEP(10);
SHOW SLAVE STATUS\G

Look for Slave_SQL_Running. It should be 'Yes'.

Look for Seconds_Behind_Master. It should be 0. If it greater than 0, keep running SHOW SLAVE STATUS\G until Seconds_Behind_Master is 0.

2
  • 1
    Thanks, Is any other way to setup initial replication without mysqldump? its taking more time and resource.
    – TheDataGuy
    Apr 7, 2017 at 4:21
  • Step 4 must be changed to CHANGE MASTER in newer versions.
    – Rick James
    Apr 7, 2017 at 5:43
1

As I'm not able to comment yet I need to write a new answer. I would like to add to the 6 steps of @RolandoMySQLDBA that the CHANGE MASTER TO command did not work for me. As the last command of STEP 03 you should run

SHOW MASTER STATUS;

instead of

SHOW BINARY LOGS;

and use the respective output as MASTER_LOG_FILE and MASTER_LOG_POS in the CHANGE MASTER TO command of STEP 04.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.