使用模板创建 Azure Redis 缓存Create an Azure Cache for Redis using a template

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

本主题将介绍如何创建 Azure 资源管理器模板,以便部署 Azure Redis 缓存。In this topic, you learn how to create an Azure Resource Manager 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.

有关创建模板的详细信息,请参阅创作 Azure Resource Manager 模板For more information about creating templates, see Authoring Azure Resource Manager Templates. 若要了解缓存资源类型的 JSON 语法和属性,请参阅 Microsoft.Cache 资源类型To learn about the JSON syntax and properties for cache resource types, see Microsoft.Cache resource types.

有关完整的模板,请参阅 Azure Redis 缓存模板For the complete template, see Azure Cache for Redis template.

Note

适用于新高级层的 Resource Manager 模板现已推出。Resource Manager templates for the new Premium tier are available.

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

要部署的内容What you will deploy

在此模板中,将部署 Azure Redis 缓存,以便使用现有存储帐户保存诊断数据。In this template, you will deploy an Azure Cache for Redis that uses an existing storage account for diagnostic data.

若要自动运行部署,请单击以下按钮:To run the deployment automatically, click the following button:

部署到 AzureDeploy to Azure

parametersParameters

使用 Azure Resource Manager,可以定义在部署模板时想要指定的值的参数。With Azure Resource Manager, you define parameters for values you want to specify when the template is deployed. 该模板具有一个名为 Parameters 的部分,其中包含所有参数值。The template includes a section called Parameters that contains all of the parameter values. 应该为随着要部署的项目或要部署到的环境而变化的值定义参数。You should define a parameter for those values that vary based on the project you are deploying or based on the environment you are deploying to. 不要为永远保持不变的值定义参数。Do not define parameters for values that always stay the same. 每个参数值可在模板中用来定义所部署的资源。Each parameter value is used in the template to define the resources that are deployed.

cacheSKUNamecacheSKUName

新 Azure Redis 缓存的定价层。The pricing tier of the new Azure Cache for Redis.

"cacheSKUName": {
  "type": "string",
  "allowedValues": [
    "Basic",
    "Standard"
  ],
  "defaultValue": "Basic",
  "metadata": {
    "description": "The pricing tier of the new Azure Cache for Redis."
  }
},

模板将定义此参数允许的值(Basic 或 Standard),如果未指定任何值,则分配默认值 (Basic)。The template defines the values that are permitted for this parameter (Basic or Standard), and assigns a default value (Basic) if no value is specified. Basic 提供单个节点,该节点具有多种大小,最大大小为 53 GB。Basic provides a single node with multiple sizes available up to 53 GB. Standard 提供“主/副本”两个节点,这些节点具有多种大小(最大 53 GB)并提供 99.9% SLA。Standard provides two-node Primary/Replica with multiple sizes available up to 53 GB and 99.9% SLA.

cacheSKUFamilycacheSKUFamily

SKU 的系列。The family for the sku.

"cacheSKUFamily": {
  "type": "string",
  "allowedValues": [
    "C"
  ],
  "defaultValue": "C",
  "metadata": {
    "description": "The family for the sku."
  }
},

cacheSKUCapacitycacheSKUCapacity

新 Azure Redis 缓存实例的大小。The size of the new Azure Cache for Redis instance.

"cacheSKUCapacity": {
  "type": "int",
  "allowedValues": [
    0,
    1,
    2,
    3,
    4,
    5,
    6
  ],
  "defaultValue": 0,
  "metadata": {
    "description": "The size of the new Azure Cache for Redis instance. "
  }
}

模板将定义此参数允许的值(0、1、2、3、4、5 或 6),如果未指定任何值,则分配默认值 (0)。The template defines the values that are permitted for this parameter (0, 1, 2, 3, 4, 5 or 6), and assigns a default value (0) if no value is specified. 这些数字对应于以下缓存大小:0 = 250 MB,1 = 1 GB,2 = 2.5 GB,3 = 6 GB,4 = 13 GB,5 = 26 GB,6 = 53 GBThose numbers correspond to following cache sizes: 0 = 250 MB, 1 = 1 GB, 2 = 2.5 GB, 3 = 6 GB, 4 = 13 GB, 5 = 26 GB, 6 = 53 GB

redisCacheLocationredisCacheLocation

Azure Redis 缓存的位置。The location of the Azure Cache for Redis. 为获得最佳性能,请使用要与缓存配合使用的应用所在的位置。For best performance, use the same location as the app to be used with the cache.

"redisCacheLocation": {
  "type": "string"
}

existingDiagnosticsStorageAccountNameexistingDiagnosticsStorageAccountName

要用于诊断的现有存储帐户的名称。The name of the existing storage account to use for diagnostics.

"existingDiagnosticsStorageAccountName": {
  "type": "string"
}

enableNonSslPortenableNonSslPort

一个布尔值,该值指示是否允许通过非 SSL 端口访问。A boolean value that indicates whether to allow access via non-SSL ports.

"enableNonSslPort": {
  "type": "bool"
}

diagnosticsStatusdiagnosticsStatus

一个值,该值指示是否启用诊断。A value that indicates whether diagnostics is enabled. 使用 ON 或 OFF。Use ON or OFF.

"diagnosticsStatus": {
  "type": "string",
  "defaultValue": "ON",
  "allowedValues": [
        "ON",
        "OFF"
    ]
}

要部署的资源Resources to deploy

用于 Redis 的 Azure 缓存Azure Cache for Redis

创建 Azure Redis 缓存。Creates the Azure Cache for Redis.

{
  "apiVersion": "2015-08-01",
  "name": "[parameters('redisCacheName')]",
  "type": "Microsoft.Cache/Redis",
  "location": "[parameters('redisCacheLocation')]",
  "properties": {
    "enableNonSslPort": "[parameters('enableNonSslPort')]",
    "sku": {
      "capacity": "[parameters('redisCacheCapacity')]",
      "family": "[parameters('redisCacheFamily')]",
      "name": "[parameters('redisCacheSKU')]"
    }
  },
  "resources": [
    {
      "apiVersion": "2017-05-01-preview",
      "type": "Microsoft.Cache/redis/providers/diagnosticsettings",
      "name": "[concat(parameters('redisCacheName'), '/Microsoft.Insights/service')]",
      "location": "[parameters('redisCacheLocation')]",
      "dependsOn": [
        "[concat('Microsoft.Cache/Redis/', parameters('redisCacheName'))]"
      ],
      "properties": {
        "status": "[parameters('diagnosticsStatus')]",
        "storageAccountName": "[parameters('existingDiagnosticsStorageAccountName')]"
      }
    }
  ]
}

运行部署的命令Commands to run deployment

要将资源部署到 Azure,必须登录到 Azure 帐户,并且必须使用 Azure 资源管理器模块。To deploy the resources to Azure, you must be signed in to your Azure account and you must use the Azure Resource Manager module. 若要了解配合使用 Azure 资源管理器和 Azure PowerShell 或 Azure CLI 的相关信息,请参阅:To learn about using Azure Resource Manager with either Azure PowerShell or Azure CLI, see:

以下示例假定帐户中已具有一个指定名称的资源组。The following examples assume you already have a resource group in your account with the specified name.

PowerShellPowerShell

New-AzResourceGroupDeployment -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-redis-cache/azuredeploy.json -ResourceGroupName ExampleDeployGroup -redisCacheName ExampleCache

Azure CLIAzure CLI

azure group deployment create --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-redis-cache/azuredeploy.json -g ExampleDeployGroup