データ移行を使用してデータを移行する

このガイドでは、データ移行 (DM) ツールを使用してデータを移行する方法について説明します。

ステップ 1: DM クラスターをデプロイ

TiUP を使用して DM クラスターを展開するにおすすめです。トライアルまたはテスト用にバイナリを使用して DM クラスターを展開するを使用することもできます。

ノート:

  • すべての DM 構成ファイルのデータベース パスワードについては、 dmctlで暗号化されたパスワードを使用することをお勧めします。データベースのパスワードが空の場合、暗号化する必要はありません。 dmctl を使用してデータベース パスワードを暗号化するを参照してください。
  • アップストリーム データベースとダウンストリーム データベースのユーザーには、対応する読み取り権限と書き込み権限が必要です。

ステップ 2: クラスター情報を確認する

TiUP を使用して DM クラスターをデプロイすると、構成情報は以下のようになります。

  • DM クラスター内の関連コンポーネントの構成情報:

    成分ホストポート
    dm_worker1172.16.10.728262
    dm_worker2172.16.10.738262
    dm_master172.16.10.718261
  • 上流および下流のデータベース インスタンスの情報:

    データベース インスタンスホストポートユーザー名暗号化パスワード
    アップストリーム MySQL-1172.16.10.813306VjX8cEeTX+qcvZ3bPaO4h0C80pe/1aU=
    アップストリーム MySQL-2172.16.10.823306VjX8cEeTX+qcvZ3bPaO4h0C80pe/1aU=
    ダウンストリーム TiDB172.16.10.834000

MySQL ホストで必要な権限のリストは、 事前チェックドキュメントに記載されています。

ステップ 3: データ ソースを作成する

  1. MySQL-1 関連の情報をconf/source1.yamlに書き込みます。

    # MySQL1 Configuration.
    
    source-id: "mysql-replica-01"
    # This indicates that whether DM-worker uses Global Transaction Identifier (GTID) to pull binlog. Before you use this configuration item, make sure that the GTID mode is enabled in the upstream MySQL.
    enable-gtid: false
    
    from:
      host: "172.16.10.81"
      user: "root"
      password: "VjX8cEeTX+qcvZ3bPaO4h0C80pe/1aU="
      port: 3306
    
  2. ターミナルで次のコマンドを実行し、 tiup dmctlを使用して MySQL-1 データ ソース構成を DM クラスターにロードします。

    tiup dmctl --master-addr 172.16.10.71:8261 operate-source create conf/source1.yaml
    
  3. MySQL-2 の場合、構成ファイル内の関連情報を変更し、同じdmctlコマンドを実行します。

ステップ 4: データ移行タスクを構成する

次の例では、上流の MySQL-1 と MySQL-2 の両方のインスタンスのtest_dbデータベースにあるすべてのtest_tableテーブル データを、フル データと増分データで、TiDB のtest_dbデータベースにある下流のtest_tableテーブルに移行する必要があると想定しています。モード。

task.yamlのタスク構成ファイルを次のように編集します。

# The task name. You need to use a different name for each of the multiple tasks that
# run simultaneously.
name: "test"
# The full data plus incremental data (all) migration mode.
task-mode: "all"
# The downstream TiDB configuration information.
target-database:
  host: "172.16.10.83"
  port: 4000
  user: "root"
  password: ""

# Configuration of all the upstream MySQL instances required by the current data migration task.
mysql-instances:
-
  # The ID of upstream instances or the migration group. You can refer to the configuration of `source_id` in the "inventory.ini" file or in the "dm-master.toml" file.
  source-id: "mysql-replica-01"
  # The configuration item name of the block and allow lists of the name of the
  # database/table to be migrated, used to quote the global block and allow
  # lists configuration that is set in the global block-allow-list below.
  block-allow-list: "global"  # Use black-white-list if the DM version is earlier than or equal to v2.0.0-beta.2.
  # The configuration item name of the dump processing unit, used to quote the global configuration of the dump unit.
  mydumper-config-name: "global"

-
  source-id: "mysql-replica-02"
  block-allow-list: "global"  # Use black-white-list if the DM version is earlier than or equal to v2.0.0-beta.2.
  mydumper-config-name: "global"

# The global configuration of block and allow lists. Each instance can quote it by the
# configuration item name.
block-allow-list:                     # Use black-white-list if the DM version is earlier than or equal to v2.0.0-beta.2.
  global:
    do-tables:                        # The allow list of upstream tables to be migrated.
    - db-name: "test_db"              # The database name of the table to be migrated.
      tbl-name: "test_table"          # The name of the table to be migrated.

# The global configuration of the dump unit. Each instance can quote it by the configuration item name.
mydumpers:
  global:
    extra-args: ""

ステップ 5: データ移行タスクを開始する

データ移行構成の潜在的なエラーを事前に検出するために、DM は事前チェック機能を提供します。

  • DM は、データ移行タスクの開始時に、対応する権限と構成を自動的にチェックします。
  • check-taskコマンドを使用して、上流の MySQL インスタンス構成が DM 要件を満たしているかどうかを手動で事前チェックすることもできます。

事前チェック機能の詳細については、 アップストリームの MySQL インスタンス構成を事前チェックするを参照してください。

ノート:

初めてデータ移行タスクを開始する前に、アップストリームを構成しておく必要があります。そうしないと、タスクの開始時にエラーが報告されます。

tiup dmctlコマンドを実行して、データ移行タスクを開始します。 task.yamlは、上で編集した構成ファイルです。

tiup dmctl --master-addr 172.16.10.71:8261 start-task ./task.yaml
  • 上記のコマンドが次の結果を返す場合、タスクが正常に開始されたことを示します。

    {
        "result": true,
        "msg": "",
        "workers": [
            {
                "result": true,
                "worker": "172.16.10.72:8262",
                "msg": ""
            },
            {
                "result": true,
                "worker": "172.16.10.73:8262",
                "msg": ""
            }
        ]
    }
    
  • データ移行タスクの開始に失敗した場合は、返されたプロンプトに従って構成を変更し、 start-task task.yamlコマンドを実行してタスクを再開します。

ステップ 6: データ移行タスクを確認する

タスクの状態を確認する必要がある場合、または特定のデータ移行タスクが DM クラスターで実行されているかどうかを確認する必要がある場合は、次のコマンドをtiup dmctlで実行します。

tiup dmctl --master-addr 172.16.10.71:8261 query-status

ステップ 7: データ移行タスクを停止する

データを移行する必要がなくなった場合は、 tiup dmctlで次のコマンドを実行してタスクを停止します。

tiup dmctl --master-addr 172.16.10.71:8261 stop-task test

testは、 task.yaml構成ファイルのname構成項目で設定したタスク名です。

ステップ 8: タスクを監視してログを確認する

Prometheus、Alertmanager、および Grafana が、TiUP を使用した DM クラスターのデプロイと共に正常にデプロイされ、Grafana アドレスが172.16.10.71であると仮定します。 DM に関連するアラート情報を表示するには、ブラウザーでhttp://172.16.10.71:9093を開いて Alertmanager に入ります。モニタリング指標を確認するには、 http://172.16.10.71:3000に進み、DM ダッシュボードを選択します。

DM クラスターが実行されている間、DM-master、DM-worker、および dmctl はログを介して監視メトリック情報を出力します。各コンポーネントのログ ディレクトリは次のとおりです。

  • DM-master ログ ディレクトリ: --log-file DM-master プロセス パラメータによって指定されます。 DM が TiUP を使用して展開されている場合、ログ ディレクトリは DM-master ノードの{log_dir}です。
  • DM-worker ログ ディレクトリ: --log-file DM-worker プロセス パラメータで指定されます。 DM が TiUP を使用してデプロイされている場合、ログ ディレクトリは DM-worker ノードの{log_dir}です。
エコシステム
TiDB
TiKV
TiFlash
TiSpark
Chaos Mesh
© 2023 PingCAP. All Rights Reserved.