通过带数据盘的自定义镜像来创建使用应用程序网关的虚拟机规模集
虛擬機規模集是一種 Azure 計算資源,可用于部署和管理一組相同的 VM。 規模集中的所有 VM 采用相同的配置,無需對 VM 進行預配就可以進行自動橫向擴展。 這樣就可以更方便地構建面向大型計算、大型數據、容器化工作負荷的大規模服務。
如果用戶需要通過一個帶數據盤的自定義鏡像來創建規模集,數據盤里可能存放用戶定制應用,同時又希望辦規模集置于應用程序網關之后,而不是簡單的使用負載均衡服務,那么下面這段模板,可以幫助用戶實現以上功能。
?
{
??? "$schema": "http://schema.management.azure.com/schemas/2015-01-01-preview/deploymentTemplate.json",
??? "contentVersion": "1.0.0.0",
??? "parameters": {
??????? "vmSku": {
??????????? "defaultValue": "Standard_A0",
??????????? "type": "String",
??????????? "metadata": {
??????????????? "description": "Size of VMs in the VM Scale Set."
??????????? }
???? ???},
??????? "sourceImageID": {
??????????? "type": "String",
??????????? "metadata": {
??????????????? "description": "The source Image ID, must be in the same region of the deployment."
??????????? }
??????? },
??????? "vmssName": {
??????????? "maxLength": 61,
??????????? "type": "String",
??????????? "metadata": {
??????????????? "description": "String used as a base for naming resources. Must be 3-61 characters in length and globally unique across Azure. A hash is prepended to this string for some resources, and resource-specific information is appended."
??????????? }
??????? },
??????? "instanceCount": {
??????????? "maxValue": 100,
??????????? "type": "Int",
??????????? "metadata": {
??????????????? "description": "Number of VM instances (100 or less)."
??????????? }
??????? },
??????? "adminUsername": {
??????????? "type": "String",
??????????? "metadata": {
??????????????? "description": "Admin username on all VMs."
??????????? }
?? ?????},
??????? "adminPassword": {
??????????? "type": "SecureString",
??????????? "metadata": {
??????????????? "description": "Admin password on all VMs."
??????????? }
??????? },
??????? "existingSubnetResourceId": {
??????????? "type": "String",
????? ??????"metadata": {
??????????????? "description": "Resource ID of the existing subnet to deploy the scale set into. Should be of the form: /subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP/providers/Microsoft.Network/virtualNetworks/YOUR_VNET_NAME/subnets/YOUR_SUBNET_NAME"
??????????? }
??????? },
??????? "AppgwSubnetResourceId": {
??????????? "type": "String",
??????????? "metadata": {
??????????????? "description": "Resource ID of the existing subnet to deploy the scale set into. Should be of the form: /subscriptions/YOUR_SUBSCRIPTION_ID/resourceGroups/YOUR_RESOURCE_GROUP/providers/Microsoft.Network/virtualNetworks/YOUR_VNET_NAME/subnets/YOUR_SUBNET_NAME"
??????????? }
??????? }
??? },
??? "variables": {
??????? "storageAccountType": "Standard_LRS",
??????? "namingInfix": "[toLower(substring(concat(parameters('vmssName'), uniqueString(resourceGroup().id)), 0, 9))]",
??????? "wadnameInfix": "[concat(variables('namingInfix'), 'autoscalewad')]",
??????? "longNamingInfix": "[toLower(parameters('vmssName'))]",
??????? "newStorageAccountSuffix": "[concat(variables('namingInfix'), 'sa')]",
??????? "publicIPAddressName": "[concat(variables('namingInfix'), 'pip')]",
??????? "loadBalancerName": "[concat(variables('namingInfix'), 'appgw')]",
??????? "publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]",
??????? "lbID": "[resourceId('Microsoft.Network/applicationGateways',variables('loadBalancerName'))]",
??????? "natPoolName": "[concat(variables('namingInfix'), 'natpool')]",
??????? "bePoolName": "appGatewayBackendPool",
??????? "natStartPort": 50000,
??????? "natEndPort": 50119,
??????? "natBackendPort": 22,
??????? "nicName": "[concat(variables('namingInfix'), 'nic')]",
??????? "ipConfigName": "[concat(variables('namingInfix'), 'ipconfig')]",
??????? "frontEndIPConfigID": "[concat(variables('lbID'),'/frontendIPConfigurations/appGatewayFrontendIP')]",
??????? "diagnosticsStorageAccountName": "[concat(uniqueString(concat(resourceGroup().id, variables('newStorageAccountSuffix'))), variables('newStorageAccountSuffix'))]",
??????? "diagnosticsStorageAccountResourceGroup": "[resourceGroup().name]",
??????? "accountid": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',variables('diagnosticsStorageAccountResourceGroup'),'/providers/','Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]",
??????? "wadlogs": "<WadCfg><DiagnosticMonitorConfiguration>",
??????? "wadperfcounters1": "<PerformanceCounters scheduledTransferPeriod=\"PT1M\"><PerformanceCounterConfiguration counterSpecifier=\"\\Memory\\AvailableMemory\" sampleRate=\"PT15S\" unit=\"Bytes\"><annotation displayName=\"Memory available\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Memory\\PercentAvailableMemory\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"Mem. percent available\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Memory\\UsedMemory\" sampleRate=\"PT15S\" unit=\"Bytes\"><annotation displayName=\"Memory used\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Memory\\PercentUsedMemory\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"Memory percentage\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Memory\\PercentUsedByCache\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"Mem. used by cache\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Processor\\PercentIdleTime\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"CPU idle time\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Processor\\PercentUserTime\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"CPU user time\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Processor\\PercentProcessorTime\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"CPU percentage guest OS\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\Processor\\PercentIOWaitTime\" sampleRate=\"PT15S\" unit=\"Percent\"><annotation displayName=\"CPU IO wait time\" locale=\"en-us\"/></PerformanceCounterConfiguration>",
??????? "wadperfcounters2": "<PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\BytesPerSecond\" sampleRate=\"PT15S\" unit=\"BytesPerSecond\"><annotation displayName=\"Disk total bytes\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\ReadBytesPerSecond\" sampleRate=\"PT15S\" unit=\"BytesPerSecond\"><annotation displayName=\"Disk read guest OS\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\WriteBytesPerSecond\" sampleRate=\"PT15S\" unit=\"BytesPerSecond\"><annotation displayName=\"Disk write guest OS\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\TransfersPerSecond\" sampleRate=\"PT15S\" unit=\"CountPerSecond\"><annotation displayName=\"Disk transfers\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\ReadsPerSecond\" sampleRate=\"PT15S\" unit=\"CountPerSecond\"><annotation displayName=\"Disk reads\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\WritesPerSecond\" sampleRate=\"PT15S\" unit=\"CountPerSecond\"><annotation displayName=\"Disk writes\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\AverageReadTime\" sampleRate=\"PT15S\" unit=\"Seconds\"><annotation displayName=\"Disk read time\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\AverageWriteTime\" sampleRate=\"PT15S\" unit=\"Seconds\"><annotation displayName=\"Disk write time\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\AverageTransferTime\" sampleRate=\"PT15S\" unit=\"Seconds\"><annotation displayName=\"Disk transfer time\" locale=\"en-us\"/></PerformanceCounterConfiguration><PerformanceCounterConfiguration counterSpecifier=\"\\PhysicalDisk\\AverageDiskQueueLength\" sampleRate=\"PT15S\" unit=\"Count\"><annotation displayName=\"Disk queue length\" locale=\"en-us\"/></PerformanceCounterConfiguration></PerformanceCounters>",
??????? "wadcfgxstart": "[concat(variables('wadlogs'),variables('wadperfcounters1'),variables('wadperfcounters2'),'<Metrics resourceId=\"')]",
??????? "wadmetricsresourceid": "[concat('/subscriptions/',subscription().subscriptionId,'/resourceGroups/',resourceGroup().name ,'/providers/','Microsoft.Compute/virtualMachineScaleSets/',variables('namingInfix'))]",
??????? "wadcfgxend": "[concat('\"><MetricAggregation scheduledTransferPeriod=\"PT1H\"/><MetricAggregation scheduledTransferPeriod=\"PT1M\"/></Metrics></DiagnosticMonitorConfiguration></WadCfg>')]",
??????? "computeApiVersion": "2016-04-30-preview",
??????? "networkApiVersion": "2016-03-30",
??????? "storageApiVersion": "2015-06-15",
??????? "insightsApiVersion": "2015-04-01"
??? },
??? "resources": [
??????? {
??????????? "type": "Microsoft.Storage/storageAccounts",
??????????? "name": "[variables('diagnosticsStorageAccountName')]",
??????????? "apiVersion": "2015-06-15",
??????????? "location": "[resourceGroup().location]",
??????????? "properties": {
???????? ???????"accountType": "[variables('storageAccountType')]"
??????????? }
??????? },
??????? {
??????????? "type": "Microsoft.Network/publicIPAddresses",
??????????? "name": "[variables('publicIPAddressName')]",
??????????? "apiVersion": "[variables('networkApiVersion')]",
??????????? "location": "[resourceGroup().location]",
??????????? "properties": {
??????????????? "publicIPAllocationMethod": "Dynamic",
??????????????? "dnsSettings": {
??????????????????? "domainNameLabel": "[variables('longNamingInfix')]"
??????????????? }
??????????? }
??????? },
??????? {
??????????? "type": "Microsoft.Network/applicationGateways",
??????????? "name": "[variables('loadBalancerName')]",
??????????? "apiVersion": "[variables('networkApiVersion')]",
??????????? "location": "[resourceGroup().location]",
??????????? "properties": {
??????????????? "sku": {
??????????????????? "name": "WAF_Medium",
??????????????????? "tier": "WAF",
??????????????????? "capacity": "1"
??????????????? },
??????????????? "gatewayIPConfigurations": [
??????????????????? {
??????????????????????? "name": "appGatewayIpConfig",
??????????????????????? "properties": {
??????????????????????????? "subnet": {
??????????????????????????????? "id": "[parameters('AppgwSubnetResourceId')]"
??????????????????????????? }
??????????????????????? }
??????????????????? }
??????????????? ],
??????????????? "frontendIPConfigurations": [
??????????????????? {
??????????????????????? "name": "appGatewayFrontendIP",
??????????????????????? "properties": {
??????????????????????????? "PublicIPAddress": {
??????????????????????????????? "id": "[variables('publicIPAddressID')]"
??????????????????????????? }
??????????????????????? }
??????????????????? }
??????????????? ],
??????????????? "frontendPorts": [
??????????????????? {
??????????????????????? "name": "appGatewayFrontendPort",
??????????????????????? "properties": {
??????????????????????????? "Port": 80
??????????????????????? }
??????????????????? }
????????????? ??],
??????????????? "backendAddressPools": [
??????????????????? {
??????????????????????? "name": "[variables('bePoolName')]"
??????????????????? }
??????????????? ],
??????????????? "backendHttpSettingsCollection": [
??????????????????? {
????????????? ??????????"name": "appGatewayBackendHttpSettings",
??????????????????????? "properties": {
??????????????????????????? "Port": 80,
??????????????????????????? "Protocol": "Http",
??????????????????????????? "CookieBasedAffinity": "Disabled"
?????????????? ?????????}
??????????????????? }
??????????????? ],
??????????????? "httpListeners": [
??????????????????? {
??????????????????????? "name": "appGatewayHttpListener",
??????????????????????? "properties": {
??????????????????????????? "FrontendIPConfiguration": {
??????????????????????????????? "Id": "[concat(variables('lbID'), '/frontendIPConfigurations/appGatewayFrontendIP')]"
??????????????????????????? },
??????????????????????????? "FrontendPort": {
??????????????????????????????? "Id": "[concat(variables('lbID'), '/frontendPorts/appGatewayFrontendPort')]"
??????????????????????????? },
??????????????????????????? "Protocol": "Http",
??????????????????????????? "SslCertificate": null
???????????????? ???????}
??????????????????? }
??????????????? ],
??????????????? "requestRoutingRules": [
??????????????????? {
??????????????????????? "Name": "rule1",
??????????????????????? "properties": {
??????????????????????????? "RuleType": "Basic",
???????????? ???????????????"httpListener": {
??????????????????????????????? "id": "[concat(variables('lbID'), '/httpListeners/appGatewayHttpListener')]"
??????????????????????????? },
??????????????????????????? "backendAddressPool": {
?????????????????????????????? ?"id": "[concat(variables('lbID'), '/backendAddressPools/appGatewayBackendPool')]"
??????????????????????????? },
??????????????????????????? "backendHttpSettings": {
??????????????????????????????? "id": "[concat(variables('lbID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
??????????????????????????? }
??????????????????????? }
??????????????????? }
??????????????? ]
??????????? },
??????????? "dependsOn": [
??????????????? "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
??????????? ]
??????? },
??????? {
??????????? "type": "Microsoft.Compute/virtualMachineScaleSets",
??????????? "sku": {
??????????????? "name": "[parameters('vmSku')]",
??????????????? "tier": "Standard",
??????????????? "capacity": "[parameters('instanceCount')]"
??????????? },
??????????? "name": "[variables('namingInfix')]",
??????????? "apiVersion": "[variables('computeApiVersion')]",
??????????? "location": "[resourceGroup().location]",
??????????? "properties": {
??????????????? "overprovision": "true",
??????????????? "upgradePolicy": {
??????????????????? "mode": "Manual"
??????????????? },
??????????????? "virtualMachineProfile": {
??????????????????? "storageProfile": {
??????????????????????? "osDisk": {
??????????????????????????? "createOption": "FromImage",
??????????????????????????? "managedDisk": {
??????????????????????????????? "storageAccountType": "Standard_LRS"
??????????????????????????? }
??????????????????????? },
??????????????????? ????"imageReference": {
??????????????????????????? "id": "[parameters('sourceImageID')]"
??????????????????????? }
??????????????????? },
??????????????????? "osProfile": {
??????????????????????? "computerNamePrefix": "[variables('namingInfix')]",
??????????????????????? "adminUsername": "[parameters('adminUsername')]",
??????????????????????? "adminPassword": "[parameters('adminPassword')]"
??????????????????? },
??????????????????? "networkProfile": {
??????????????????????? "networkInterfaceConfigurations": [
??????????????????????????? {
??????????????????????????????? "name": "[variables('nicName')]",
??????????????????????????????? "properties": {
??????????????????????????????????? "primary": "true",
??????????????????????????????????? "ipConfigurations": [
??????????????????????????????????????? {
??????????????????????????????????????????? "name": "[variables('ipConfigName')]",
??????????????????????????????????????????? "properties": {
??????????????????????????????????????????????? "subnet": {
??????????????????????????????????????????????????? "id": "[parameters('existingSubnetResourceId')]"
??????????????????????????????????????????????? },
??????????????????????????????????????????????? "applicationGatewayBackendAddressPools": [
???????? ???????????????????????????????????????????{
??????????????????????????????????????????????????????? "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/applicationGateways/', variables('loadBalancerName'), '/backendAddressPools/', variables('bePoolName'))]"
??????????????????????????????????????????????????? }
??????????????????????????????????????????????? ]
??????????????????????????????????????????? }
?????????????????? ?????????????????????}
??????????????????????????????????? ]
??????????????????????????????? }
??????????????????????????? }
??????????????????????? ]
??????????????????? },
??????????????????? "extensionProfile": {
??????????????????????? "extensions": [
??????????????????????????? {
??????????????????????????????? "name": "LinuxDiagnostic",
??????????????????????????????? "properties": {
??????????????????????????????????? "publisher": "Microsoft.OSTCExtensions",
??????????????????????????????????? "type": "LinuxDiagnostic",
??????????????????????????????????? "typeHandlerVersion": "2.3",
??????????????????????????????????? "autoUpgradeMinorVersion": true,
??????????????????????????????????? "settings": {
??????????????????????????????????????? "xmlCfg": "[base64(concat(variables('wadcfgxstart'),variables('wadmetricsresourceid'),variables('wadcfgxend')))]",
??????????????????????????????????????? "storageAccount": "[variables('diagnosticsStorageAccountName')]"
??????????????????????????????????? },
??????? ????????????????????????????"protectedSettings": {
??????????????????????????????????????? "storageAccountName": "[variables('diagnosticsStorageAccountName')]",
??????????????????????????????????????? "storageAccountKey": "[listkeys(variables('accountid'), variables('storageApiVersion')).key1]",
??????????????????????????????????????? "storageAccountEndPoint": "https://core.chinacloudapi.cn"
??????????????????????????????????? }
??????????????????????????????? }
??????????????????????????? }
?????????????? ?????????]
??????????????????? }
??????????????? }
??????????? },
??????????? "dependsOn": [
??????????????? "[concat('Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]",
??????????????? "[concat('Microsoft.Network/applicationGateways/', variables('loadBalancerName'))]"
??????????? ]
??????? },
??????? {
??????????? "type": "Microsoft.Insights/autoscaleSettings",
??????????? "name": "[variables('wadnameInfix')]",
??????????? "apiVersion": "[variables('insightsApiVersion')]",
??????????? "location": "[resourceGroup().location]",
??????????? "properties": {
??????????????? "name": "[variables('wadnameInfix')]",
??????????????? "targetResourceUri": "[concat('/subscriptions/',subscription().subscriptionId, '/resourceGroups/',? resourceGroup().name, '/providers/Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]",
??????????????? "enabled": true,
??????????????? "profiles": [
??????????????????? {
??????????????????????? "name": "Profile1",
????????????????????? ??"capacity": {
??????????????????????????? "minimum": "1",
??????????????????????????? "maximum": "100",
??????????????????????????? "default": "1"
??????????????????????? },
??????????????????????? "rules": [
??????????????????????????? {
?????????????? ?????????????????"metricTrigger": {
??????????????????????????????????? "metricName": "\\Processor\\PercentProcessorTime",
??????????????????????????????????? "metricNamespace": "",
??????????????????????????????????? "metricResourceUri": "[concat('/subscriptions/',subscription().subscriptionId, '/resourceGroups/',? resourceGroup().name, '/providers/Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]",
??????????????????????????????????? "timeGrain": "PT1M",
???????????????????????????? ???????"statistic": "Average",
??????????????????????????????????? "timeWindow": "PT5M",
??????????????????????????????????? "timeAggregation": "Average",
??????????????????????????????????? "operator": "GreaterThan",
??????????????????????????????????? "threshold": 50
??????????????????????????????? },
??????????????????????????????? "scaleAction": {
??????????????????????????????????? "direction": "Increase",
??????????????????????????????????? "type": "ChangeCount",
??????????????????????????????????? "value": "1",
??????????????????????????????????? "cooldown": "PT1M"
??????????????????????????????? }
??????????????????????????? },
??????????????????????????? {
??????????????????????????????? "metricTrigger": {
???? ???????????????????????????????"metricName": "\\Processor\\PercentProcessorTime",
??????????????????????????????????? "metricNamespace": "",
??????????????????????????????????? "metricResourceUri": "[concat('/subscriptions/',subscription().subscriptionId, '/resourceGroups/',? resourceGroup().name, '/providers/Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]",
??????????????????????????????????? "timeGrain": "PT1M",
??????????????????????????????????? "statistic": "Average",
????????? ??????????????????????????"timeWindow": "PT5M",
??????????????????????????????????? "timeAggregation": "Average",
??????????????????????????????????? "operator": "LessThan",
??????????????????????????????????? "threshold": 30
????????????????????????????? ??},
??????????????????????????????? "scaleAction": {
??????????????????????????????????? "direction": "Decrease",
??????????????????????????????????? "type": "ChangeCount",
??????????????????????????????????? "value": "1",
??????????????????????????????? ????"cooldown": "PT5M"
??????????????????????????????? }
??????????????????????????? }
??????????????????????? ]
??????????????????? }
??????????????? ]
??????????? },
??????????? "dependsOn": [
??????????????? "[concat('Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]"
??????????? ]
??????? }
??? ]
}
?
請注意,由于目前Portal功能限制,用戶是無法修改規模集在應用程序網關中的設置的,
?
?
轉載于:https://www.cnblogs.com/lujohn74/p/8758319.html
總結
以上是生活随笔為你收集整理的通过带数据盘的自定义镜像来创建使用应用程序网关的虚拟机规模集的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 翻译:程序员数据结构基础:选择正确的数据
- 下一篇: iOS高级必备