天天看點

mysql cluster 設定單向複制_配置master-master mysql cluster複制

1. 準備工作,修改配置

Master side:

set binlog_format:mysqld=mixed,sync_binlog:mysqld=1 c01_test;

set server_id:mysqld:51=51,log_bin:mysqld:51=/data/mcm_data/clusters/c01_test/51/data/binlog c01_test;

set server_id:mysqld:52=52,log_bin:mysqld:52=/data/mcm_data/clusters/c01_test/52/data/binlog c01_test;

mcm> get server_id:mysqld c01_test;

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

| Name | Value | Process1 | NodeId1 | Process2 | NodeId2 | Level | Comment |

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

| server_id | 51 | mysqld | 51 | | | | |

| server_id | 52 | mysqld | 52 | | | | |

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

2 rows in set (0.07 sec)

驗證:兩邊都執行下面的操作

show master status;

show slave status\G

select * FROM mysql.ndb_binlog_index;

select * from mysql.ndb_apply_status;

2. Master, create user

GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'slave_password';

3. Slave設定master的資訊

CHANGE MASTER TO

MASTER_HOST='192.168.1.14',

MASTER_PORT=3306,

MASTER_USER='slave_user',

MASTER_PASSWORD='slave_password';

對等:

CHANGE MASTER TO

MASTER_HOST='192.168.1.13',

MASTER_PORT=3306,

MASTER_USER='slave_user',

MASTER_PASSWORD='slave_password';

4.master:備份

ndb_mgm> START BACKUP WAIT COMPLETED;

Connected to Management Server at: localhost:1186

Waiting for completed, this may take several minutes

Node 1: Backup 4 started from node 50

ndb_mgm> Node 1: Backup 4 started from node 50 completed

StartGCP: 389082 StopGCP: 389085

#Records: 2156 #LogRecords: 0

Data: 63636 bytes Log: 0 bytes

5. slave:恢複

把每個datanode上的備份拷貝到slave的cluster上,再本地恢複

或在master上遠端恢複到slave,我用的是遠端恢複

ndb_restore -c 192.168.1.13:1186 -n 2 -b 4 -r -m ./2/data/BACKUP/BACKUP-4

ndb_restore -c 192.168.1.13:1186 -n 1 -b 4 -r -e ./1/data/BACKUP/BACKUP-4

第一個恢複-m參數恢複metadata是必需的,隻在第一個恢複的時候使用

最後一個恢複-e (or --restore-epoch)是必須的,這樣才能更新mysql.ndb_apply_status得内容

slave:檢視-e參數更新的資料

mysql> select * from mysql.ndb_apply_status;

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

| server_id | epoch | log_name | start_pos | end_pos |

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

| 0 | 1671111645331455 | | 0 | 0 |

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

1 row in set (0.00 sec)

master:取得LSN号

SELECT SUBSTRING_INDEX(File, '/', -1), Position

FROM mysql.ndb_binlog_index

WHERE epoch > 1671111645331455;

如果為空,則用show master status取得LSN号:

SHOW MASTER STATUS;

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

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| binlog.000001 | 112 | | |

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

1 row in set (0.00 sec)

7 slave:啟動slave:

CHANGE MASTER TO MASTER_LOG_FILE='binlog.000001', MASTER_LOG_POS=112;

start slave;

show slave status\G

對等:

CHANGE MASTER TO MASTER_LOG_FILE='binlog.000001', MASTER_LOG_POS=268;

start slave;

show slave status\G

8. 驗證

兩邊執行更新,檢視是否複制成功

下面的查詢應該有資料了

select * FROM mysql.ndb_binlog_index;

select * from mysql.ndb_apply_status;

閱讀(2333) | 評論(0) | 轉發(0) |