#step 1: create credential
$MyAzureName = "youraccou@youraccount.partner.onmschina.cn";
$myPasswd='password '
$MyAzurePassword = ConvertTo-SecureString $myPasswd -AsPlainText -Force;
$AzureRMCredential = new-object -typename System.Management.Automation.PSCredential($MyAzureName, $MyAzurePassword);
#step 2: login azure rm account and select subscrptionid
$e1=Get-AzureRmEnvironment -Name AzureChinaCloud
$AzureRMCred = Get-Credential -Credential $AzureRMCredential;
Login-AzureRmAccount -Environment $e1 -Credential $AzureRMCred
Select-AzureRmSubscription -SubscriptionId yoursubid
#step 3: get ResourceProvider 查看 Microsoft.Cache 是否注册,如果已经注册则略过step4
Get-AzureRmResourceProvider | ft
ProviderNamespace RegistrationState ResourceTypes Locations
----------------- ----------------- ------------- ---------
Microsoft.Backup Registered {BackupVault} {China East, China North}
Microsoft.Batch Registered {batchAccounts, operations, locations, loca... {China North, China East}
Microsoft.Cache Registered {Redis, locations, locations/operationResul... {China North, China East}
Microsoft.ClassicCompute Registered {domainNames, checkDomainNameAvailability, ... {China North, China East}
Microsoft.ClassicNetwork Registered {virtualNetworks, reservedIps, quotas, gate... {China North, China East}
Microsoft.ClassicStorage Registered {storageAccounts, quotas, checkStorageAccou... {China North, China East}
Microsoft.Compute Registered {availabilitySets, virtualMachines, virtual... {China North, China East}
Microsoft.Devices Registered {checkNameAvailability, operations, IotHubs} {China North, China East}
Microsoft.DocumentDB Registered {databaseAccounts, databaseAccountNames, op... {China North, China East}
microsoft.insights Registered {logprofiles, alertrules, autoscalesettings... {China North, China East}
Microsoft.KeyVault Registered {vaults, vaults/secrets, operations} {China North, China East}
Microsoft.MySql Registered {servers} {China East, China North}
Microsoft.Sql Registered {operations, locations, locations/capabilit... {China North, China East}
Microsoft.Storage Registered {storageAccounts, operations, usages, check... {China North, China East}
Microsoft.StreamAnalytics Registered {streamingjobs, locations, locations/quotas... {China North, China East}
Microsoft.Web Registered {sites/extensions, sites/slots/extensions, ... {China North, China East}
Microsoft.Authorization Registered {roleAssignments, roleDefinitions, classicA... {}
Microsoft.Features Registered {features, providers} {}
Microsoft.Resources Registered {tenants, locations, providers, checkresour... {China North, China East}
Microsoft.Scheduler Registered {jobcollections, operations, operationResults} {China North, China East}
#step 4:新建资源组和持久化所在的storageaccount
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.Cache
$rgname='yourresourcegroupname'
$redisname="$redisname"
#New-AzureRmResourceGroup -Name test -Location "China East" #or "china north"
$storageaccount="testrmstorageaccount"
#New-AzureRmStorageAccount -ResourceGroupName Sunmsy -Name $storageaccount -Location "China East" -Type Standard_LRS
$keys=Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name yourstorageaccountname
$key_Primary=$keys[0].Value
#step 5:新建redis cache并做持久化
New-AzureRmRedisCache -Name $redisname -ResourceGroupName $rgname -Location "china East" -Size P1 -Sku Premium -RedisConfiguration @{"rdb-backup-enabled"="true";"rdb-storage-connection-string" = "DefaultEndpointsProtocol=https;AccountName=$storageaccount;AccountKey=$key_Primary;EndpointSuffix=core.chinacloudapi.cn";"rdb-backup-frequency"="60"}
#step 6: get redis cache
Get-AzureRmRedisCache -ResourceGroupName $rgname -Name $redisname
#step 7: get redis key
$rediskey= Get-AzureRmRedisCacheKey -ResourceGroupName $rgname -Name $redisname
#step 8 导入/导出 RDB 文件
Export-AzureRmRedisCache/ Import-AzureRmRedisCache
#step 9: 缩放、管理redis cache
# Set-AzureRmRedisCache -Name <String> -ResourceGroupName <String> [-Size <String>] [-Sku <String>] [-MaxMemoryPolicy <String>] [-RedisConfiguration <Hashtable>] [-EnableNonSslPort <Boole
an>] [-ShardCount <Integer>] [<CommonParameters>]
#例如打开6379 端口,默认关闭
Set-AzureRmRedisCache -ResourceGroupName $resourcegroup -Name $redisname -EnableNonSslPort 1
# 导入aof 文件, LINUX CMD
redis-cli -h $redisname.redis.cache.chinacloudapi.cn –a youaccesskey -p 6379 --pipe < appendonly.aof
#step 10: 开启诊断命令
$subid="yoursubid"
$resourcegroup="yourresourcegroupname"
$storageaccount="yourstorageaccountname"
Set-AzureRmRedisCacheDiagnostics -ResourceGroupName $resourcegroup -Name $redisname -StorageAccountId "/subscriptions/$subid/resourceGroups/$resourcegroup/providers/Microsoft.Storage/storageAccounts/$storageaccount"
#step 11: 删除
Remove-AzureRmRedisCacheDiagnostics -ResourceGroupName $rgname -Name $redisname