1. 程式人生 > >49、mysql多源複製實戰

49、mysql多源複製實戰

在master1上

vim /etc/my.cnf

[mysqld]

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/mydata/data

log-bin=/mydata/binlog/log-bin

server-id=1

bind-address = 0.0.0.0

skip-name-resolve


mysql


GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repluser'@'192.168.130.%' IDENTIFIED BY 'replpass';


FLUSH PRIVILEGES;


mysql> show master status;

+----------------+----------+--------------+------------------+-------------------+

| File           | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+----------------+----------+--------------+------------------+-------------------+

| log-bin.000017 |      154 |              |                  |                   |

+----------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)



在master2上

vim /etc/my.cnf

[mysqld]

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/mydata/data

log-bin=/mydata/binlog/log-bin

server-id=2

bind-address = 0.0.0.0

skip-name-resolve


mysql


GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repluser'@'192.168.130.%' IDENTIFIED BY 'replpass';


FLUSH PRIVILEGES;



mysql>  show master status;

+----------------+----------+--------------+------------------+-------------------+

| File           | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+----------------+----------+--------------+------------------+-------------------+

| log-bin.000017 |      154 |              |                  |                   |

+----------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)



在slave上

vim /etc/my.cnf

[mysqld]

socket=/tmp/mysql.sock

basedir=/usr/local/mysql

datadir=/mydata/data

#log-bin=/mydata/binlog/log-bin

server-id=3

relay-log = /mydata/binlog/relay-bin

bind-address = 0.0.0.0

skip-name-resolve

master_info_repository=TABLE

relay_log_info_repository=TABLE


SHOW GLOBAL VARIABLES LIKE '%repository%';

~                                    


CHANGE MASTER TO MASTER_HOST='192.168.130.61', MASTER_USER='repluser', MASTER_PASSWORD='replpass', MASTER_LOG_FILE='log-bin.000017', MASTER_LOG_POS=154 FOR CHANNEL 'Master_1';

START SLAVE FOR CHANNEL  'Master_1';

SHOW SLAVE STATUS FOR CHANNEL 'Master_1'\G;


CHANGE MASTER TO MASTER_HOST='192.168.130.62', MASTER_USER='repluser', MASTER_PASSWORD='replpass', MASTER_LOG_FILE='log-bin.000017', MASTER_LOG_POS=154 FOR CHANNEL 'Master_2';

START SLAVE FOR CHANNEL  'Master_2';

SHOW SLAVE STATUS FOR CHANNEL 'Master_2'\G;