如何使用 PowerShell 在 Azure Database for MariaDB 中创建和管理只读副本How to create and manage read replicas in Azure Database for MariaDB using PowerShell

本文介绍如何使用 PowerShell 在 Azure Database for MariaDB 服务中创建和管理只读副本。In this article, you learn how to create and manage read replicas in the Azure Database for MariaDB service using PowerShell. 若要详细了解只读副本,请参阅概述To learn more about read replicas, see the overview.

Azure PowerShellAzure PowerShell

可以使用 PowerShell 创建和管理只读副本。You can create and manage read replicas using PowerShell.

先决条件Prerequisites

若要完成本操作指南,需要:To complete this how-to guide, you need:

重要

尽管 Az.MariaDb PowerShell 模块为预览版,但必须使用以下命令从 Az PowerShell 模块单独安装它:Install-Module -Name Az.MariaDb -AllowPrereleaseWhile the Az.MariaDb PowerShell module is in preview, you must install it separately from the Az PowerShell module using the following command: Install-Module -Name Az.MariaDb -AllowPrerelease.

使用 Connect-AzAccount cmdlet 连接到 Azure 帐户。Connect to your Azure account using the Connect-AzAccount cmdlet.

重要

只读副本功能仅适用于“常规用途”或“内存优化”定价层中的 Azure Database for MariaDB 服务器。The read replica feature is only available for Azure Database for MariaDB servers in the General Purpose or Memory Optimized pricing tiers. 请确保源服务器位于其中一个定价层中。Ensure the source server is in one of these pricing tiers.

创建只读副本Create a read replica

重要

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

可以使用以下命令创建只读副本服务器:A read replica server can be created using the following command:

Get-AzMariaDbServer -Name mydemoserver -ResourceGroupName myresourcegroup |
  New-AzMariaDbServerReplica -Name mydemoreplicaserver -ResourceGroupName myresourcegroup

New-AzMariaDbServerReplica 命令需要以下参数:The New-AzMariaDbServerReplica command requires the following parameters:

设置Setting 示例值Example value 说明Description
ResourceGroupNameResourceGroupName myresourcegroupmyresourcegroup 在其中创建副本服务器的资源组。The resource group where the replica server is created.
名称Name mydemoreplicaservermydemoreplicaserver 所创建的新副本服务器的名称。The name of the new replica server that is created.

若要创建跨区域只读副本,请使用 Location 参数。To create a cross region read replica, use the Location parameter. 以下示例在“中国东部 2”区域中创建一个副本。The following example creates a replica in the China East 2 region.

Get-AzMariaDbServer -Name mrdemoserver -ResourceGroupName myresourcegroup |
  New-AzMariaDServerReplica -Name mydemoreplicaserver -ResourceGroupName myresourcegroup -Location chinaeast2

若要详细了解可以在哪些区域中创建副本,请访问只读副本概念文章To learn more about which regions you can create a replica in, visit the read replica concepts article.

默认情况下,除非指定了 Sku 参数,否则将使用与源服务器相同的服务器配置来创建只读副本。By default, read replicas are created with the same server configuration as the source unless the Sku parameter is specified.

备注

建议副本服务器的配置应始终采用与源服务器相同或更大的值,以确保副本能够与主服务器保持一致。It is recommended that the replica server's configuration should be kept at equal or greater values than the source to ensure the replica is able to keep up with the master.

列出源服务器的副本List replicas for a source server

若要查看给定源服务器的所有副本,请运行以下命令:To view all replicas for a given source server, run the following command:

Get-AzMariaDReplica -ResourceGroupName myresourcegroup -ServerName mydemoserver

Get-AzMariaDReplica 命令需要以下参数:The Get-AzMariaDReplica command requires the following parameters:

设置Setting 示例值Example value 说明Description
ResourceGroupNameResourceGroupName myresourcegroupmyresourcegroup 要在其中创建副本服务器的资源组。The resource group where the replica server will be created to.
ServerNameServerName mydemoservermydemoserver 源服务器的名称或 ID。The name or ID of the source server.

删除副本服务器Delete a replica server

可以通过运行 Remove-AzMariaDbServer cmdlet 来删除只读副本服务器。Deleting a read replica server can be done by running the Remove-AzMariaDbServer cmdlet.

Remove-AzMariaDbServer -Name mydemoreplicaserver -ResourceGroupName myresourcegroup

删除源服务器Delete a source server

重要

删除源服务器会停止复制到所有副本服务器,并删除源服务器本身。Deleting a source server stops replication to all replica servers and deletes the source server itself. 副本服务器成为现在支持读取和写入的独立服务器。Replica servers become standalone servers that now support both read and writes.

若要删除源服务器,可以运行 Remove-AzMariaDbServer cmdlet。To delete a source server, you can run the Remove-AzMariaDbServer cmdlet.

Remove-AzMariaDbServer -Name mydemoserver -ResourceGroupName myresourcegroup

后续步骤Next steps