Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

RDS MariaDB ソースの設定ガイド

これは、MySQL ClickPipe 経由でデータをレプリケーションするために、RDS MariaDB インスタンスを設定する手順をまとめたガイドです。


バイナリログの保持を有効にする

バイナリログは、MySQL server インスタンスで行われたデータ変更に関する情報を含むログファイルの集合です。バイナリログファイルはレプリケーションに必要です。以下の両方の手順を実行する必要があります。

自動バックアップでバイナリログを有効にする

自動バックアップ機能によって、MySQL のバイナリログを有効にするかどうかが決まります。これは AWS コンソールで設定できます。

RDS で自動バックアップを有効にする

レプリケーションのユースケースに応じて、バックアップ保持期間を十分長く設定することをお勧めします。

binlog の保持時間

Amazon RDS for MariaDB では、binlog の保持期間 (変更内容を含む binlog ファイルを保持しておく時間) の設定方法が異なります。binlog ファイルが削除される前に一部の変更が読み取られないと、レプリケーションを継続できなくなります。binlog retention hours のデフォルト値は NULL で、これはバイナリログが保持されないことを意味します。

DB インスタンスでバイナリログを保持する時間数を指定するには、レプリケーションに十分な長さの binlog の保持期間を指定して、mysql.rds_set_configuration 関数を使用します。推奨される最小値は 24 hours です。

mysql=> call mysql.rds_set_configuration('binlog retention hours', 24);

パラメータグループで binlog 設定を構成する

パラメータグループは、RDS Console で MariaDB インスタンスをクリックし、Configurations タブに移動すると確認できます。

RDS でパラメータグループを確認する場所

パラメータグループのリンクをクリックすると、パラメータグループのページに移動します。右上に Edit ボタンがあります。

パラメータグループを編集

binlog_formatbinlog_row_metadatabinlog_row_image は次のように設定する必要があります。

  1. binlog_formatROW に設定します。
Binlog format を ROW に設定
  1. binlog_row_metadataFULL に設定します。
Binlog row metadata を FULL に設定
  1. binlog_row_imageFULL に設定します。
Binlog row image を FULL に設定

次に、右上の Save Changes をクリックします。変更を反映するには、インスタンスの再起動が必要になる場合があります。RDS インスタンスの Configurations タブで、パラメータグループのリンクの横に Pending reboot と表示されている場合は、インスタンスの再起動が必要である可能性が高いことを示しています。


GTID モードを有効にする

Global Transaction Identifiers (GTID) は、MySQL/MariaDB でコミットされた各トランザクションに割り当てられる一意の ID です。これにより、binlog レプリケーションが簡素化され、トラブルシューティングも容易になります。MariaDB ではデフォルトで GTID モードが有効になっているため、利用するためにユーザー側で追加の操作を行う必要はありません。

データベースユーザーを設定する

管理者ユーザーとして RDS MariaDB インスタンスに接続し、次のコマンドを実行します。

  1. ClickPipes 専用のユーザーを作成します。

    CREATE USER 'clickpipes_user'@'host' IDENTIFIED BY 'some-password';
  2. スキーマに対する権限を付与します。次の例では、mysql データベースに対する権限を示しています。レプリケーション対象とする各データベースおよびホストについて、これらのコマンドを繰り返してください。

    GRANT SELECT ON `mysql`.* TO 'clickpipes_user'@'host';
  3. ユーザーにレプリケーション権限を付与します。

    GRANT REPLICATION CLIENT ON *.* TO 'clickpipes_user'@'%';
    GRANT REPLICATION SLAVE ON *.* TO 'clickpipes_user'@'%';

IAM認証を使用する (任意)

Instead of a password, you can authenticate the ClickPipes user with an AWS IAM role. This lets ClickPipes connect to your Amazon RDS instance without storing database credentials.

Enable IAM authentication

  1. Log in to your AWS account and go to the RDS instance you want to configure.
  2. Click Modify.
  3. Scroll to the Database authentication section.
  4. Select Password and IAM database authentication.
  5. Click Continue.
  6. Review the changes and select Apply immediately.

Create the ClickPipes user

Create the ClickPipes user with IAM authentication enabled, then grant it the same schema and replication privileges shown above:

CREATE USER 'clickpipes_iam_user' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';

Obtain the ClickHouse service IAM role ARN

  1. Log in to your ClickHouse Cloud account.
  2. Select the ClickHouse service you want to connect.
  3. Select the Settings tab.
  4. Scroll to the Network security information section at the bottom of the page.
  5. Copy the service's Service role ID (IAM) value, shown below.
Service role ID (IAM) value in the Network security information section

This value is your {ClickHouse_IAM_ARN} — the role ClickPipes uses to access your RDS instance.

Obtain the resource ID

  1. Log in to your AWS account and go to the RDS instance you want to configure.
  2. Select the Configuration tab.
  3. Note the Resource ID value — it looks like db-xxxxxxxxxxxxxx. This is your {RDS_RESOURCE_ID}, which you reference in the permissions policy.

Create the IAM role

  1. Log in to your AWS account with an IAM user that has permission to create and manage IAM roles.
  2. Open the IAM console.
  3. Create a new IAM role with the following trust and permissions policies.

    Trust policy (replace {ClickHouse_IAM_ARN} with the IAM role ARN of your ClickHouse instance):

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "AWS": "{ClickHouse_IAM_ARN}"
          },
          "Action": [
            "sts:AssumeRole",
            "sts:TagSession"
          ]
        }
      ]
    }

    Permissions policy (replace {RDS_RESOURCE_ID} with the resource ID of your RDS instance, {RDS_REGION} with its region, and {AWS_ACCOUNT} with your AWS account ID):

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "rds-db:connect"
          ],
          "Resource": [
            "arn:aws:rds-db:{RDS_REGION}:{AWS_ACCOUNT}:dbuser:{RDS_RESOURCE_ID}/clickpipes_iam_user"
          ]
        }
      ]
    }
  4. Once the role is created, copy its ARN. This is your {RDS_ACCESS_IAM_ROLE_ARN}.

You can now use this IAM role to authenticate with your RDS instance from ClickPipes.

ネットワークアクセスを設定する

IP ベースのアクセス制御

RDS インスタンスへのトラフィックを制限する場合は、RDS のセキュリティグループの Inbound rules に、ドキュメントに記載されている固定 NAT IP を追加してください。

RDS でセキュリティグループはどこにありますか?
上記のセキュリティグループのインバウンドルールを編集

プライベートネットワーク経由で RDS インスタンスに接続するには、AWS PrivateLink を使用できます。接続を設定するには、ClickPipes 向け AWS PrivateLink セットアップガイドに従ってください。

Navigation