快速入门:使用 ARM 模板创建 Azure Redis 缓存Quickstart: Create an Azure Cache for Redis using an ARM template

了解如何创建 Azure 资源管理器模板(ARM 模板),以便部署 Azure Cache for Redis。Learn how to create an Azure Resource Manager template (ARM template) that deploys an Azure Cache for Redis. 该缓存可以用于现有存储帐户以保存诊断数据。The cache can be used with an existing storage account to keep diagnostic data. 还将了解如何定义要部署的资源以及如何定义执行部署时指定的参数。You also learn how to define which resources are deployed and how to define parameters that are specified when the deployment is executed. 可将此模板用于自己的部署,或自定义此模板以满足要求。You can use this template for your own deployments, or customize it to meet your requirements. 目前,对订阅的同一区域中的所有缓存共享诊断设置。Currently, diagnostic settings are shared for all caches in the same region for a subscription. 更新区域中的一个缓存会影响该区域中的所有其他缓存。Updating one cache in the region affects all other caches in the region.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

“部署到 Azure”Deploy to Azure

先决条件Prerequisites

  • Azure 订阅:如果没有 Azure 订阅,可在开始前创建一个 试用帐户Azure subscription: If you don't have an Azure subscription, create a Trial before you begin.
  • 存储帐户:若要创建帐户,请参阅 创建 Azure 存储帐户A storage account: To create one, see Create an Azure Storage account. 存储帐户用于诊断数据。The storage account is used for diagnostic data.

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "redisCacheName": {
      "type": "string",
      "metadata": {
        "description": "Specify the name of the Azure Redis Cache to create."
      }
    },
    "location": {
      "defaultValue": "[resourceGroup().location]",
      "type": "string",
      "metadata": {
        "description": "Location of all resources"
      }
    },
    "redisCacheSKU": {
      "type": "string",
      "defaultValue": "Standard",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "metadata": {
        "description": "Specify the pricing tier of the new Azure Redis Cache."
      }
    },
    "redisCacheFamily": {
      "type": "string",
      "defaultValue": "C",
      "allowedValues": [
        "C",
        "P"
      ],
      "metadata": {
        "description": "Specify the family for the sku. C = Basic/Standard, P = Premium."
      }
    },
    "redisCacheCapacity": {
      "type": "int",
      "defaultValue": 1,
      "allowedValues": [
        0,
        1,
        2,
        3,
        4,
        5,
        6
      ],
      "metadata": {
        "description": "Specify the size of the new Azure Redis Cache instance. Valid values: for C (Basic/Standard) family (0, 1, 2, 3, 4, 5, 6), for P (Premium) family (1, 2, 3, 4)"
      }
    },
    "enableNonSslPort": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Specify a boolean value that indicates whether to allow access via non-SSL ports."
      }
    },
    "diagnosticsEnabled": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "Specify a boolean value that indicates whether diagnostics should be saved to the specified storage account."
      }
    },
    "existingDiagnosticsStorageAccountId": {
      "type": "string",
      "metadata": {
        "description": "Specify an existing storage account for diagnostics."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Cache/Redis",
      "apiVersion": "2020-06-01",
      "name": "[parameters('redisCacheName')]",
      "location": "[parameters('location')]",
      "properties": {
        "enableNonSslPort": "[parameters('enableNonSslPort')]",
        "minimumTlsVersion": "1.2",
        "sku": {
          "capacity": "[parameters('redisCacheCapacity')]",
          "family": "[parameters('redisCacheFamily')]",
          "name": "[parameters('redisCacheSKU')]"
        }
      },
      "resources": [
        {
          "type": "Microsoft.Cache/redis/providers/diagnosticsettings",
          "apiVersion": "2017-05-01-preview",
          "name": "[concat(parameters('redisCacheName'), '/Microsoft.Insights/', parameters('redisCacheName'))]",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Cache/Redis', parameters('redisCacheName'))]"
          ],
          "properties": {
            "storageAccountId": "[parameters('existingDiagnosticsStorageAccountId')]",
            "metrics": [
              {
                "timeGrain": "AllMetrics",
                "enabled": "[parameters('diagnosticsEnabled')]",
                "retentionPolicy": {
                  "days": 90,
                  "enabled": "[parameters('diagnosticsEnabled')]"
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

该模板中定义了以下资源:The following resources are defined in the template:

适用于新高级层的资源管理器模板也已推出。Resource Manager templates for the new Premium tier are also available.

若要检查最新模板,请参阅 Azure 快速入门模板并搜索 Azure Cache for Redis。To check for the latest templates, see Azure Quickstart Templates and search for Azure Cache for Redis.

部署模板Deploy the template

  1. 选择下图登录到 Azure 并打开模板。Select the following image to sign in to Azure and open the template.

    部署到 AzureDeploy to Azure

  2. 选择或输入以下值:Select or enter the following values:

    • 订阅:选择用于创建数据共享和其他资源的 Azure 订阅。Subscription: select an Azure subscription used to create the data share and the other resources.
    • 资源组:选择“新建”以创建新的资源组,或选择现有资源组。Resource group: select Create new to create a new resource group or select an existing resource group.
    • 位置:选择资源组的位置。Location: select a location for the resource group. 存储帐户和 Redis 缓存必须位于同一区域。The storage account and the Redis cache must be in the same region. 默认情况下,Redis 缓存使用的位置与资源组位置相同。By default the Redis cache uses the same location as the resource group. 因此指定存储帐户所在的同一位置。So, specify the same location as the storage account.
    • Redis 缓存名称:输入 Redis 缓存的名称。Redis Cache Name: enter a name for the Redis cache.
    • 现有的诊断存储帐户:输入存储帐户的资源 ID。Existing Diagnostics Storage Account: enter the resource ID of a storage account. 语法为 /subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>The syntax is /subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>.

    其余设置均采用默认值。Use the default value for the rest of the settings.

  3. 选择“我同意上述条款和条件”,然后选择“购买” 。select I agree to the terms and conditions stated above, and the select Purchase.

查看已部署的资源Review deployed resources

  1. 登录 Azure 门户Sign in to the Azure portal.
  2. 打开创建的 Redis 缓存。Open the Redis cache that you created.

清理资源Clean up resources

如果不再需要资源组,可以将其删除,这将删除资源组中的资源。When no longer needed, delete the resource group, which deletes the resources in the resource group.

$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
Remove-AzResourceGroup -Name $resourceGroupName
Write-Host "Press [ENTER] to continue..."

后续步骤Next steps

本教程介绍了如何创建 Azure 资源管理器模板,以便部署 Azure Cache for Redis。In this tutorial, you learnt how to create an Azure Resource Manager template that deploys an Azure Cache for Redis. 若要了解如何创建 Azure 资源管理器模板来部署包含 Azure Cache for Redis 的 Azure Web 应用,请参阅使用模板创建 Web 应用和 Azure Cache for RedisTo learn how to create an Azure Resource Manager template that deploys an Azure Web App with Azure Cache for Redis, see Create a Web App plus Azure Cache for Redis using a template.