MULTIMASTER REPLICATION MYSQL
Multi-master replication is a method of database replicaton which allows data to be stored by a group of computers, and updated by any member of the group. All members are responsive to client data queries. The multi-master replication system is responsible for propagating the data modifications made by each member to the rest of the group, and resolving any conflicts that might arise between concurrent changes made by different members.
Multi-master replication can be contrasted with master-slave replication, in which a single member of the group is designated as the "master" for a given piece of data and is the only node allowed to modify that data item. Other members wishing to modify the data item must first contact the master node. Allowing only a single master makes it easier to achieve consistency among the members of the group, but is less flexible than multi-master replication.
Multi-master replication can also be contrasted with failover clustering where passive slave servers are replicating the master data in order to prepare for takeover in the event that the master stops functioning. The master is the only server active for client interaction.
Multi-master replication is a method of database replication which allows data to be stored by a group of computers, and updated by any member of the group. All members are responsive to client data queries.Master1 acts as the master for Master2, Master2 acts as the master for master1.
We have three mysql server.
1. 192.168.122.47 (Master1/ Slave2 redhat 6.5 )
2. 192.168.122.251 (Master2 /Slave1 redhat 6.5)
3. 192.168.122.235 (Slave redhat 6.5)
Now start with master1
[root@master1~]# yum install mysql mysqlserver y
[root@master1~]# mysql_secure_installation
[root@master1~]# yum install mysql mysqlserver y
[root@master1~]# mysql_secure_installation
[root@master1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symboliclinks=0
serverid = 1
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
save
[root@master1 ~]# mysql u root p
password:
mysql> slave stop;
GRANT REPLICATION SLAVE ON *.* TO 'raj'@'%' IDENTIFIED BY 'keenable@123';
mysql> FLUSH PRIVILEGES;
mysql> FLUSH READ LOCK WITH TABLES;
mysql> salve start;
mysql> show master status;
mysql> show master status;
+------------------+----------+--------------+-------------------------+
|
File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+-------------------------+
|
mysql-bin.000004 | 331 | | |
+------------------+----------+--------------+-------------------------+
mysql> \qNow take dump of all database and copy to master2 before this once again going to master1 for
unloack table
[root@master1 ~]# mysqldump -u root -p --all-databases > /root/dbdump.db
[root@master1 ~]# mysql -p
password:
mysql> uloack tables;
mysql> \q
[root@master1~]# scp r alldb.dbroot@master2.replication.com:
password:
Now going to master2 and import db
[root@master2 ~]#mysql u root p < /root/dbdump.db
[root@master2 ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symboliclinks is recommendedsymboliclinks=0
to prevent assorted security risks
serverid = 2
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
##############Entry for Master#############
masterhost=192.168.122.47
masterconnectretry=60
masteruser=raj
masterpassword=keenable@123
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
[mysqld_safe]
logerror=/var/log/mysqld.log
pidfile=/var/run/mysqld/mysqld.pid
save & quite
NOTE: Login into master2 as root user and stop the slave. Then tell the slave to where to look for Master1 log file, that we have write down on master with SHOW MASTER STATUS; command as File (mysqlbin.000004) and Position (331)
numbers. You must change 192.168.122.47to the IPaddress of the Master1 Server, and change the user and password accordingly.
[root@master2~]#mysql u root p
password:
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='192.168.122.47',
MASTER_USER='raj',
MASTER_PASSWORD='keenable@123', MASTER_LOG_FILE='mysqlbin.000004',
MASTER_LOG_POS=331;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to sendMaster_Host: 192.168.122.47
Master_User: raj
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlbin.000004
Read_Master_Log_Pos: 331
Relay_Log_File: mysqlrelaybin.000013
Relay_Log_Pos: 251
Relay_Master_Log_File: mysqlbin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 331
Relay_Log_Space: 551
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
event
mysql> show master status;
+------------------+----------+--------------+-------------------------+
|
File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+-------------------------+
|
mysql-bin.000004 | 185 | | |
+------------------+----------+--------------+-------------------------+
Now time to configure master master replication
Come back to msater1 and edit config file (my.cnf)
[root@master1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symboliclinks=0
serverid = 1
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
####Second step After done MasterSlave [This entry for master]####
masterhost=192.168.122.251
masterconnectretry=60
masteruser=raj
masterpassword=keenable@123
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
[mysqld_safe]
logerror=/var/log/mysqld.log
pidfile=/var/run/mysqld/mysqld.pid
save & quite
restart the mysql service and check master1.
[root@master1 ~]# /etc/init.d/mysqld restart
[root@master1 ~]# mysql u root p
password:
mysql> STOP SLAVE;
mysql> CHANGE MASTER TO MASTER_HOST='192.168.122.251', MASTER_USER='raj',
MASTER_PASSWORD='keenable@123', MASTER_LOG_FILE='mysqlbin.000004',
MASTER_LOG_POS=185;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to sendMaster_Host: 192.168.122.251
Master_User: raj
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlbin.000004
Read_Master_Log_Pos: 185
Relay_Log_File: mysqlrelaybin.000024
Relay_Log_Pos: 251
Relay_Master_Log_File: mysqlbin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 185
Relay_Log_Space: 551
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
event
Now go to master2 and edit my.cnf file for create master-master
[root@master2 ~]#vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symboliclinkssymboliclinks=0
is recommended to prevent assorted security risks
serverid = 2
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
########Entry for salve server as mster#############3
masterhost=192.168.122.47
masterconnectretry=60
masteruser=raj
masterpassword=keenable@123
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
[mysqld_safe]
logerror=/var/log/mysqld.log
pidfile=/var/run/mysqld/mysqld.pid
save & quite
[root@master1 ~]# /etc/init.d/mysqld restart
[root@master1 ~]# mysql -p
password:
Now create database school on master1 & keenable on master2 and check on both master server
mysql> create database school;=====[Master1]
mysql> create database keenable; ===[Master2]
mysql> show databases;
+------------------------------+
| Database |
+------------------------------+
|
information_schema |
|
mysql |
|
school |
|
keenable |
+------------------------------+
4
rows in set (0.00 sec)
Master2
mysql -p
password:
mysql> show databases;
+----------------------------+
| Database |
+--------
-------------------+
|
information_schema |
|
mysql |
|
school |
|
keenable |
+----------------------------+
4
rows in set (0.00 sec)
Now time to configure slave server
Slave [192.168.122.235]
[root@slave ~]# yum install mysql mysqserver
[root@slave ~]# mysql_secure_installation
[root@slave ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symboliclinks is recommended to prevent assorted securitysymboliclinks=0
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
[mysqld_safe]
logerror=/var/log/mysqld.log
pidfile=/var/run/mysqld/mysqld.pid
risks
#####Entry for Slave#######
masterhost=192.168.122.47
masterconnectretry=60
masteruser=slave_user
masterpassword=keenable@123
serverid = 3
relaylog = /var/lib/mysql/mysqlrelaybin
relaylogindex = /var/lib/mysql/mysqlrelaybin.index
logerror = /var/lib/mysql/mysql.err
masterinfofile = /var/lib/mysql/mysqlmaster.info
relayloginfofile = /var/lib/mysql/mysqlrelaylog.info
logbin = /var/lib/mysql/mysqlbin
save & quite
Restart mysql service
[root@slave ~]# /etc/init.d/mysqldrestart
[root@slave ~]# /etc/init.d/mysqld restart
[root@slave ~]# mysq uroot p
password:
mysql> slave stop;
mysql> CHANGE MASTER TO MASTER_HOST='192.168.122.47', MASTER_USER='raj',
MASTER_PASSWORD='keenable@123', MASTER_LOG_FILE='mysqlbin.000005',
MASTER_LOG_POS=588;
mysql> slave start;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.122.47
Master_User: raj
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlbin.000005
Read_Master_Log_Pos: 588
Relay_Log_File: mysqlrelaybin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysqlbin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 588
Relay_Log_Space: 406
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert:Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
No
NOTE: All database show into slave. And check on all server connecting master1 master2 and slave each other master to master and master
slave.
[root@slave ~]# mysq u root p
password:
mysql> show databases;
+-------------------------+
|
Database |
+-------------------------+
|
information_schema |
|
mysql |
|
school |
|
keenable |
+-------------------------+
4
rows in set (0.00 sec)
Now successfully run multi-master replication.
No comments:
Post a Comment