Share
Embed
Aurora MySQL のバージョンアップで Blue/Green デプロイを試してみた
JAWS-UG 浜松 AWS 勉強会 2022#12 2022/12/16
Transcript
28 slides
-
本日のネタ(自己紹介は省略) • 先日 RDS/Aurora の Blue/Green デプロイが登場 ◦ 対象は RDS(for
MySQL・MariaDB)と Aurora MySQL • Aurora MySQL v1 から v2・v3 へのバージョンアップを 試してみた 2 -
結果の要約 • binlog レプリケーション構築とエンドポイント切り替え をよしなにやってくれるので便利 • Aurora MySQL v1 →
v2 移行には使えそう ◦ v2 → v3 もおそらく同様 • v1 → v3 移行は 2 段階の Blue/Green デプロイが必要 ◦ 1 回の Blue/Green デプロイ(スイッチオーバー)では不可 3 -
おことわり • 内容は無保証です • 機能は日々進化する可能性があります ◦ 例 : v1 →
v2 の Green 環境作成は 12/1 頃サポート 4 -
関連記事 • Qiita に 3 本 ◦ 導入編 ▪ https://qiita.com/hmatsu47/items/cb69c0a4f0042b7666e7
◦ スイッチオーバー編 ▪ https://qiita.com/hmatsu47/items/922c4f23a1e66f948947 ◦ v1 → v3 失敗編 ▪ https://qiita.com/hmatsu47/items/9a5afb73d2774600fdd9 5 -
Blue/Green デプロイとは?(1/2) • 変更前と変更後のリソースを両方とも稼働させた状態で ◦ 今回の対象リソースは Aurora の DB クラスター
◦ Blue 環境 : 変更前のリソース(現在の本番リソース) ◦ Green 環境 : 変更後のリソース(新しい本番リソース候補) • Green 環境への移行や動作確認を進めて • 準備ができたら Green 環境を本番用に切り替える ◦ スイッチオーバー 6 -
Blue/Green デプロイを作成 (3/8) • Green 環境作成中に Blue 環境にデータを追加 11 mysql>
create database bg_test; Query OK, 1 row affected (0.02 sec) mysql> use bg_test; Database changed mysql> create table test_table (id int primary key auto_increment, val int not null, str text); Query OK, 0 rows affected (0.04 sec) mysql> insert into test_table set val = 100, str = 'abcdefg'; Query OK, 1 row affected (0.01 sec) mysql> insert into test_table set val = 110, str = 'ABCDEFG'; Query OK, 1 row affected (0.01 sec) -
Blue/Green デプロイを作成 (5/8) • 追加データの Green 環境への複製を確認 13 mysql> use
bg_test; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from test_table; +----+-----+---------+ | id | val | str | +----+-----+---------+ | 1 | 100 | abcdefg | | 2 | 110 | ABCDEFG | +----+-----+---------+ 2 rows in set (0.00 sec) -
Blue/Green デプロイを作成 (6/8) • Green 環境 v1 → v2 移行中に
Blue 環境にデータを追加 14 mysql> insert into test_table set val = 120, str = 'hijklmn'; Query OK, 1 row affected (0.01 sec) mysql> insert into test_table set val = 130, str = 'HIJKLMN'; Query OK, 1 row affected (0.01 sec) -
Blue/Green デプロイを作成 (8/8) • 追加データの Green 環境への複製を確認 16 mysql> select
* from test_table; +----+-----+---------+ | id | val | str | +----+-----+---------+ | 1 | 100 | abcdefg | | 2 | 110 | ABCDEFG | | 3 | 120 | hijklmn | | 4 | 130 | HIJKLMN | +----+-----+---------+ 4 rows in set (0.00 sec) -
Blue/Green 作成時に中でやってること(想像) • Blue 環境のクローンを作成 ◦ その際、Blue 環境の binlog ポジションを記憶
▪ ただし GTID を使っている場合はポジションが一意になるのでスキップ ◦ クローン完了後 binlog レプリケーション開始 • 必要に応じてクローンをインプレースアップグレード ◦ 事前に binlog レプリケーションを停止 ◦ 事後に binlog レプリケーションを再開 17 -
スイッチオーバー (1/5) • スイッチオーバー前に Blue 環境でバージョン確認 18 $ mysql -u
admin -h my56.cluster-XXXX.ap-northeast-1.rds.amazonaws.com -p (中略) mysql> select @@aurora_version; +------------------+ | @@aurora_version | +------------------+ | 1.23.4 | +------------------+ 1 row in set (0.01 sec) -
スイッチオーバー (5/5) • あらためて Blue 環境でバージョン確認 22 mysql> select @@aurora_version;
ERROR 2013 (HY000): Lost connection to MySQL server during query No connection. Trying to reconnect... Connection id: 42 Current database: *** NONE *** +------------------+ | @@aurora_version | +------------------+ | 2.11.0 | +------------------+ 1 row in set (0.03 sec) -
Green 環境を v2 → v3 にしてスイッチオーバー…? 23 • スイッチオーバー前に v3
へ バージョンアップ…!! -
スイッチオーバー時にやってくれること • 移行可能か確認 • binlog レプリケーション停止・解除 • Blue 環境のエンドポイント名を「old」付きに変更 ◦
クラスタ(読み取り専用含む)・インスタンスとも(↓も同様) • Green 環境のエンドポイント名を Blue 環境のものに変更 • タイムアウト時間を過ぎてしまったら切り戻し 25 -
その他(1/2) • クラスタと DB のパラメータグループで設定を揃える • binlog は MIXED 形式のみ
◦ ROW 形式は NG 26 -
その他(2/2) • 切り戻し方向の binlog レプリケーションは設定されない • スイッチオーバー時、旧 Blue 環境の read_only
が 1 に ◦ おそらく誤更新対策(明示的にエラーになるように) 27 mysql> select @@read_only; +-------------+ | @@read_only | +-------------+ | 1 | +-------------+ 1 row in set (0.00 sec) -
結果の要約(再) • binlog レプリケーション構築とエンドポイント切り替え をよしなにやってくれるので便利 • Aurora MySQL v1 →
v2 移行には使えそう ◦ v2 → v3 もおそらく同様 • v1 → v3 移行は 2 段階の Blue/Green デプロイが必要 ◦ 1 回の Blue/Green デプロイ(スイッチオーバー)では不可 28