Freigeben über


Konfigurieren Sie Maschinen auf einen gewünschten Zustand

Hinweis

Azure Automation State Configuration wird am 30. September 2027 eingestellt, bitte wechseln Sie zu Azure Computerkonfiguration bis zu diesem Datum. Weitere Informationen finden Sie in der Blogpost-Ankündigung. Der Azure Computerkonfigurationsdienst kombiniert Features der DSC-Erweiterung, Azure Automation State Configuration und die am häufigsten angeforderten Features aus Kundenfeedback. Azure Computerkonfiguration umfasst auch hybride Computerunterstützung über Arc-fähige Server.

Wichtig

Die Navigationslinks Hinzufügen, Konfiguration erstellen und Katalog werden am 31. März 2025 aus dem Portal entfernt.

Achtung

Azure Automation DSC für Linux wurde am 30. September 2023 eingestellt. Weitere Informationen finden Sie in der Ankündigung.

mit Azure Automation State Configuration können Sie Konfigurationen für Ihre Server angeben und sicherstellen, dass sich diese Server im angegebenen Zustand im Laufe der Zeit befinden.

  • Einen virtuellen Computer bei Azure Automation DSC anmelden und verwalten.
  • Hochladen einer Konfiguration in Azure Automation
  • Kompilieren einer Konfiguration in eine Knotenkonfiguration
  • Zuweisen einer Knotenkonfiguration zu einem verwalteten Knoten
  • Überprüfen des Konformitätsstatus eines verwalteten Knotens

Für dieses Tutorial verwenden wir eine einfache DSC-Konfiguration, die sicherstellt, dass IIS auf der VM installiert ist.

Voraussetzungen

Hinweis

Windows Server 2008 und Windows Server 2008 R2 haben das Ende des Supports (EOS) erreicht. Weitere Informationen finden Sie unter End der Unterstützung für Windows Server 2008 und Windows Server 2008 R2 und Perform-Direktes Upgrade auf Windows Server 2016, 2019, 2022 oder 2025. Überprüfen Sie Ihre Nutzung und planen Sie Betriebssystemupgrades und -migrationen entsprechend.

Unterstützung für Teilkonfigurationen

Azure Automation State Configuration unterstützt die Verwendung von partialkonfigurationen. In diesem Szenario ist DSC so konfiguriert, dass mehrere Konfigurationen unabhängig voneinander verwaltet werden, und jede Konfiguration wird aus Azure Automation abgerufen. Einem Knoten kann jedoch nur eine Konfiguration über ein Automatisierungskonto zugewiesen werden. Dies bedeutet, dass Sie bei Verwendung von zwei Konfigurationen für einen Knoten zwei Automation-Kontos benötigen.

Ausführliche Informationen zum Registrieren einer Teilkonfiguration aus einem Pulldienst finden Sie in der Dokumentation zu Teilkonfigurationen.

Weitere Informationen dazu, wie Teams zusammenarbeiten können, um Server gemeinsam mithilfe von Konfiguration als Code zu verwalten, finden Sie unter Grundlegendes zu DSCs Rolle in einer CI/CD-Pipeline.

Anmelden bei Azure

Melden Sie sich mit dem Cmdlet Connect-AzAccount bei Ihrem Azure-Abonnement an, und folgen Sie den Anweisungen auf dem Bildschirm.

Connect-AzAccount

Erstellen und Hochladen einer Konfiguration in Azure Automation

Geben Sie in einem Texteditor Folgendes ein, und speichern Sie die Datei lokal als TestConfig.ps1.

configuration TestConfig {
   Node WebServer {
      WindowsFeature IIS {
         Ensure               = 'Present'
         Name                 = 'Web-Server'
         IncludeAllSubFeature = $true
      }
   }
}

Hinweis

Konfigurationsnamen in Azure Automation dürfen nicht mehr als 100 Zeichen lang sein.

In komplexeren Szenarien, in denen mehrere Module importiert werden müssen, die DSC-Ressourcen bereitstellen, müssen Sie sicherstellen, dass jedes Modul über eine eindeutige Zeile vom Typ Import-DscResource in Ihrer Konfiguration verfügt.

Rufen Sie das Cmdlet Import-AzAutomationDscConfiguration auf, um die Konfiguration in Ihr Automation-Konto hochzuladen.

$importAzAutomationDscConfigurationSplat = @{
    SourcePath = 'C:\DscConfigs\TestConfig.ps1'
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    Published = $true
}
Import-AzAutomationDscConfiguration @importAzAutomationDscConfigurationSplat

Kompilieren einer Konfiguration in eine Knotenkonfiguration

Eine DSC-Konfiguration muss in eine Knotenkonfiguration kompiliert werden, bevor sie einem Knoten zugewiesen werden kann. Weitere Informationen finden Sie unter DSC-Konfigurationen.

Rufen Sie das Cmdlet Start-AzAutomationDscCompilationJob auf, um die TestConfig-Konfiguration in eine Knotenkonfiguration namens TestConfig.WebServer in Ihrem Automation-Konto zu kompilieren.

$startAzAutomationDscCompilationJobSplat = @{
    ConfigurationName = 'TestConfig'
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
}
Start-AzAutomationDscCompilationJob @startAzAutomationDscCompilationJobSplat

Registrieren eines virtuellen Computers, der von State Configuration verwaltet werden soll

Sie können Azure Automation State Configuration verwenden, um Azure VMs (sowohl classic als auch Resource Manager), lokale VMs, Linux-Computer, AWS-VMs und lokale physische Computer zu verwalten. In diesem Artikel wird erläutert, wie nur Azure Resource Manager VMs registriert werden. Informationen zum Registrieren anderer Computertypen finden Sie unter Integrieren von Computern für die Verwaltung durch die Azure Automation-Zustandskonfiguration.

Rufen Sie das Cmdlet Register-AzAutomationDscNode auf, um Ihren virtuellen Computer mit Azure Automation State Configuration als verwalteten Knoten zu registrieren.

$registerAzAutomationDscNodeSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    AzureVMName = 'DscVm'
}
Register-AzAutomationDscNode @registerAzAutomationDscNodeSplat

Angeben der Konfigurationsmoduseinstellungen

Verwenden Sie das Cmdlet Register-AzAutomationDscNode, um einen virtuellen Computer als verwalteten Knoten zu registrieren und Konfigurationseigenschaften anzugeben. Sie können z. B. festlegen, dass der Zustand des Computers nur einmalig angewendet werden soll, indem Sie ApplyOnly als Wert der ConfigurationMode-Eigenschaft angeben. State Configuration versucht nicht, die Konfiguration nach der ersten Überprüfung anzuwenden.

$registerAzAutomationDscNodeSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    AzureVMName = 'DscVm'
    ConfigurationMode = 'ApplyOnly'
}
Register-AzAutomationDscNode @registerAzAutomationDscNodeSplat```

You can also specify how often DSC checks the configuration state by using the
`ConfigurationModeFrequencyMins` property. For more information about DSC configuration settings,
see [Configuring the Local Configuration Manager][05].

```powershell
# Run a DSC check every 60 minutes
$registerAzAutomationDscNodeSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    AzureVMName = 'DscVm'
    ConfigurationModeFrequencyMins = 60
}
Register-AzAutomationDscNode @registerAzAutomationDscNodeSplat```

## Assign a node configuration to a managed node

Now we can assign the compiled node configuration to the VM we want to configure.

```powershell
# Get the ID of the DSC node
$getAzAutomationDscNodeSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    Name = 'DscVm'
}
$node = Get-AzAutomationDscNode @getAzAutomationDscNodeSplat

# Assign the node configuration to the DSC node
$setAzAutomationDscNodeSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    NodeConfigurationName = 'TestConfig.WebServer'
    NodeId = $node.Id
}
Set-AzAutomationDscNode @setAzAutomationDscNodeSplat

Damit wird dem registrierten DSC-Knoten TestConfig.WebServer die Knotenkonfiguration namens DscVm zugeordnet. Standardmäßig wird der DSC-Knoten alle 30 Minuten auf Konformität mit der Knotenkonfiguration geprüft. Informationen zum Ändern des Complianceüberprüfungsintervalls finden Sie unter Configuring the Local Konfigurations-Manager.

Überprüfen des Konformitätsstatus eines verwalteten Knotens

Sie können Berichte zum Compliancestatus eines verwalteten Knotens abrufen, indem Sie das Cmdlet Get-AzAutomationDscNodeReport verwenden.

# Get the ID of the DSC node
$getAzAutomationDscNodeSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    Name = 'DscVm'
}
$node = Get-AzAutomationDscNode @getAzAutomationDscNodeSplat

# Get an array of status reports for the DSC node
$getAzAutomationDscNodeReportSplat = @{
    ResourceGroupName = 'MyResourceGroup'
    AutomationAccountName = 'myAutomationAccount'
    NodeId = $node.Id
}
$reports = Get-AzAutomationDscNodeReport @getAzAutomationDscNodeReportSplat

# Display the most recent report
$reports[0]

Nächste Schritte