Azure Database for MariaDB 中的只读副本Read replicas in Azure Database for MariaDB

使用只读副本功能可将数据从 Azure Database for MariaDB 服务器复制到只读服务器。The read replica feature allows you to replicate data from an Azure Database for MariaDB server to a read-only server. 可将主服务器中的数据复制到最多 5 个副本。You can replicate from the master server to up to five replicas. 使用全局事务 ID (GTID) 通过 MariaDB 引擎的基于二进制日志 (binlog) 文件位置的复制技术以异步方式更新副本。Replicas are updated asynchronously using the MariaDB engine's binary log (binlog) file position-based replication technology with global transaction ID (GTID). 要详细了解 binlog 复制,请参阅 binlog 复制概述To learn more about binlog replication, see the binlog replication overview.

副本是新的服务器,可以像管理普通的 Azure Database for MariaDB 服务器一样对其进行管理。Replicas are new servers that you manage similar to regular Azure Database for MariaDB servers. 每个只读副本按照预配计算资源的 vCore 数量以及每月 GB 存储量计费。For each read replica, you're billed for the provisioned compute in vCores and storage in GB/ month.

若要详细了解 GTID 复制,请参阅 MariaDB 复制文档To learn more about GTID replication, see the MariaDB replication documentation.

何时使用只读副本When to use a read replica

只读副本功能可帮助改善读取密集型工作负荷的性能与规模。The read replica feature helps to improve the performance and scale of read-intensive workloads. 读取工作负载可以与副本服务器隔离,而写入工作负载可以定向到主服务器。Read workloads can be isolated to the replicas, while write workloads can be directed to the master.

常见方案是让 BI 和分析工作负载将只读副本用作报告的数据源。A common scenario is to have BI and analytical workloads use the read replica as the data source for reporting.

由于副本是只读的,它们不能直接缓解主服务器上的写入容量负担。Because replicas are read-only, they don't directly reduce write-capacity burdens on the master. 此功能并非面向写入密集型工作负荷。This feature isn't targeted at write-intensive workloads.

只读副本功能使用异步复制技术。The read replica feature uses asynchronous replication. 该功能不适用于同步复制方案。The feature isn't meant for synchronous replication scenarios. 主服务器与副本之间存在明显的延迟。There will be a measurable delay between the master and the replica. 副本上的数据最终将与主服务器上的数据保持一致。The data on the replica eventually becomes consistent with the data on the master. 对于能够适应这种延迟的工作负荷,可以使用此功能。Use this feature for workloads that can accommodate this delay.

跨区域复制Cross-region replication

可以在与主服务器不同的区域中创建只读副本。You can create a read replica in a different region from your master server. 跨区域复制对于灾难恢复规划或使数据更接近用户等方案非常有用。Cross-region replication can be helpful for scenarios like disaster recovery planning or bringing data closer to your users.

Note

跨区域复制处于预览状态。Cross region replication is in preview.

可以在任何 Azure Database for MariaDB 区域中设置主服务器。You can have a master server in any Azure Database for MariaDB region. 主服务器可以在其配对区域中有一个副本。A master server can have a replica in its paired region.

配对区域Paired regions

如果你使用跨区域副本进行灾难恢复规划,建议你在配对区域而不是其他某个区域中创建副本。If you are using cross-region replicas for disaster recovery planning, we recommend you create the replica in the paired region instead of one of the other regions. 配对区域可避免同时更新,并优先考虑物理隔离和数据驻留。Paired regions avoid simultaneous updates and prioritize physical isolation and data residency.

创建副本Create a replica

如果主服务器没有现有的副本服务器,主服务器会先重启,以自行准备复制。If a master server has no existing replica servers, the master will first restart to prepare itself for replication.

启动“创建副本”工作流时,将创建空白的 Azure Database for MariaDB 服务器。When you start the create replica workflow, a blank Azure Database for MariaDB server is created. 新服务器中填充了主服务器上的数据。The new server is filled with the data that was on the master server. 创建时间取决于主服务器上的数据量,以及自上次每周完整备份以来所经历的时间。The creation time depends on the amount of data on the master and the time since the last weekly full backup. 具体所需时间从几分钟到几小时不等。The time can range from a few minutes to several hours.

Note

如果尚未在服务器上设置存储警报,我们建议进行设置。If you don't have a storage alert set up on your servers, we recommend that you do so. 当服务器即将达到其存储限制(这会影响复制)时,警报可以向你发出通知。The alert informs you when a server is approaching its storage limit, which will affect the replication.

了解如何在 Azure 门户中创建只读副本Learn how to create a read replica in the Azure portal.

连接到副本Connect to a replica

创建时,副本会继承主服务器的防火墙规则或 VNet 服务终结点。At creation, a replica inherits the firewall rules or VNet service endpoint of the master server. 之后,这些规则将独立于主服务器。Afterwards, these rules are independent from the the master server.

副本从主服务器继承其管理员帐户。The replica inherits the admin account from the master server. 主服务器上的所有用户帐户将复制到只读副本。All user accounts on the master server are replicated to the read replicas. 只能使用主服务器上可用的用户帐户连接到只读副本。You can only connect to a read replica by using the user accounts that are available on the master server.

可以使用主机名和有效的用户帐户连接到副本,就像在常规的 Azure Database for MariaDB 服务器上连接一样。You can connect to the replica by using its hostname and a valid user account, as you would on a regular Azure Database for MariaDB server. 对于名称为 myreplica、管理员用户名为 myadmin 的服务器,可以使用 mysql CLI 连接到副本:For a server named myreplica with the admin username myadmin, you can connect to the replica by using the mysql CLI:

mysql -h myreplica.mariadb.database.chinacloudapi.cn -u myadmin@myreplica -p

在提示符下,输入用户帐户的密码。At the prompt, enter the password for the user account.

监视复制Monitor replication

Azure Database for MariaDB 在 Azure Monitor 中提供“复制滞后时间(秒)”指标。 Azure Database for MariaDB provides the Replication lag in seconds metric in Azure Monitor. 此指标仅适用于副本。This metric is available for replicas only.

此指标是使用 MariaDB 的 SHOW SLAVE STATUS 命令中提供的 seconds_behind_master 指标计算得出的。This metric is calculated using the seconds_behind_master metric available in MariaDB's SHOW SLAVE STATUS command.

请设置警报,以便在复制滞后时间达到工作负荷不可接受的值时收到通知。Set an alert to inform you when the replication lag reaches a value that isn’t acceptable for your workload.

停止复制Stop replication

可以停止主服务器与副本之间的复制。You can stop replication between a master and a replica. 在主服务器与只读副本之间停止复制后,副本将成为独立服务器。After replication is stopped between a master server and a read replica, the replica becomes a standalone server. 独立服务器中的数据是启动“停止复制”命令时副本上可用的数据。The data in the standalone server is the data that was available on the replica at the time the stop replication command was started. 独立服务器与主服务器不同步。The standalone server doesn't catch up with the master server.

选择停止复制到副本时,副本会丢失指向其以前的主服务器和其他副本的所有链接。When you choose to stop replication to a replica, it loses all links to its previous master and other replicas. 在主服务器与其副本之间无法自动进行故障转移。There is no automated failover between a master and its replica.

Important

独立服务器不能再次成为副本。The standalone server can't be made into a replica again. 在只读副本上停止复制之前,请确保副本包含所需的全部数据。Before you stop replication on a read replica, ensure the replica has all the data that you require.

了解如何停止复制到副本Learn how to stop replication to a replica.

注意事项和限制Considerations and limitations

定价层Pricing tiers

只读副本当前仅适用于“常规用途”和“内存优化”的定价层。Read replicas are currently only available in the General Purpose and Memory Optimized pricing tiers.

主服务器重启Master server restart

如果为没有现有副本的主服务器创建副本,主服务器将首先重启以便为复制准备自身。When you create a replica for a master that has no existing replicas, the master will first restart to prepare itself for replication. 请考虑这一点并在非高峰期执行这些操作。Take this into consideration and perform these operations during an off-peak period.

新副本New replicas

只读副本将创建为新的 Azure Database for MariaDB 服务器。A read replica is created as a new Azure Database for MariaDB server. 无法将现有的服务器设为副本。An existing server can't be made into a replica. 无法创建另一个只读副本的副本。You can't create a replica of another read replica.

副本配置Replica configuration

副本是使用与主服务器相同的服务器配置创建的。A replica is created by using the same server configuration as the master. 创建副本后,可以独立于主服务器更改多项设置:计算代系、vCore 数、存储、备份保留期和 MariaDB 引擎版本。After a replica is created, several settings can be changed independently from the master server: compute generation, vCores, storage, backup retention period, and MariaDB engine version. 定价层也可以独立更改,但“基本”层除外。The pricing tier can also be changed independently, except to or from the Basic tier.

Important

将主服务器的配置更新为新值之前,请将副本配置更新为与这些新值相等或更大的值。Before a master server configuration is updated to new values, update the replica configuration to equal or greater values. 此操作可确保副本与主服务器发生的任何更改保持同步。This action ensures the replica can keep up with any changes made to the master.

创建副本服务器时,防火墙规则、虚拟网络规则和参数设置会从主服务器继承到副本服务器。Firewall rules, virtual network rules, and parameter settings are inherited from the master server to the replica when the replica is created. 之后,副本服务器的规则将独立。Afterwards, the replica's rules are independent.

停止的副本Stopped replicas

如果停止主服务器与只读副本之间的复制,已停止的副本将成为可接受读取和写入的独立服务器。If you stop replication between a master server and a read replica, the stopped replica becomes a standalone server that accepts both reads and writes. 独立服务器不能再次成为副本。The standalone server can't be made into a replica again.

删除的主服务器和独立服务器Deleted master and standalone servers

删除主服务器后,将对所有只读副本停止复制。When a master server is deleted, replication is stopped to all read replicas. 这些副本服务器将成为独立服务器。These replicas become standalone servers. 将删除主服务器本身。The master server itself is deleted.

用户帐户User accounts

主服务器上的用户将复制到只读副本。Users on the master server are replicated to the read replicas. 只能使用主服务器上可用的用户帐户连接到只读副本。You can only connect to a read replica using the user accounts available on the master server.

服务器参数Server parameters

为了防止数据不同步并避免潜在的数据丢失或损坏,使用读取副本时,会锁定某些服务器参数以防止其更新。To prevent data from becoming out of sync and to avoid potential data loss or corruption, some server parameters are locked from being updated when using read replicas.

将在主服务器和副本服务器上锁定以下的服务器参数:The following server parameters are locked on both the master and replica servers:

将在副本服务器上锁定 event_scheduler 参数。The event_scheduler parameter is locked on the replica servers.

其他Other

  • 不支持创建副本服务器的副本。Creating a replica of a replica is not supported.
  • 内存中的表可能会导致副本服务器变得不同步。这是 MariaDB 复制技术的限制。In-memory tables may cause replicas to become out of sync. This is a limitation of the MariaDB replication technology.
  • 确保主服务器表具有主键。Ensure the master server tables have primary keys. 缺少主键可能会导致主服务器与副本服务器之间的复制延迟。Lack of primary keys may result in replication latency between the master and replicas.

后续步骤Next steps