Azure Cache for Redis をデプロイする Azure Resource Manager テンプレート (ARM テンプレート) を作成する方法について説明します。 キャッシュを既存のストレージ アカウントで使用することで、診断データを保持することができます。 さらに、デプロイ対象のリソースを定義する方法と、デプロイの実行時に指定されるパラメーターを定義する方法についても説明します。 このテンプレートは、独自のデプロイに使用することも、要件に合わせてカスタマイズすることもできます。 現時点では、診断設定は、サブスクリプションの同じリージョン内のすべてのキャッシュで共有されます。 領域内の 1 つのキャッシュを更新すると、領域内の他のすべてのキャッシュに反映されます。
Azure Resource Manager テンプレートは、プロジェクトのインフラストラクチャと構成を定義する JavaScript Object Notation (JSON) ファイルです。 このテンプレートでは、宣言型の構文が使用されています。 デプロイを作成するための一連のプログラミング コマンドを記述しなくても、意図したデプロイを記述できます。
環境が前提条件を満たしていて、ARM テンプレートの使用に慣れている場合は、 [Azure へのデプロイ] ボタンを選択します。 Azure portal でテンプレートが開きます。
[前提条件]
- Azure サブスクリプション:Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。
- ストレージ アカウント:これを作成するには、「Azure Storage アカウントの作成」を参照してください。 ストレージ アカウントは、診断データに使用されます。
Azure Cache for Redis (アジュール・キャッシュ・フォー・レディス)
テンプレートを確認する
このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.27.1.19265",
"templateHash": "10339364272812551477"
}
},
"parameters": {
"redisCacheName": {
"type": "string",
"defaultValue": "[format('redisCache-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specify the name of the Azure Redis Cache to create."
}
},
"___location": {
"type": "string",
"defaultValue": "[resourceGroup().___location]",
"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, 5)"
}
},
"builtInAccessPolicyName": {
"type": "string",
"defaultValue": "Data Reader",
"allowedValues": [
"Data Owner",
"Data Contributor",
"Data Reader"
],
"metadata": {
"description": "Specify name of Built-In access policy to use as assignment."
}
},
"builtInAccessPolicyAssignmentName": {
"type": "string",
"defaultValue": "[format('builtInAccessPolicyAssignment-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specify name of custom access policy to create."
}
},
"builtInAccessPolicyAssignmentObjectId": {
"type": "string",
"defaultValue": "[newGuid()]",
"metadata": {
"description": "Specify the valid objectId(usually it is a GUID) of the Microsoft Entra Service Principal or Managed Identity or User Principal to which the built-in access policy would be assigned."
}
},
"builtInAccessPolicyAssignmentObjectAlias": {
"type": "string",
"defaultValue": "[format('builtInAccessPolicyApplication-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specify human readable name of principal Id of the Microsoft Entra Application name or Managed Identity name used for built-in policy assignment."
}
},
"customAccessPolicyName": {
"type": "string",
"defaultValue": "[format('customAccessPolicy-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specify name of custom access policy to create."
}
},
"customAccessPolicyPermissions": {
"type": "string",
"defaultValue": "+@connection +get +hget allkeys",
"metadata": {
"description": "Specify the valid permissions for the customer access policy to create. For details refer to https://aka.ms/redis/ConfigureAccessPolicyPermissions"
}
},
"customAccessPolicyAssignmentName": {
"type": "string",
"defaultValue": "[format('customAccessPolicyAssignment-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specify name of custom access policy to create."
}
},
"customAccessPolicyAssignmentObjectId": {
"type": "string",
"defaultValue": "[newGuid()]",
"metadata": {
"description": "Specify the valid objectId(usually it is a GUID) of the Microsoft Entra Service Principal or Managed Identity or User Principal to which the custom access policy would be assigned."
}
},
"customAccessPolicyAssignmentObjectAlias": {
"type": "string",
"defaultValue": "[format('customAccessPolicyApplication-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specify human readable name of principal Id of the Microsoft Entra Application name or Managed Identity name used for custom policy assignment."
}
}
},
"resources": [
{
"type": "Microsoft.Cache/redis",
"apiVersion": "2023-08-01",
"name": "[parameters('redisCacheName')]",
"___location": "[parameters('___location')]",
"properties": {
"enableNonSslPort": false,
"minimumTlsVersion": "1.2",
"sku": {
"capacity": "[parameters('redisCacheCapacity')]",
"family": "[parameters('redisCacheFamily')]",
"name": "[parameters('redisCacheSKU')]"
},
"redisConfiguration": {
"aad-enabled": "true"
}
}
},
{
"type": "Microsoft.Cache/redis/accessPolicyAssignments",
"apiVersion": "2023-08-01",
"name": "[format('{0}/{1}', parameters('redisCacheName'), parameters('builtInAccessPolicyAssignmentName'))]",
"properties": {
"accessPolicyName": "[parameters('builtInAccessPolicyName')]",
"objectId": "[parameters('builtInAccessPolicyAssignmentObjectId')]",
"objectIdAlias": "[parameters('builtInAccessPolicyAssignmentObjectAlias')]"
},
"dependsOn": [
"[resourceId('Microsoft.Cache/redis', parameters('redisCacheName'))]"
]
},
{
"type": "Microsoft.Cache/redis/accessPolicies",
"apiVersion": "2023-08-01",
"name": "[format('{0}/{1}', parameters('redisCacheName'), parameters('customAccessPolicyName'))]",
"properties": {
"permissions": "[parameters('customAccessPolicyPermissions')]"
},
"dependsOn": [
"[resourceId('Microsoft.Cache/redis', parameters('redisCacheName'))]",
"[resourceId('Microsoft.Cache/redis/accessPolicyAssignments', parameters('redisCacheName'), parameters('builtInAccessPolicyAssignmentName'))]"
]
},
{
"type": "Microsoft.Cache/redis/accessPolicyAssignments",
"apiVersion": "2023-08-01",
"name": "[format('{0}/{1}', parameters('redisCacheName'), parameters('customAccessPolicyAssignmentName'))]",
"properties": {
"accessPolicyName": "[parameters('customAccessPolicyName')]",
"objectId": "[parameters('customAccessPolicyAssignmentObjectId')]",
"objectIdAlias": "[parameters('customAccessPolicyAssignmentObjectAlias')]"
},
"dependsOn": [
"[resourceId('Microsoft.Cache/redis', parameters('redisCacheName'))]",
"[resourceId('Microsoft.Cache/redis/accessPolicies', parameters('redisCacheName'), parameters('customAccessPolicyName'))]"
]
}
]
}
テンプレートで定義されているリソースは次のとおりです。
新しい Premium レベルの Resource Manager テンプレートも利用できます。
- クラスタリングを使用する Premium Azure Cache for Redis の作成
- データの永続化を使用する Premium Azure Cache for Redis の作成
- 仮想ネットワーク にデプロイされた Premium Redis Cache を作成する
最新のテンプレートを確認する場合は、「Azure クイックスタート テンプレート」で Azure Cache for Redis を検索してください。
テンプレートをデプロイする
Azure にサインインし、テンプレートを開くには次の画像を選択します。
次の値を選択または入力します。
- [サブスクリプション] : データ共有とその他のリソースの作成に使用する Azure サブスクリプションを選択します。
- [リソース グループ] : [新規作成] を選択して新しいリソース グループを作成するか、既存のリソース グループを選択します。
- 場所: リソース グループの場所を選択します。 ストレージ アカウントと Redis Cache は同じリージョンに存在する必要があります。 既定では、Redis Cache はリソース グループと同じ場所を使用します。 そのため、ストレージ アカウントと同じ場所を指定します。
- Redis Cache 名: Redis Cache の名前を入力します。
-
既存の診断ストレージ アカウント: ストレージ アカウントのリソース ID を入力します。 構文は
/subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>
です。
残りの設定については既定値を使用します。
[上記の使用条件に同意する] を選んで、[購入] を選びます。
Azure Managed Redis
テンプレートを確認する
cachename
と region
パラメーターを変更します。 それを azuredeploy.json
ファイルにコピーします。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"cachename": {
"defaultValue": "myAMRcache",
"type": "String"
},
"region": {
"defaultValue": "centraluseuap",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Cache/redisEnterprise",
"apiVersion": "2024-05-01-preview",
"name": "[parameters('cachename')]",
"___location": "[parameters('region')]",
"sku": {
"name": "Balanced_B5"
},
"identity": {
"type": "None"
},
"properties": {
"minimumTlsVersion": "1.2"
}
},
{
"type": "Microsoft.Cache/redisEnterprise/databases",
"apiVersion": "2024-05-01-preview",
"name": "[concat(parameters('cachename'), '/default')]",
"dependsOn": [
"[resourceId('Microsoft.Cache/redisEnterprise', parameters('cachename'))]"
],
"properties": {
"clientProtocol": "Encrypted",
"port": 10000,
"clusteringPolicy": "OSSCluster",
"evictionPolicy": "NoEviction",
"persistence": {
"aofEnabled": false,
"rdbEnabled": false
}
}
}
]
}
テンプレートをデプロイする
Azure Resource Manager テンプレートを azuredeploy.json としてローカル コンピューターに保存します。
Azure CLI または Azure PowerShell を使用してテンプレートをデプロイします。
az deployment group create --resource-group exampleRG --template-file main.bicep
デプロイされているリソースを確認する
- Azure portal にサインインします。
- 作成した Redis Cache を開きます。
リソースをクリーンアップする
不要になったら、リソース グループを削除します。これにより、リソース グループ内のリソースが削除されます。
$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
Remove-AzResourceGroup -Name $resourceGroupName
Write-Host "Press [ENTER] to continue..."
関連コンテンツ
このチュートリアルでは、Azure Cache for Redis をデプロイする Azure Resource Manager テンプレートを作成する方法について説明しました。 Azure Web アプリと Azure Cache for Redis をデプロイする Azure Resource Manager のテンプレートを作成する方法については、「テンプレートを使用して Web アプリと Azure Cache for Redis を作成する」を参照してください。