✅ 一键防CPU被压死防护脚本(管理员PowerShell运行)

✅ 一键防CPU被压死防护脚本(管理员PowerShell运行)

1777706067337

 

Write-Host "正在配置服务器防CPU压死防护..." -ForegroundColor Cyan;
# 1. 开启系统CPU资源保护,限制单进程CPU占用
New-Item -Path "HKLM:SYSTEMCurrentControlSetControlSession ManagerPower" -Force | New-ItemProperty -Name HiberbootEnabled -Value 0 -PropertyType DWord -Force;
New-Item -Path "HKLM:SYSTEMCurrentControlSetServicesProcessorParameters" -Force | New-ItemProperty -Name DisableIdleStates -Value 1 -PropertyType DWord -Force;
# 2. 限制Nginx/PHP进程CPU占用上限(防止恶意请求吃满CPU)
New-Item -Path "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsnginx.exePerfOptions" -Force | New-ItemProperty -Name CpuPriorityClass -Value 4 -PropertyType DWord -Force;
New-Item -Path "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsphp-cgi.exePerfOptions" -Force | New-ItemProperty -Name CpuPriorityClass -Value 4 -PropertyType DWord -Force;
# 3. 开启CPU节流保护,高负载时自动限制非核心进程
New-Item -Path "HKLM:SYSTEMCurrentControlSetControlPowerPowerSettings54533251-82be-4824-96c1-4b7fc84815f8cc5b647-c1df-4637-891a-dec35c318583" -Force | New-ItemProperty -Name Attributes -Value 2 -PropertyType DWord -Force;
# 4. 禁用系统后台CPU占用服务
Stop-Service -Name "WSearch", "SysMain", "wuauserv" -Force -ErrorAction SilentlyContinue; Set-Service -Name "WSearch", "SysMain", "wuauserv" -StartupType Disabled -ErrorAction SilentlyContinue;
# 5. 开启自动CPU守护,高负载时清理闲置进程
schtasks /Create /TN "AutoCpuGuard" /TR "powershell.exe -Command "Get-Process | Where-Object {$_.Cpu -gt 50 -and $_.Name -notin ('nginx','php-cgi','mysql','System')} | Stop-Process -Force -ErrorAction SilentlyContinue"" /SC MINUTE /MO 1 /RL HIGHEST /F >nul 2>&1;
Write-Host "✅ 防CPU压死防护配置完成!高负载下CPU也不会被吃满" -ForegroundColor Green

✅ 一键防CPU被压死防护脚本(管理员PowerShell运行)

© 版权声明
THE END
喜欢就支持一下吧
点赞148W+ 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容