mysql gtidプライマリ・スレーブ・レプリケーションの使用

71244 ワード

環境:
master:192.168.56.201
slave:192.168.56.211
1、主従ノードのサービスプロファイルの設定
1.1マスターノードの構成:

    
    
    
    
[mysqld]
binlog-format=ROW
server_id =1
log_slave_updates=1
#binlog-do-db = brent
#binlog-ignore-db = mysql
#replicate_ignore_db=mysql
#replicate_do_table=brent.t1
#replicate_ignore_table=brent.t2
#######GTID#######
gtid-mode = on
enforce-gtid-consistency = true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
report-port=3306
report-host=192.168.56.201

1.2、slaveノードを構成する:

    
    
    
    
[mysqld]
binlog-format=ROW
#################REPLICATE###############
server_id =11
log_slave_updates=1
#binlog-do-db = brent
#binlog-ignore-db = mysql
#replicate_ignore_db=mysql
#replicate_do_table=brent.t1
#replicate_ignore_table=brent.t2
#######GTID#######
gtid-mode = on
enforce-gtid-consistency = true
master-info-repository=TABLE
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
report-port=3306
report-host=192.168.56.211

2、複製ユーザーの作成
マスター側にレプリケーション・ユーザーを作成する

    
    
    
    
mysql> GRANT REPLICATION SLAVE ON *.* TO rpl@'%‘ IDENTIFIED BY 'rpl';

3、予備ノードに初期データセットを提供する
プライマリ・テーブルをロックし、プライマリ・ノードのデータをバックアップし、スレーブ・ノードに復元します.GTIDが有効になっていない場合は、バックアップ時にmasterでshow master statusコマンドを使用してバイナリログファイル名とイベント場所を表示し、slaveノードを後で起動するときに使用する必要があります.
ここで使用するmysqldumpコマンド:
mysqldump --lock-all-tables --all-databases  >suq.sql
slaveノードにデータをインポート
cat suq.sql |mysql
4、ノードからのコピースレッドを起動する
GTID機能が有効になっている場合は、次のコマンドを使用します.
mysql> CHANGE MASTER TO MASTER_HOST='master.magedu.com', MASTER_USER='rpl', MASTER_PASSWORD='rpl', 
MASTER_AUTO_POSITION=1;
###################################################################################
1.gtidでrelay_log_info_repository=table、master_info_repository=tableをtableに設定とmaster.infoとrelay.infoのデータはmysqlのテーブルに保存され、
それぞれ:
mysql.slave_master_info
mysql.slave_relay_info
mysql.slave_worker_info
2.gtidモードでエラーが発生しました.skip counterを使用してトランザクションをスキップすることはできません.トランザクションIDを空の値に設定する必要があります.具体的には、次のとおりです.
show slave statusを使用して現在のステータスを表示します.

    
    
    
    
Last_SQL_Error: Worker 1 failed executing transaction 'ca6ccc10-b5c5-11e5-aed5-08002775af00:911' at master log master-bin.000006, end_log_pos 280262; Could not execute Delete_rows event on table suq.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_END_OF_FILE; the event's master log FIRST, end_log_pos 280262
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: ca6ccc10-b5c5-11e5-aed5-08002775af00
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 160108 15:27:58
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: ca6ccc10-b5c5-11e5-aed5-08002775af00:331-911
Executed_Gtid_Set: 22e602cb-b5c8-11e5-aee4-08002775af00:1-2,
ca6ccc10-b5c5-11e5-aed5-08002775af00:1-910

retrieved_gtid_set:受信したトランザクションを表す
executed_gtid_set:完了したトランザクションを表します.
ここに複数のロー・テーブルがあるのは、uuidとトランザクションに対応する複数のプライマリまたは現在のプライマリです.
そのうち1-910は完了し、911トランザクションはエラーを報告しました.
このとき、このトランザクションをスキップします.

    
    
    
    
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set gtid_next='ca6ccc10-b5c5-11e5-aed5-08002775af00:911';
Query OK, 0 rows affected (0.00 sec)
 
mysql> begin;commit;
Query OK, 0 rows affected (0.00 sec)
 
Query OK, 0 rows affected (0.00 sec)
 
mysql> set gtid_next="automatic";
Query OK, 0 rows affected (0.00 sec)
 
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)

slave端子は正常です.

    
    
    
    
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.201
Master_User: rpl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000006
Read_Master_Log_Pos: 280293
Relay_Log_File: relay-bin.000005
Relay_Log_Pos: 451
Relay_Master_Log_File: master-bin.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: 280293
Relay_Log_Space: 1226
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: ca6ccc10-b5c5-11e5-aed5-08002775af00
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: ca6ccc10-b5c5-11e5-aed5-08002775af00:331-911
Executed_Gtid_Set: 22e602cb-b5c8-11e5-aee4-08002775af00:1-2,
ca6ccc10-b5c5-11e5-aed5-08002775af00:1-911
Auto_Position: 1

3.gtidモードを従来モードに変更
まずmy.cnfにgtid-mode=ONとenforce-gtid-consistency=ONを注記しmysqlを再起動
次に、文change master to master_を使用します.auto_potision=0;
最後に使用:
slave> CHANGE MASTER TO MASTER_HOST='192.168.56.201',
-> MASTER_USER='rpl',
-> MASTER_PASSWORD='rpl',
-> MASTER_LOG_FILE='master-bin.000003',
-> MASTER_LOG_POS=1174;