使用虛擬機器擴展集搭配 Azure DSC 擴充功能

虛擬機器擴展集可與 Azure 所需狀態設定 (DSC) 擴充功能處理常式搭配使用。 虛擬機器擴展集 提供部署和管理大量虛擬機器的方法,並能根據負載彈性地擴展進出。 DSC 會在 VM 上線時用於設定它們,使其執行正式執行軟體。

Note

DSC 擴充功能將於 2028 年 3 月 31 日淘汰。 在該日期前移轉至 Azure 機器設定。 如需詳細資訊,請參閱 部落格文章 公告。 Azure Machine Configuration 服務結合了 DSC 擴充功能、Azure 自動化狀態設定的特定功能,以及客戶意見反應中常用的功能。 Azure Machine Configuration 也包含混合機器支援 (透過已啟用 Arc 的伺服器提供)。

部署至虛擬機器與虛擬機器擴展集的差異

虛擬機縮放集的底層模板結構與單一虛擬機略有不同。 具體而言,單一 VM 會在「virtualMachines」節點下部署擴充功能。 範本中有一個類型為「extensions」的項目,DSC 會加入到該項目中

"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')]"
                  }
              }
          }
      ]

虛擬機縮放集節點有一個「屬性」區塊,包含「VirtualMachineProfile」、「extensionProfile」屬性。 DSC 會被加入「延伸」欄位

"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')]"
                        }
                    }
                }
            ]

虛擬機器擴展集的行為

虛擬機擴展集的行為與單一虛擬機的行為相同。 當新虛擬機建立時,會自動以 DSC 擴充功能進行配置。 如果擴充功能需要較新的 WMF 版本,VM 會先重新啟動,然後才恢復連線。 一旦上線,它會下載DSC設定 .zip 並在虛擬機上配置。 更多細節可見於 the Azure DSC Extension Overview。

下一步

查看 適用於 DSC 擴充功能的 Azure Resource Manager 範本。

了解 DSC 擴充功能如何安全地處理憑證。

欲了解更多關於 Azure DSC 擴充處理器的資訊,請參見 Azure Desired State Configuration擴展處理器簡介。

欲了解更多關於 PowerShell DSC 的資訊,請 造訪 PowerShell 文件中心。