LoginSignup
5
2

More than 5 years have passed since last update.

AWS DMSでMySQLRDS→オンプレMySQLの継続的レプリケーション

Posted at

やりたいこと

AWS DMSを使用して、MySQLRDS→オンプレMySQLでの継続的レプリケーションのテスト

MySQLバージョン:5.7

以下の公式ドキュメントを参照しながら、MySQLRDSの設定を一つずつ確認していく
Amazon が管理する MySQL 互換データベースの AWS DMS のソースとしての使用

自動バックアップは有効である必要がある

image.png

binlog_formatがROWである必要がある

本来であればmy.cnfに書かれる設定で、RDSではパラメータグループで確認する

image.png

バイナリログ保持期間の変更

デフォルトの設定では、RDSやAuroraはすぐにバイナリログを消去するため、保持期間を長くする必要がある
binlogの保持期間を24hにする

変更前
MySQL [(none)]> call mysql.rds_show_configuration;
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| name                   | value | description                                                                                          |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| binlog retention hours | NULL  | binlog retention hours specifies the duration in hours before binary logs are automatically deleted. |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

変更
call mysql.rds_set_configuration('binlog retention hours', 24);

変更後確認
MySQL [(none)]> call mysql.rds_show_configuration;
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| name                   | value | description                                                                                          |
+------------------------+-------+------------------------------------------------------------------------------------------------------+
| binlog retention hours | 24    | binlog retention hours specifies the duration in hours before binary logs are automatically deleted. |
+------------------------+-------+------------------------------------------------------------------------------------------------------+

binlog_checksumをNONEにする必要がある

image.png

パラメータグループ変更

binlog_formatとbinlog_checksumが指定の値になっていないため、RDSパラメータグループを変更する

image.png

変更はdynamicなのでRDSの再起動を伴わないで実行される

変更確認
image.png

DMS実行

移行元でテスト用DBを作っておく

MySQL [(none)]> create database dms_test;
MySQL [(none)]> use dms_test;
Database changed
MySQL [dms_test]> create table testtable ( id INT , name VARCHAR(5) );
Query OK, 0 rows affected (0.05 sec)

MySQL [dms_test]> show tables;
+--------------------+
| Tables_in_dms_test |
+--------------------+
| testtable          |
+--------------------+
1 row in set (0.00 sec)

MySQL [dms_test]> insert into testtable values ( 1 , "taro");
Query OK, 1 row affected (0.01 sec)

MySQL [dms_test]>
MySQL [dms_test]> select * from testtable;
+------+------+
| id   | name |
+------+------+
|    1 | taro |
+------+------+

タスク作成→実行

以下の設定でタスクを作成する
タスク名:dms-cdc-test
移行タイプ:「既存のデータを移行して、継続的な変更をレプリケートする」
ロギングの有効化:チェック (CloudWatchログでタスクの実行ログを確認したいため)
テーブルマッピング:dms_testスキーマを選択

タスクを実行する
image.png
ステータスは準備完了になる。
この時点で、オンプレ側DBにはまだ何も移行されていない

開始/再開 ボタンをクリックするとタスクが開始される
image.png

移行先DBへのデータロードが完了すると、CloudWatchログに以下のように出力され、移行が完了する

Load finished for table 'dms_test','testtable'...

タスクのステータスは、「ロード完了、レプリケーション進行中」となる
image.png

移行先DBのデータを確認する。dms_testデータベースの移行が完了している

mysql> show databases;          mysql> select * from dms_test.testtable;        
+--------------------+          +------+------+     
| Database           |          | id   | name |     
+--------------------+          +------+------+     
| information_schema |          |    1 | taro |     
| awsdms_control     |          +------+------+     
| dms_test           |                  
| mysql              |                  
| performance_schema |                  
| sys                |                  
+--------------------+                  
8 rows in set (0.00 sec)

移行元DBにinsertする

MySQL [dms_test]> insert into testtable values ( 2,"ichi");                 
Query OK, 1 row affected, 1 warning (0.01 sec)                  

MySQL [dms_test]> select * from testtable;                  
+------+-------+                    
| id   | name  |                    
+------+-------+                    
|    1 | taro  |                    
|    2 | ichi  |                    
+------+-------+                    
2 rows in set (0.00 sec)

移行先DBでの反映を確認

mysql> select * from testtable;     
+------+-------+        
| id   | name  |        
+------+-------+        
|    1 | taro  |        
|    2 | ichi  |        
+------+-------+        
2 rows in set (0.00 sec)        

参考

バイナリログのフォーマットについて

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2