Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

RDS MySQL 源设置指南

本分步指南将介绍如何配置 Amazon RDS MySQL,使用 MySQL ClickPipe 将数据复制到 ClickHouse Cloud。有关 MySQL CDC 的常见问题,请参阅 MySQL 常见问题页面

启用二进制日志保留

二进制日志是一组日志文件,包含对 MySQL 服务器实例所做的数据修改信息,而复制需要这些二进制日志文件。要在 RDS MySQL 中配置二进制日志保留,您必须先启用二进制日志记录,并增加 binlog 保留时间间隔

通过自动备份启用二进制日志记录

自动备份功能决定是否为 MySQL 启用二进制日志记录。您可以在 RDS 控制台中依次进入 Modify > Additional configuration > Backup,然后选中 Enable automated backups 复选框 (如果尚未选中) ,为实例配置自动备份。

在 RDS 中启用自动备份

我们建议根据复制用例,将 Backup retention period 设置为合理且较长的值。

增加 binlog 保留时间间隔

默认情况下,Amazon RDS 会尽快清除 二进制日志 (即 延迟清除) 。我们建议将 binlog 保留时间间隔增加到至少 72 小时,以确保在发生故障时,复制所需的 二进制日志 文件仍然可用。要设置 二进制日志 的保留时间 (binlog retention hours) ,请使用 mysql.rds_set_configuration 存储过程:

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

如果未设置此配置,或将其间隔设得过低,可能会导致二进制日志出现断档,从而影响 ClickPipes 恢复复制。

配置 binlog 设置

在 RDS 控制台中点击你的 MySQL 实例,然后进入 Configuration 选项卡,即可找到参数组。

在 RDS 中查找参数组的位置

点击参数组链接,进入其详情页面。你应当会在右上角看到 Edit 按钮。

编辑参数组

将以下参数设置为:

  1. binlog_format 设为 ROW
将 binlog format 设为 ROW
  1. binlog_row_metadata 设为 FULL
将 binlog row metadata 设为 FULL
  1. binlog_row_image 设为 FULL
将 binlog row image 设为 FULL

然后,点击右上角的 Save Changes。你可能需要重启实例,更改才会生效——一个判断方法是:在 RDS 实例的 Configuration 选项卡中,如果参数组链接旁边显示 Pending reboot,就说明需要重启。

启用 GTID 模式

全局事务标识符 (GTID) 是 MySQL 中为每个已提交事务分配的唯一 ID。它们可简化 binlog 复制,并让故障排查更加容易。我们建议启用 GTID 模式,以便 MySQL ClickPipe 使用基于 GTID 的复制。

Amazon RDS for MySQL 5.7、8.0 和 8.4 版本支持基于 GTID 的复制。要为您的 Aurora MySQL 实例启用 GTID 模式,请按以下步骤操作:

  1. 在 RDS 控制台中,点击您的 MySQL 实例。
  2. 点击 Configuration 选项卡。
  3. 点击参数组链接。
  4. 点击右上角的 Edit 按钮。
  5. enforce_gtid_consistency 设置为 ON
  6. gtid-mode 设置为 ON
  7. 点击右上角的 Save Changes
  8. 重启您的实例,使更改生效。
GTID 已启用

配置数据库用户

以管理员身份连接到你的 RDS MySQL 实例,并执行以下命令:

  1. 为 ClickPipes 创建一个专用用户:

    CREATE USER 'clickpipes_user'@'host' IDENTIFIED BY 'some-password';
  2. 授予 schema 权限。以下示例展示了 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 的访问控制

要限制发往 Aurora MySQL 实例的流量,请将文档中列出的静态 NAT IP 地址添加到 RDS 安全组 (Security Group) 的 入站规则 中。

在 RDS MySQL 中在哪里可以找到安全组?
编辑上述安全组的入站规则

若要通过私有网络连接到您的 RDS 实例,可以使用 AWS PrivateLink。请按照 ClickPipes 的 AWS PrivateLink 设置指南 配置连接。

下一步

现在,您的亚马逊 RDS MySQL 实例已完成 binlog 复制配置,并已与 ClickHouse Cloud 建立安全连接,您可以创建第一个 MySQL ClickPipe。如需了解有关 MySQL CDC 的常见问题,请参见 MySQL 常见问题页面

Navigation