使用 PowerShell 設定伺服器的 應用程式集區 預設值
ForEach ($sComputer in $global:aComputers)
{
# Sets Application Pool Configuration
Write-Host "Setting Application Pool Configuration $sComputer..."; Start-Timer
Write-Host " 1. 啟動模式 由 OnDemand => AlwaysRunning."
set-webconfigurationproperty /system.applicationHost/applicationPools/applicationPoolDefaults -name startMode -value 1
Write-Host " 2. 佇列長度改為5000."
set-webconfigurationproperty /system.applicationHost/applicationPools/applicationPoolDefaults -name queueLength -value 5000
Write-Host " 3. 停用 Idle Time 設定 (20 分鐘) => 改為 0"
set-webconfigurationproperty /system.applicationHost/applicationPools/applicationPoolDefaults/processModel -name idleTimeout -value (New-TimeSpan -h 00 -m 00)
Write-Host " 4. 停用預設的固定時間區間回收機制 (1740 分鐘) => 改為 0"
set-webconfigurationproperty /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart -name time -value (New-TimeSpan -h 00 -m 00)
Write-Host " 5. 設定固定的時間回收(例如: 04:00) => 設定為離峰時間, 同一個 Farm 的機器的時間要不同, 如: WEB01 為 4:00, WEB02 為 4:10."
add-webconfiguration /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule -value (New-TimeSpan -h 4 -m 10)
Write-Host " 6. 將所有 Application pool 回收事件寫入系統事件"
set-webconfigurationproperty '/system.applicationHost/applicationPools/applicationPoolDefaults' -PSPath IIS:\ -Name recycling.logEventOnRecycle -Value "Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory"
Write-Host "Done! [$(Stop-Timer)]"
}
Write-Host 'Done!'