如何为高级 Azure Redis 缓存配置数据暂留How to configure data persistence for a Premium Azure Cache for Redis

本文介绍如何通过 Azure 门户在高级 Azure Cache for Redis 实例中配置暂留功能。In this article, you will learn how to configure persistence in a premium Azure Cache for Redis instance through the Azure portal. Azure Redis 缓存具有不同的缓存产品/服务,从而在缓存大小和功能(包括群集、暂留和虚拟网络支持等高级层功能)的选择上具有灵活性。Azure Cache for Redis has different cache offerings, which provide flexibility in the choice of cache size and features, including Premium tier features such as clustering, persistence, and virtual network support.

什么是数据暂留?What is data persistence?

Redis 暂留可让你保留存储在 Redis 中的数据。Redis persistence allows you to persist data stored in Redis. 还可以获取快照并备份数据,以便在出现硬件故障时进行加载。You can also take snapshots and back up the data, which you can load in case of a hardware failure. 这相对于基本级别或标准级别是一项巨大优势,因为基本级别或标准级别将所有数据存储在内存中,在出现故障的情况下,如果缓存节点停机,则可能导致数据丢失。This is a huge advantage over Basic or Standard tier where all the data is stored in memory and there can be potential data loss in case of a failure where Cache nodes are down.

Azure Redis 缓存使用以下模型提供 Redis 暂留:Azure Cache for Redis offers Redis persistence using the following models:

  • RDB 暂留 - 配置 RDB(Redis 数据库)暂留以后,Azure Redis 缓存按照可配置的备份频率,将 Azure Redis 缓存的快照以 Redis 二进制格式暂留在磁盘上。RDB persistence - When RDB (Redis database) persistence is configured, Azure Cache for Redis persists a snapshot of the Azure Cache for Redis in a Redis binary format to disk based on a configurable backup frequency. 如果发生了灾难性事件,导致主缓存和副缓存都无法使用,则会使用最新快照重新构造缓存。If a catastrophic event occurs that disables both the primary and replica cache, the cache is reconstructed using the most recent snapshot. 详细了解 RDB 暂留的优点缺点Learn more about the advantages and disadvantages of RDB persistence.
  • AOF 暂留 - 配置 AOF(仅追加文件)暂留后,Azure Redis 缓存将每个写入操作保存到日志,此日志每秒至少保存到 Microsoft Azure 存储帐户一次。AOF persistence - When AOF (Append only file) persistence is configured, Azure Cache for Redis saves every write operation to a log that is saved at least once per second into an Azure Storage account. 如果发生了灾难性事件,导致主缓存和副缓存都无法使用,则会使用存储的写入操作重新构造缓存。If a catastrophic event occurs that disables both the primary and replica cache, the cache is reconstructed using the stored write operations. 详细了解 AOF 暂留的优点缺点Learn more about the advantages and disadvantages of AOF persistence.

暂留将 Redis 数据写入你拥有和管理的 Azure 存储帐户。Persistence writes Redis data into an Azure Storage account that you own and manage. 可在缓存创建过程中通过“新建 Azure Redis 缓存”边栏选项卡进行配置,也可以在现有高级缓存的“资源”菜单上配置。You can configure from the New Azure Cache for Redis blade during cache creation and on the Resource menu for existing premium caches.

备注

保存数据时,Azure 存储会自动加密数据。Azure Storage automatically encrypts data when it is persisted. 可以使用自己的密钥进行加密。You can use your own keys for the encryption. 有关详细信息,请参阅 Azure Key Vault 中的客户托管密钥For more information, see Customer-managed keys with Azure Key Vault.

  1. 若要创建高级缓存,请登录到 Azure 门户并选择“创建资源”。To create a premium cache, sign in to the Azure portal and select Create a resource. 除了在 Azure 门户中创建缓存以外,也可以使用 Resource Manager 模板、PowerShell 或 Azure CLI 创建。In addition to creating caches in the Azure portal, you can also create them using Resource Manager templates, PowerShell, or Azure CLI. 有关创建 Azure Redis 缓存的详细信息,请参阅创建缓存For more information about creating an Azure Cache for Redis, see Create a cache.

    创建资源。

  2. 在“新建”页上选择“数据库”,然后选择“Azure Cache for Redis”。On the New page, select Databases and then select Azure Cache for Redis.

    选择 Azure Cache for Redis。

  3. 在“新建 Redis 缓存”页上配置新高级缓存的设置。On the New Redis Cache page, configure the settings for your new premium cache.

    设置Setting 建议的值Suggested value 说明Description
    DNS 名称DNS name 输入任何全局唯一的名称。Enter a globally unique name. 缓存名称必须是包含 1 到 63 个字符的字符串,只能包含数字、字母或连字符。The cache name must be a string between 1 and 63 characters that contain only numbers, letters, or hyphens. 该名称必须以数字或字母开头和结尾,且不能包含连续的连字符。The name must start and end with a number or letter, and can't contain consecutive hyphens. 缓存实例的主机名将是 <DNS name>.redis.cache.chinacloudapi.cnYour cache instance's host name will be <DNS name>.redis.cache.chinacloudapi.cn.
    订阅Subscription 单击下拉箭头,选择你的订阅。Drop-down and select your subscription. 要在其下创建此新的 Azure Cache for Redis 实例的订阅。The subscription under which to create this new Azure Cache for Redis instance.
    资源组Resource group 单击下拉箭头,选择一个资源组,或者选择“新建”并输入新的资源组名称。Drop-down and select a resource group, or select Create new and enter a new resource group name. 要在其中创建缓存和其他资源的资源组的名称。Name for the resource group in which to create your cache and other resources. 将所有应用资源放入一个资源组可以轻松地统一管理或删除这些资源。By putting all your app resources in one resource group, you can easily manage or delete them together.
    位置Location 单击下拉箭头,选择一个位置。Drop-down and select a location. 选择与要使用该缓存的其他服务靠近的区域Select a region near other services that will use your cache.
    缓存类型Cache type 单击下拉箭头,选择高级缓存来配置高级功能。Drop-down and select a premium cache to configure premium features. 有关详细信息,请参阅 Azure Cache for Redis 定价For details, see Azure Cache for Redis pricing. 定价层决定可用于缓存的大小、性能和功能。The pricing tier determines the size, performance, and features that are available for the cache. 有关详细信息,请参阅用于 Redis 的 Azure 缓存概述For more information, see Azure Cache for Redis Overview.
  4. 选择“网络”选项卡,或单击页面底部的“网络”按钮 。Select the Networking tab or click the Networking button at the bottom of the page.

  5. 在“网络”选项卡中,选择你的连接方法。In the Networking tab, select your connectivity method. 对于高级缓存实例,可以通过公共 IP 地址或服务终结点进行公开连接,也可以通过专用终结点进行私密连接。For premium cache instances, you can connect either publicly, via Public IP addresses or service endpoints, or privately, using a private endpoint.

  6. 选择页面底部的“下一步:高级”选项卡,或者单击页面底部的“下一步:高级”按钮。Select the Next: Advanced tab or click the Next: Advanced button on the bottom of the page.

  7. 在高级缓存实例的“高级”选项卡中,配置非 TLS 端口、群集和数据暂留的设置。In the Advanced tab for a premium cache instance, configure the settings for non-TLS port, clustering, and data persistence. 对于数据暂留,可以选择 RDB 或 AOF 暂留。For data persistence, you can choose either RDB or AOF persistence.

  8. 若要启用 RDB 暂留,请单击“RDB”并配置设置。To enable RDB persistence, click RDB and configure the settings.

    设置Setting 建议的值Suggested value 说明Description
    备份频率Backup Frequency 单击下拉箭头,选择一个备份间隔,选项包括“15 分钟”、“30 分钟”、“60 分钟”、“6 小时”、“12 小时”和“24 小时” 。Drop-down and select a backup interval, choices include 15 Minutes, 30 minutes, 60 minutes, 6 hours, 12 hours, and 24 hours. 在上一个备份操作成功完成以后,此时间间隔就会开始倒计时,同时会启动新的备份。This interval starts counting down after the previous backup operation successfully completes and when it elapses a new backup is initiated.
    存储帐户Storage Account 单击下拉箭头,选择你的存储帐户。Drop-down and select your storage account. 必须选择与缓存位于同一区域和订阅的存储帐户。建议选择“高级存储”帐户,因为高级存储的吞吐量较高。You must choose a storage account in the same region and subscription as the cache, and a Premium Storage account is recommended because premium storage has higher throughput.
    存储密钥Storage Key 单击下拉箭头,选择要使用的“主密钥”或“辅助密钥”。Drop-down and choose either the Primary key or Secondary key to use. 如果重新生成了暂留帐户的存储密钥,必须从“存储密钥”下拉列表中重新配置所需密钥。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.

    备份频率间隔的时间过后,将启动第一次备份。The first backup is initiated once the backup frequency interval elapses.

  9. 若要启用 AOF 暂留,请单击“AOF”并配置设置。To enable AOF persistence, click AOF and configure the settings.

    设置Setting 建议的值Suggested value 说明Description
    第一个存储帐户First Storage Account 单击下拉箭头,选择你的存储帐户。Drop-down and select your storage account. 此存储帐户必须与缓存位于相同区域和订阅中。建议选择“高级存储”帐户,因为高级存储的吞吐量较高。This storage account must be in the same region and subscription as the cache, and a Premium Storage account is recommended because premium storage has higher throughput.
    第一个存储密钥First Storage Key 单击下拉箭头,选择要使用的“主密钥”或“辅助密钥”。Drop-down and choose either the Primary key or Secondary key to use. 如果重新生成了暂留帐户的存储密钥,必须从“存储密钥”下拉列表中重新配置所需密钥。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.
    第二个存储帐户Second Storage Account (可选)单击下拉箭头,选择你的辅助存储帐户。(Optional) Drop-down and select your secondary storage account. 可以选择配置其他存储帐户。You can optionally configure an additional storage account. 如果配置第二个存储帐户,写入副本缓存操作会写入到第二个存储帐户。If a second storage account is configured, the writes to the replica cache are written to this second storage account.
    第二个存储密钥Second Storage Key (可选)单击下拉箭头,选择要使用的“主密钥”或“辅助密钥”。(Optional) Drop-down and choose either the Primary key or Secondary key to use. 如果重新生成了暂留帐户的存储密钥,必须从“存储密钥”下拉列表中重新配置所需密钥。If the storage key for your persistence account is regenerated, you must reconfigure the desired key from the Storage Key drop-down.

    启用 AOF 暂留后,写入缓存操作会保存到指定的存储帐户(如果配置了第二个存储帐户,还可指定该帐户)。When AOF persistence is enabled, write operations to the cache are saved to the designated storage account (or accounts if you have configured a second storage account). 如果灾难性故障导致主缓存和副本缓存均无法使用,则使用存储的 AOF 日志重新生成缓存。In the event of a catastrophic failure that takes down both the primary and replica cache, the stored AOF log is used to rebuild the cache.

  10. 选择页面底部的“下一步:标记”选项卡,或者单击“下一步:标记”按钮。Select the Next: Tags tab or click the Next: Tags button at the bottom of the page.

  11. 或者,在“标记”选项卡中,如果希望对资源分类,请输入名称或值。Optionally, in the Tags tab, enter the name and value if you wish to categorize the resource.

  12. 选择“查看 + 创建” 。Select Review + create. 随后你会转到“查看 + 创建”选项卡,Azure 将在此处验证配置。You're taken to the Review + create tab where Azure validates your configuration.

  13. 显示绿色的“已通过验证”消息后,选择“创建”。After the green Validation passed message appears, select Create.

创建缓存需要花费片刻时间。It takes a while for the cache to create. 可以在 Azure Cache for Redis 的“概述”页上监视进度。 You can monitor progress on the Azure Cache for Redis Overview page. 如果“状态”显示为“正在运行”,则表示该缓存可供使用。 When Status shows as Running, the cache is ready to use.

保留常见问题Persistence FAQ

以下列表包含对 Azure Redis 缓存暂留相关常见问题的解答。The following list contains answers to commonly asked questions about Azure Cache for Redis persistence.

RDB 暂留RDB persistence

AOF 暂留AOF persistence

能否在此前已创建的缓存的基础上启用保留?Can I enable persistence on a previously created cache?

是的,可以在创建缓存时或者在现有高级缓存上配置 Redis 持久性。Yes, Redis persistence can be configured both at cache creation and on existing premium caches.

是否可以同时启用 AOF 暂留和 RDB 暂留?Can I enable AOF and RDB persistence at the same time?

不可以,只能分别启用 RDB 或 AOF,不能同时启用二者。No, you can enable only RDB or AOF, but not both at the same time.

应该选择哪个暂留模型?Which persistence model should I choose?

AOF 暂留将每个写入保存到日志,与 RDB 暂留相比,这对吞吐量有一些影响,因为 RDB 暂留基于配置的备份间隔保存备份,对性能产生的影响非常小。AOF persistence saves every write to a log, which has some impact on throughput, compared with RDB persistence which saves backups based on the configured backup interval, with minimal impact on performance. 如果主要目标是最大程度减少数据损失,并且可应付缓存吞吐量下降,请选择 AOF 暂留。Choose AOF persistence if your primary goal is to minimize data loss, and you can handle a decrease in throughput for your cache. 如果希望在缓存上保持最优吞吐量,但仍希望使用一种数据恢复机制,请选择 RDB 暂留。Choose RDB persistence if you wish to maintain optimal throughput on your cache, but still want a mechanism for data recovery.

有关使用 AOF 暂留时的性能详细信息,请参阅 AOF 暂留是否影响缓存吞吐量、延迟或性能?For more information on performance when using AOF persistence, see Does AOF persistence affect throughout, latency, or performance of my cache?

如果我缩放到不同大小并还原了缩放操作之前生成的备份,会发生什么情况?What happens if I have scaled to a different size and a backup is restored that was made before the scaling operation?

对于 RDB 暂留和 AOF 暂留:For both RDB and AOF persistence:

  • 如果缩放到更大的大小,则没有任何影响。If you have scaled to a larger size, there is no impact.
  • 如果缩放到更小的大小,并且自定义数据库设置大于新大小的数据库限制,则不会还原这些数据库中的数据。If you have scaled to a smaller size, and you have a custom databases setting that is greater than the databases limit for your new size, data in those databases isn't restored. 有关详细信息,请参阅在缩放过程中,自定义数据库设置是否会受影响?For more information, see Is my custom databases setting affected during scaling?
  • 如果缩放到更小的大小,并且更小的大小空间不足,无法容纳上次备份的所有数据,则在还原过程中,通常会使用 allkeys-lru 逐出策略逐出密钥。If you have scaled to a smaller size, and there isn't enough room in the smaller size to hold all of the data from the last backup, keys will be evicted during the restore process, typically using the allkeys-lru eviction policy.

能否在两个不同的缓存中使用同一存储帐户进行保留?Can I use the same storage account for persistence across two different caches?

可以,你可以使用同一存储帐户在两个不同的缓存中进行保留Yes, you can use the same storage account for persistence across two different caches

创建缓存后是否可更改 RDB 备份频率?Can I change the RDB backup frequency after I create the cache?

可以,可在“数据暂留”边栏选项卡上更改 RDB 暂留的备份频率。Yes, you can change the backup frequency for RDB persistence on the Data persistence blade. 有关说明,请参阅“配置 Redis 暂留”。For instructions, see Configure Redis persistence.

为何我的 RDB 备份频率为 60 分钟,而两次备份的间隔却超过 60 分钟?Why if I have an RDB backup frequency of 60 minutes there is more than 60 minutes between backups?

RDB 暂留备份频率间隔在先前备份过程已成功完成后才会开始。The RDB persistence backup frequency interval does not start until the previous backup process has completed successfully. 如果备份频率为 60 分钟,而备份过程需要 15 分钟才能成功完成,则在上一次备份开始以后,要再过 75 分钟才会开始下一次备份。If the backup frequency is 60 minutes and it takes a backup process 15 minutes to successfully complete, the next backup won't start until 75 minutes after the start time of the previous backup.

进行新备份以后,旧的 RDB 备份会发生什么情况?What happens to the old RDB backups when a new backup is made?

除最新备份外的所有 RDB 暂留备份会被自动删除。All RDB persistence backups except for the most recent one are automatically deleted. 这种删除可能不会即刻发生,但旧备份是不会无限期保留下去的。This deletion may not happen immediately but older backups are not persisted indefinitely.

是否应使用第二个存储帐户?When should I use a second storage account?

如果认为缓存上的设置操作高于预期,则应将第二个存储帐户用于 AOF 暂留。You should use a second storage account for AOF persistence when you believe you have higher than expected set operations on the cache. 设置辅助存储帐户有助于确保缓存不会达到存储带宽限制。Setting up the secondary storage account helps ensure your cache doesn't reach storage bandwidth limits.

AOF 暂留是否影响缓存吞吐量、延迟或性能?Does AOF persistence affect throughout, latency, or performance of my cache?

缓存低于最大负载(CPU 和服务器负载皆低于 90%)时,AOF 暂留对吞吐量产生约 15% - 20% 的影响。AOF persistence affects throughput by about 15% - 20% when the cache is below maximum load (CPU and Server Load both under 90%). 缓存处于这些限制以内时不存在延迟问题。There should not be latency issues when the cache is within these limits. 但是,启用 AOF 时缓存将更快达到这些限制。However, the cache will reach these limits sooner with AOF enabled.

如何删除第二个存储帐户?How can I remove the second storage account?

可通过将第二个存储帐户设置为与第一个存储帐户相同的方式来删除 AOF 暂留辅助存储帐户。You can remove the AOF persistence secondary storage account by setting the second storage account to be the same as the first storage account. 对于现有缓存,可从缓存的“资源菜单”访问“数据暂留”边栏选项卡。For existing caches, the Data persistence blade is accessed from the Resource menu for your cache. 若要禁用 AOF 暂留,请单击“禁用”。To disable AOF persistence, click Disabled.

什么是重写?重写对缓存有何影响?What is a rewrite and how does it affect my cache?

在 AOF 文件足够大时,重写会自动处于缓存上的队列中。When the AOF file becomes large enough, a rewrite is automatically queued on the cache. 重写使用创建当前数据集所需的最小操作集来重设 AOF 文件大小。The rewrite resizes the AOF file with the minimal set of operations needed to create the current data set. 重写期间会很快达到性能限制,尤其是在处理大型数据集时。During rewrites, expect to reach performance limits sooner especially when dealing with large datasets. AOF 文件越大,重写发生频率越低,但是如果发生则会需要较长时间。Rewrites occur less often as the AOF file becomes larger, but will take a significant amount of time when it happens.

缩放启用 AOF 的缓存时会出现什么情况?What should I expect when scaling a cache with AOF enabled?

如果缩放时的 AOF 文件非常大,则缩放操作所花时间应长于预期,因为在缩放结束后才重载文件。If the AOF file at the time of scaling is significantly large, then expect the scale operation to take longer than expected since it will be reloading the file after scaling has finished.

有关缩放的详细信息,请参阅如果我缩放到不同大小并还原了缩放操作之前生成的备份,会发生什么情况?For more information on scaling, see What happens if I have scaled to a different size and a backup is restored that was made before the scaling operation?

AOF 数据如何在存储中进行整理?How is my AOF data organized in storage?

AOF 文件中存储的数据在每个节点分为多个页 Blob,以便提升将数据保存至存储的性能。Data stored in AOF files is divided into multiple page blobs per node to increase performance of saving the data to storage. 下表介绍每个定价层使用的页 Blob 数量:The following table displays how many page blobs are used for each pricing tier:

高级层Premium tier BlobBlobs
P1P1 4 个/分片4 per shard
P2P2 8 个/分片8 per shard
P3P3 16 个/分片16 per shard
P4P4 20 个/分片20 per shard

启用群集时,缓存中的每个分片具有自己的页 Blob 集,如上表所示。When clustering is enabled, each shard in the cache has its own set of page blobs, as indicated in the previous table. 例如,具有 3 个分片的 P2 缓存在 24 个页 Blob 之间(每个分片 8 个页 Blob,共 3 个分片)分配其 AOF 文件。For example, a P2 cache with three shards distributes its AOF file across 24 page blobs (8 blobs per shard, with 3 shards).

重写后,存储中存在 2 个 AOF 文件集。After a rewrite, two sets of AOF files exist in storage. 重写在后台进行,并附加到第一个文件集,而重写期间发送至缓存的设置操作会附加到第二个文件集。Rewrites occur in the background and append to the first set of files, while set operations that are sent to the cache during the rewrite append to the second set. 重写期间会暂时存储备份以防发生故障,但是备份在重写结束后会立即删除。A backup is temporarily stored during rewrites in case of failure, but is promptly deleted after a rewrite finishes.

后续步骤Next steps

了解有关 Azure Cache for Redis 功能的详细信息。Learn more about Azure Cache for Redis features.