Azure Automation State Configuration 入门Getting started with Azure Automation State Configuration

本文说明如何使用 Azure Automation State Configuration 执行最常见的任务,例如创建、导入、编译配置,加入要管理的计算机和查看报告。This article explains how to do the most common tasks with Azure Automation State Configuration, such as creating, importing, and compiling configurations, onboarding machines to manage, and viewing reports. 有关 Azure Automation State Configuration 的概述,请参阅 Azure Automation State Configuration 概述For an overview of what Azure Automation State Configuration is, see Azure Automation State Configuration Overview. 有关 Desired State Configuration (DSC) 文档,请参阅 Windows PowerShell Desired State Configuration 概述For Desired State Configuration (DSC) documentation, see Windows PowerShell Desired State Configuration Overview.

本文提供有关如何使用 Azure Automation State Configuration 的分步指南。This article provides a step-by-step guide to using Azure Automation State Configuration. 如果需要一个已经设置好的示例环境,而不想按照本文所述步骤进行操作,则可使用以下资源管理器模板:Azure 自动化托管节点模板If you want a sample environment that is already set up without following the steps described in this article, you can use the following Resource Manager template: Azure Automation Managed Node template. 此模板设置了一个完整的 Azure Automation State Configuration 环境,包括一个由 Azure Automation State Configuration 管理的 Azure VM。This template sets up a completed Azure Automation State Configuration environment, including an Azure VM that is managed by Azure Automation State Configuration.

先决条件Prerequisites

若要完成本文中的示例,需要具备以下条件:To complete the examples in this article, the following are required:

创建 DSC 配置Creating a DSC configuration

将创建一个简单的 DSC 配置,以确保存在(或不存在)Web-Server Windows 功能 (IIS),具体取决于分配节点的方式。You create a simple DSC configuration that ensures either the presence or absence of the Web-Server Windows Feature (IIS), depending on how you assign nodes.

  1. 启动 VSCode(或任何文本编辑器)。Start VSCode (or any text editor).

  2. 键入以下文本:Type the following text:

    configuration TestConfig
    {
        Node IsWebServer
        {
            WindowsFeature IIS
            {
                Ensure               = 'Present'
                Name                 = 'Web-Server'
                IncludeAllSubFeature = $true
            }
        }
    
        Node NotWebServer
        {
            WindowsFeature IIS
            {
                Ensure               = 'Absent'
                Name                 = 'Web-Server'
            }
        }
    }
    
  3. 将文件另存为 TestConfig.ps1Save the file as TestConfig.ps1.

此配置调用每个节点块中的一个资源(WindowsFeature 资源),以确保存在(或不存在)Web-Server 功能。This configuration calls one resource in each node block, the WindowsFeature resource, that ensures either the presence or absence of the Web-Server feature.

将配置导入 Azure 自动化Importing a configuration into Azure Automation

接下来,会将配置导入自动化帐户。Next, you import the configuration into the Automation account.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”页上的“配置管理”下,选择“State configuration (DSC)”。 On the Automation account page, select State configuration (DSC) under Configuration Management.

  4. 在“State configuration (DSC)”页上,依次单击“配置”选项卡、“+ 添加”。 On the State configuration (DSC) page, click the Configurations tab, then click + Add.

  5. 在“导入配置” 页中,浏览到计算机上的 TestConfig.ps1 文件。On the Import Configuration page, browse to the TestConfig.ps1 file on your computer.

    导入配置边栏选项卡的屏幕截图

  6. 单击 “确定”Click OK.

查看 Azure 自动化中的配置Viewing a configuration in Azure Automation

在导入配置以后,即可在 Azure 门户中查看该配置。After you have imported a configuration, you can view it in the Azure portal.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”页上的“配置管理”下,选择“State configuration (DSC)”。 On the Automation account page, select State configuration (DSC) under Configuration Management.

  4. 在“State configuration (DSC)”页上单击“配置”选项卡,然后单击“TestConfig”(这是在前一过程中导入的配置的名称)。 On the State configuration (DSC) page, click the Configurations tab, then click TestConfig (this is the name of the configuration you imported in the previous procedure).

  5. 在“TestConfig 配置” 页中,单击“查看配置源” 。On the TestConfig Configuration page, click View configuration source.

    “TestConfig 配置”边栏选项卡的屏幕快照

    此时会打开“TestConfig 配置源” 页面,其中显示配置的 PowerShell 代码。A TestConfig Configuration source page opens, displaying the PowerShell code for the configuration.

编译 Azure 自动化中的配置Compiling a configuration in Azure Automation

在将所需状态应用到某个节点之前,必须将定义该状态的 DSC 配置编译成一个或多个节点配置(MOF 文档),然后放置在自动化 DSC 拉取服务器上。Before you can apply a desired state to a node, a DSC configuration defining that state must be compiled into one or more node configurations (MOF document), and placed on the Automation DSC Pull Server. 如需在 Azure Automation State Configuration 中进行配置编译的更详细说明,请参阅在 Azure Automation State Configuration 中编译配置For a more detailed description of compiling configurations in Azure Automation State Configuration, see Compiling configurations in Azure Automation State Configuration. 有关编译配置的详细信息,请参阅 DSC 配置For more information about compiling configurations, see DSC Configurations.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”页上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account page, click State configuration (DSC) under Configuration Management.

  4. 在“State configuration (DSC)”页上单击“配置”选项卡,然后单击“TestConfig”(前面导入的配置的名称)。 On the State configuration (DSC) page, click the Configurations tab, then click TestConfig (the name of the previously imported configuration).

  5. 在“TestConfig 配置” 页中,单击“编译” ,并单击“是” 。On the TestConfig Configuration page, click Compile, and then click Yes. 此时会启动编译作业。This starts a compilation job.

    “TestConfig 配置”页的屏幕截图,其中突出显示“编译”按钮

Note

在 Azure 自动化中编译配置时,会自动将任何创建的节点配置 MOF 部署到拉取服务器。When you compile a configuration in Azure Automation, it automatically deploys any created node configuration MOFs to the pull server.

查看编译作业Viewing a compilation job

开始编译后,即可在“配置”页面的“编译作业”磁贴中查看该作业 。After you start a compilation, you can view it in the Compilation Jobs tile in the Configuration page. “编译作业” 磁贴显示当前正在运行的、已完成的以及失败的作业。The Compilation Jobs tile shows currently running, completed, and failed jobs. 打开编译作业页面时,会显示有关该作业的信息,包括遇到的任何错误或警告、在配置中使用的输入参数以及编译日志。When you open a compilation job page, it shows information about that job including any errors or warnings encountered, input parameters used in the configuration, and compilation logs.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”页上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account page, click State configuration (DSC) under Configuration Management.

  4. 在“State configuration (DSC)”页上单击“配置”选项卡,然后单击“TestConfig”(前面导入的配置的名称)。 On the State configuration (DSC) page, click the Configurations tab, then click TestConfig (the name of the previously imported configuration).

  5. 在“编译作业” 下,选择要查看的编译作业。Under Compilation jobs, select the compilation job you want to view. 此时会打开“编译作业” 页,其中标记了启动编译作业的日期。A Compilation Job page opens labeled with the date that the compilation job was started.

    “编译作业”页的屏幕截图

  6. 单击“编译作业” 页中的任意磁贴,了解有关该作业的更多详细信息。Click on any tile in the Compilation Job page to see further details about the job.

查看节点配置Viewing node configurations

成功完成编译作业以后,会创建一个或多个新的节点配置。Successful completion of a compilation job creates one or more new node configurations. 节点配置是一个 MOF 文档,该文档部署到拉取服务器上,可供一个或多个节点拉取和应用。A node configuration is a MOF document that is deployed to the pull server and ready to be pulled and applied by one or more nodes. 可以在“State Configuration (DSC)” 页中查看自动化帐户中的节点配置。You can view the node configurations in your Automation account in the State configuration (DSC) page. 节点配置的名称格式为 ConfigurationName.NodeNameA node configuration has a name with the form ConfigurationName.NodeName.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”边栏选项卡上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account blade, click State configuration (DSC) under Configuration Management.

  4. 在“State configuration (DSC)”页上,单击“编译的配置”选项卡。 On the State configuration (DSC) page, click the Compiled configurations tab.

    “编译的配置”选项卡屏幕截图

加入使用 Azure Automation State Configuration 管理的 Azure VMOnboarding an Azure VM for management with Azure Automation State Configuration

可以使用 Azure 自动化状态配置来管理 Azure VM(包括经典 VM 和资源管理器 VM)、本地 VM、Linux 计算机、AWS VM,以及本地物理机。You can use Azure Automation State Configuration to manage Azure VMs (both Classic and Resource Manager), on-premises VMs, Linux machines, AWS VMs, and on-premises physical machines. 本文介绍如何仅登记 Azure 资源管理器 VM。In this article, you learn how to onboard only Azure Resource Manager VMs. 有关加入其他类型的计算机的信息,请参阅加入由 Azure 自动化状态配置管理的计算机For information about onboarding other types of machines, see Onboarding machines for management by Azure Automation State Configuration.

加入由 Azure Automation State Configuration 管理的 Azure 资源管理器 VMTo onboard an Azure Resource Manager VM for management by Azure Automation State Configuration

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”边栏选项卡上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account blade, click State configuration (DSC) under Configuration Management.

  4. 在“State Configuration (DSC)”页上的“节点”选项卡中,单击“+ 添加”。 On the State configuration (DSC) page, while on the Nodes tab, click + Add.

    “DSC 节点”页的屏幕截图,其中突出显示“添加 Azure VM”按钮

  5. 在“虚拟机”页上,选择自己的 VM。 On the Virtual Machines page, select your VM.

  6. 在“虚拟机”详细信息页上,单击“+ 连接”。 On the Virtual machine detail page, click + Connect.

    Important

    此 VM 必须是运行支持的操作系统的 Azure 资源管理器 VM。This must be an Azure Resource Manager VM running a supported operating system.

  7. 在“注册” 页上的“节点配置名称” 框中,选择要应用到 VM 的节点配置的名称。In the Registration page, select the name of the node configuration you want to apply to the VM in the Node configuration name box. 可以选择在此时提供名称。Providing a name at this point is optional. 可以在登记节点以后更改分配的节点配置。You can change the assigned node configuration after onboarding the node. 选中“根据需要重新启动节点” ,并单击“确定” 。Check Reboot Node if Needed, then click OK.

    “注册”边栏选项卡的屏幕快照

    指定的节点配置将按“配置模式频率” 指定的时间间隔应用到 VM,而 VM 则会按“刷新频率” 指定的时间间隔检查节点配置的更新。The node configuration you specified are applied to the VM at intervals specified by the Configuration Mode Frequency, and the VM checks for updates to the node configuration at intervals specified by the Refresh Frequency. 有关如何使用这些值的详细信息,请参阅配置本地配置管理器For more information about how these values are used, see Configuring the Local Configuration Manager.

Azure 将启动登记 VM 的过程。Azure starts the process of onboarding the VM. 完成后,VM 会显示在自动化帐户的“State Configuration (DSC)”页上的“节点”选项卡中 。When it is complete, the VM shows up in the Nodes tab of the State configuration (DSC) page in the Automation account.

查看托管节点的列表Viewing the list of managed nodes

在“State Configuration (DSC)”页上的“节点”选项卡中,可以查看已在自动化帐户中加入管理的所有计算机的列表 。You can view the list of all machines that have been onboarded for management in your Automation account in the Nodes tab of the State configuration (DSC) page.

  1. 登录到 Azure 门户Sign in to the Azure portal.
  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.
  3. 在“自动化帐户”边栏选项卡上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account blade, click State configuration (DSC) under Configuration Management.
  4. 在“State Configuration (DSC)”页上,单击“节点”选项卡。 On the State configuration (DSC) page, click the Nodes tab.

查看托管节点的报告Viewing reports for managed nodes

每当 Azure Automation State Configuration 在托管节点上执行一致性检查时,该节点会将状态报告发送回拉取服务器。Each time Azure Automation State Configuration performs a consistency check on a managed node, the node sends a status report back to the pull server. 可以在该节点的页上查看这些报告。You can view these reports on the page for that node.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”边栏选项卡上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account blade, click State configuration (DSC) under Configuration Management.

  4. 在“State Configuration (DSC)”页上,单击“节点”选项卡。 在此处,可以查看配置状态的概述,以及每个节点的详细信息。On the State configuration (DSC) page, click the Nodes tab. Here, you can see the overview of Configuration state and the details for each node.

    “节点”页的屏幕截图

  5. 在“节点”选项卡上,单击节点记录打开报告。 While on the Nodes tab, click the node record to open the reporting. 单击要在其中查看其他报告详细信息的报告。Click the report you want to view additional reporting details.

    “报告”边栏选项卡的屏幕快照

在单个报告的边栏选项卡中,可以看到对应的一致性检查的下列状态信息:On the blade for an individual report, you can see the following status information for the corresponding consistency check:

  • 报告状态 - 节点是否“合规”、配置是否“失败”、节点是否“不合规”(当节点处于 ApplyandMonitor 模式且计算机不在所需状态时)。The report status — whether the node is "Compliant", the configuration "Failed", or the node is "Not Compliant" (when the node is in ApplyandMonitor mode and the machine is not in the desired state).
  • 一致性检查的开始时间。The start time for the consistency check.
  • 一致性检查的总运行时间。The total runtime for the consistency check.
  • 一致性检查的类型。The type of consistency check.
  • 任何错误,包括错误代码和错误消息。Any errors, including the error code and error message.
  • 在配置中使用的任何 DSC 资源,以及每个资源的状态(节点是否处于该资源的期望状态)- 可以单击每个资源以获取该资源的更多详细信息。Any DSC resources used in the configuration, and the state of each resource (whether the node is in the desired state for that resource) — you can click on each resource to get more detailed information for that resource.
  • 节点的名称、IP 地址和配置模式。The name, IP address, and configuration mode of the node.

还可以通过单击“查看原始报告” 来查看节点发送到服务器的实际数据。You can also click View raw report to see the actual data that the node sends to the server. 有关如何使用该数据的详细信息,请参阅使用 DSC 报表服务器For more information about using that data, see Using a DSC report server.

在登记节点以后,可能需要一段时间才会提供第一个报告。It can take some time after a node is onboarded before the first report is available. 在登记节点以后,可能需要等待长达 30 分钟的时间才能获得第一个报告。You might need to wait up to 30 minutes for the first report after you onboard a node.

为节点重新分配其他节点配置Reassigning a node to a different node configuration

为节点分配配置时,可以让其使用不同于初始配置的节点配置。You can assign a node to use a different node configuration than the one you initially assigned.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”边栏选项卡上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account blade, click State configuration (DSC) under Configuration Management.

  4. 在“State Configuration (DSC)”页上,单击“节点”选项卡。 On the State configuration (DSC) page, click the Nodes tab.

  5. 在“节点”选项卡中,单击要重新分配的节点的名称 。On the Nodes tab, click on the name of the node you want to reassign.

  6. 在该节点的页面上,单击“分配节点配置” 。On the page for that node, click Assign node configuration.

    “节点详细信息”页的屏幕截图,其中突出显示了“分配节点配置”按钮

  7. 在“分配节点配置” 页中,选择要向其分配节点的节点配置,并单击“确定” 。On the Assign Node Configuration page, select the node configuration to which you want to assign the node, and then click OK.

    “分配节点配置”页面的屏幕截图

注销节点Unregistering a node

如果不想让某个节点继续受 Azure Automation DSC 管理,则可注销该节点。If you no longer want a node to be managed by Azure Automation DSC, you can unregister it.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在左侧,单击“所有资源” ,并单击自动化帐户的名称。On the left, click All resources and then the name of your Automation account.

  3. 在“自动化帐户”边栏选项卡上的“配置管理”下,单击“State configuration (DSC)”。 On the Automation account blade, click State configuration (DSC) under Configuration Management.

  4. 在“State Configuration (DSC)”页上,单击“节点”选项卡。 On the State configuration (DSC) page, click the Nodes tab.

  5. 在“节点”选项卡上,单击要注销的节点的名称 。On the Nodes tab, click on the name of the node you want to unregister.

  6. 在该节点的页中,单击“注销” 。On the page for that node, click Unregister.

    “节点详细信息”页的屏幕截图,其中突出显示了“注销”按钮