将虚拟机规模集与 Azure DSC 扩展配合使用Using Virtual Machine Scale Sets with the Azure DSC Extension

虚拟机规模集可与 Azure 期望状态配置 (DSC) 扩展处理程序配合使用。Virtual Machine Scale Sets can be used with the Azure Desired State Configuration (DSC) extension handler. 虚拟机规模集提供部署和管理大量虚拟机的方法,并且可根据负载情况实现弹性横向缩减和扩展。Virtual machine scale sets provide a way to deploy and manage large numbers of virtual machines, and can elastically scale in and out in response to load. VM 联机时,DSC 用于配置 VM,使它们能够运行生产软件。DSC is used to configure the VMs as they come online so they are running the production software.

部署到虚拟机和部署到虚拟机规模集之间的区别Differences between deploying to Virtual Machines and Virtual Machine Scale Sets

虚拟机规模集的基础模板结构与单一 VM 略有不同。The underlying template structure for a virtual machine scale set is slightly different from a single VM. 具体而言,单一 VM 是在“virtualMachines”节点下扩展部署。Specifically, a single VM deploys extensions under the "virtualMachines" node. 其中有一个 "type": "extensions" 条目,用于将 DSC 添加到模板中There is an entry of type "extensions" where DSC is added to the template

"resources": [
          {
              "name": "Microsoft.Powershell.DSC",
              "type": "extensions",
              "location": "[resourceGroup().location]",
              "apiVersion": "2015-06-15",
              "dependsOn": [
                  "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
              ],
              "tags": {
                  "displayName": "dscExtension"
              },
              "properties": {
                  "publisher": "Microsoft.Powershell",
                  "type": "DSC",
                  "typeHandlerVersion": "2.20",
                  "autoUpgradeMinorVersion": false,
                  "forceUpdateTag": "[parameters('dscExtensionUpdateTagVersion')]",
                  "settings": {
                      "configuration": {
                          "url": "[concat(parameters('_artifactsLocation'), '/', variables('dscExtensionArchiveFolder'), '/', variables('dscExtensionArchiveFileName'))]",
                          "script": "DscExtension.ps1",
                          "function": "Main"
                      },
                      "configurationArguments": {
                          "nodeName": "[variables('vmName')]"
                      }
                  },
                  "protectedSettings": {
                      "configurationUrlSasToken": "[parameters('_artifactsLocationSasToken')]"
                  }
              }
          }
      ]

虚拟机规模集节点具有“properties”节,其中包含“VirtualMachineProfile”和“extensionProfile”属性。A virtual machine scale set node has a "properties" section with the "VirtualMachineProfile", "extensionProfile" attribute. DSC 添加在“extensions”下面DSC is added under "extensions"

"extensionProfile": {
            "extensions": [
                {
                    "name": "Microsoft.Powershell.DSC",
                    "properties": {
                        "publisher": "Microsoft.Powershell",
                        "type": "DSC",
                        "typeHandlerVersion": "2.20",
                        "autoUpgradeMinorVersion": false,
                        "forceUpdateTag": "[parameters('DscExtensionUpdateTagVersion')]",
                        "settings": {
                            "configuration": {
                                "url": "[concat(parameters('_artifactsLocation'), '/', variables('DscExtensionArchiveFolder'), '/', variables('DscExtensionArchiveFileName'))]",
                                "script": "DscExtension.ps1",
                                "function": "Main"
                            },
                            "configurationArguments": {
                                "nodeName": "localhost"
                            }
                        },
                        "protectedSettings": {
                            "configurationUrlSasToken": "[parameters('_artifactsLocationSasToken')]"
                        }
                    }
                }
            ]

虚拟机规模集的行为Behavior for a Virtual Machine Scale Set

虚拟机规模集的行为与单一 VM 的行为相同。The behavior for a virtual machine scale set is identical to the behavior for a single VM. 创建新 VM 后,会自动使用 DSC 扩展对其进行预配。When a new VM is created, it is automatically provisioned with the DSC extension. 如果扩展需要更新的 WMF 版本,则 VM 会重新启动,并联机。If a newer version of the WMF is required by the extension, the VM reboots before coming online. VM 联机后,将下载 DSC 配置 .zip 文件,并在 VM 上预配该文件。Once it is online, it downloads the DSC configuration .zip and provision it on the VM. Azure DSC 扩展概述中可以找到详细信息。More details can be found in the Azure DSC Extension Overview.

后续步骤Next steps

检查适用于 DSC 扩展的 Azure 资源管理器模板Examine the Azure Resource Manager template for the DSC extension.

了解DSC 扩展安全处理凭据的方法。Learn how the DSC extension securely handles credentials.

有关 Azure DSC 扩展处理程序的详细信息,请参阅 Introduction to the Azure Desired State Configuration extension handler(Azure Desired State Configuration 扩展处理程序简介)。For more information on the Azure DSC extension handler, see Introduction to the Azure Desired State Configuration extension handler.

有关 PowerShell DSC 的详细信息,请访问 PowerShell 文档中心For more information about PowerShell DSC, visit the PowerShell documentation center.