✅ 一键防内存被攻击爆满防护脚本(管理员PowerShell直接运行)

Write-Host "正在配置服务器防内存爆满防护..." -ForegroundColor Cyan;
# 1. 开启系统低内存保护,强制优先释放闲置内存
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Force | New-ItemProperty -Name LowMemoryThreshold -Value 512 -PropertyType DWord -Force;
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" -Force | New-ItemProperty -Name DisablePagingExecutive -Value 1 -PropertyType DWord -Force;
# 2. 限制单进程最大内存占用(防止恶意进程吃爆内存)
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\php-cgi.exe\PerfOptions" -Force | New-ItemProperty -Name CpuPriorityClass -Value 4 -PropertyType DWord -Force;
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\nginx.exe\PerfOptions" -Force | New-ItemProperty -Name CpuPriorityClass -Value 4 -PropertyType DWord -Force;
# 3. 开启自动内存保护,内存低于20%时强制释放
schtasks /Create /TN "AutoMemoryGuard" /TR "powershell.exe -Command \"Get-Process | Where-Object {$_.WorkingSet64 -gt 0} | ForEach-Object {try{$_.MinWorkingSet=$_.WorkingSet64;$_.MaxWorkingSet=$_.WorkingSet64}catch{}}; wmic memorycache delete 2>&1 | Out-Null\"" /SC MINUTE /MO 5 /RL HIGHEST /F >nul 2>&1;
# 4. 关闭系统内存自动膨胀功能
New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\SysMain\Parameters" -Force | New-ItemProperty -Name NoSuperfetch -Value 1 -PropertyType DWord -Force;
Write-Host "✅ 防内存爆满防护配置完成!网站访问不受影响" -ForegroundColor Green
✅ 一键防内存被攻击爆满防护脚本(管理员PowerShell直接运行)
© 版权声明
THE END
暂无评论内容