| 項目 | 建議值 | 理由 |
|---|---|---|
| 最佳時段 | 凌晨 03:00 ~ 04:00(如 03:33) | 業務流量最低、無排程任務衝突、避開 Windows Update 預設安裝時段 |
| 建議頻率 | 每月 1 次 | 釋放記憶體碎片、清理暫存檔、重置網路連線池、套用核心更新需重啟 |
| 避開時段 | Windows Update 自動安裝時段(預設 03:00) | 若啟用自動更新,請錯開 30 分鐘以上,避免更新未完成即被強制重啟 |
Monthly Server Reboot,描述:每月凌晨自動重啟釋放資源。C:\Windows\System32\shutdown.exe-r -f -t 60 -c "Scheduled monthly reboot for maintenance"
-r:重啟-f:強制關閉應用程式-t 60:60 秒倒數(給使用者儲存機會)-c:註解訊息$action = New-ScheduledTaskAction -Execute "C:\Windows\System32\shutdown.exe" -Argument "-r -f -t 60 -c 'Monthly maintenance reboot'" $trigger = New-ScheduledTaskTrigger -Monthly -DaysOfMonth 1 -At 3:33am $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd Register-ScheduledTask -TaskName "MonthlyServerReboot" -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest -Force
@echo off set LOG=C:\Logs\server_reboot_%date:~,4%%date:~5,2%%date:~8,2%.log echo [%date% %time%] Initiating scheduled reboot... >> %LOG% net stop "World Wide Web Publishing Service" >> %LOG% 2>&1 net stop "SQL Server (MSSQLSERVER)" >> %LOG% 2>&1 timeout /t 30 shutdown -r -f -t 30 -c "Scheduled maintenance reboot" echo [%date% %time%] Reboot command sent. >> %LOG%
將上述存為 C:\Scripts\reboot_monthly.bat,排程器呼叫此批次檔即可。
「每月一次、凌晨三點半、shutdown -r -f」是簡單可靠的伺服器維護節奏。搭配服務優雅停止腳本與日誌記錄,能最大程度減少業務影響,保持系統長期穩定運行。