Bagikan melalui


Mengonfigurasi komputer ke kondisi yang diinginkan

Catatan

Konfigurasi Status Azure Automation akan dihentikan pada 30 September 2027, silakan transisi ke Konfigurasi Komputer Azure pada tanggal tersebut. Untuk informasi selengkapnya, lihat pengumuman posting blog. Layanan Azure Machine Configuration menggabungkan fitur Ekstensi DSC, Konfigurasi Status Azure Automation, dan fitur yang paling umum diminta dari umpan balik pelanggan. Azure Machine Configuration juga menyertakan dukungan komputer hibrid melalui server yang didukung Arc.

Azure Automation State Configuration. memungkinkan Anda menentukan konfigurasi untuk server Anda dan memastikan bahwa server tersebut berada dalam keadaan yang ditentukan dari waktu ke waktu.

  • Mengintegrasikan komputer virtual yang akan dikelola oleh Azure Automation DSC
  • Mengunggah konfigurasi ke Azure Automation
  • Mengompilasi konfigurasi menjadi konfigurasi simpul
  • Menetapkan konfigurasi simpul ke simpul terkelola
  • Memeriksa status kepatuhan dari simpul yang dikelola

Untuk tutorial ini, kami menggunakan konfigurasi DSC sederhana yang memastikan bahwa IIS diinstal pada komputer virtual.

Prasyarat

Dukungan untuk konfigurasi parsial

Azure Automation State Configuration mendukung penggunaan konfigurasi parsial. Dalam skenario ini, DSC dikonfigurasi untuk mengelola beberapa konfigurasi secara independen dan setiap konfigurasi diambil dari Azure Automation. Namun, hanya satu konfigurasi yang dapat ditetapkan ke simpul per akun automation. Ini berarti jika Anda menggunakan dua konfigurasi untuk simpul, Anda memerlukan dua akun Automation.

Untuk detail tentang cara mendaftarkan konfigurasi parsial dari layanan tarik, lihat dokumentasi untuk konfigurasi parsial.

Untuk informasi selengkapnya tentang bagaimana tim dapat bekerja sama untuk mengelola server secara kolaboratif menggunakan konfigurasi sebagai kode, lihat Memahami peran DSC dalam Alur CI/CD.

Masuk ke Azure

Masuk ke langganan Azure Anda dengan cmdlet Connect-AzAccount dan ikuti petunjuk di layar.

Connect-AzAccount

Membuat dan mengunggah konfigurasi ke Azure Automation

Dalam editor teks, ketik berikut ini dan simpan secara lokal sebagai TestConfig.ps1.

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

Catatan

Nama konfigurasi di Azure Automation harus dibatasi hingga tidak lebih dari 100 karakter.

Dalam skenario lebih lanjut yang memerlukan beberapa modul untuk diimpor yang menyediakan Sumber Daya DSC, pastikan setiap modul memiliki baris Import-DscResource unik dalam konfigurasi Anda.

Panggil cmdlet Import-AzAutomationDscConfiguration untuk mengunggah konfigurasi ke akun Automation Anda.

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

Mengompilasi konfigurasi menjadi konfigurasi simpul

Konfigurasi DSC harus dikompilasi ke dalam konfigurasi simpul sebelum dapat ditetapkan ke sebuah simpul. Lihat Konfigurasi DSC.

Panggil cmdlet Start-AzAutomationDscCompilationJob untuk mengompilasi TestConfig konfigurasi menjadi konfigurasi simpul bernama TestConfig.WebServer di akun Automation Anda.

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

Mendaftarkan komputer virtual untuk dikelola oleh Konfigurasi Status

Anda dapat menggunakan Azure Automation Konfigurasi Status untuk mengelola komputer virtual Azure (Klasik dan Resource Manager), komputer virtual lokal, komputer Linux, komputer virtual AWS, dan komputer fisik lokal. Dalam artikel ini, kami membahas cara mendaftarkan hanya VM Azure Resource Manager. Untuk informasi tentang mendaftarkan jenis komputer lain, lihat Onboarding komputer untuk pengelolaan menurut Azure Automation State Configuration.

Panggil cmdlet Register-AzAutomationDscNode untuk mendaftarkan komputer virtual Anda dengan Azure Automation State Configuration sebagai simpul terkelola.

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

Menentukan pengaturan mode konfigurasi

Gunakan cmdlet Register-AzAutomationDscNode untuk mendaftarkan komputer virtual sebagai simpul terkelola dan menentukan properti konfigurasi. Misalnya, Anda dapat menentukan bahwa status komputer akan diterapkan hanya sekali dengan menentukan ApplyOnly sebagai nilai properti ConfigurationMode. State Configuration tidak mencoba menerapkan konfigurasi setelah pemeriksaan awal.

$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

Ini akan menetapkan konfigurasi simpul bernama TestConfig.WebServer ke node DSC DscVm yang terdaftar. Secara default, simpul DSC akan diperiksa kepatuhannya dengan konfigurasi simpul setiap 30 menit. Untuk informasi tentang cara mengubah interval pemeriksaan kepatuhan, lihat Mengonfigurasi Microsoft Endpoint Configuration Manager Lokal.

Memeriksa status kepatuhan dari simpul yang dikelola

Anda dapat memperoleh laporan tentang status kepatuhan dari simpul terkelola menggunakan cmdlet Get-AzAutomationDscNodeReport.

# 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]

Langkah berikutnya