VPS Windows bị chậm hoặc đầy disk là vấn đề thường gặp. Bài này hướng dẫn cách chẩn đoán và xử lý nhanh.
==== VPS BỊ CHẬM ====
Bước 1: Xác định nguyên nhân
# Xem process ngốn CPU nhiều nhất
Get-Process | Sort-Object CPU -Descending | Select-Object Name, CPU, WorkingSet | Select-Object -First 15 | Format-Table
# Xem process ngốn RAM
Get-Process | Sort-Object WorkingSet -Descending | Select-Object Name, @{N="RAM(MB)";E={[math]::Round($_.WorkingSet/1MB,1)}} | Select-Object -First 15
# Xem CPU tổng
Get-Counter "\Processor(_Total)\% Processor Time" -SampleInterval 2 -MaxSamples 5
# Xem disk I/O
Get-Counter "\PhysicalDisk(_Total)\Disk Transfers/sec" -SampleInterval 2 -MaxSamples 3
Bước 2: Kill process ngốn tài nguyên
# Kill process theo tên
Stop-Process -Name "ProcessName" -Force
# Kill theo PID
Stop-Process -Id 1234 -Force
# Kill tất cả instance của 1 app
Get-Process "chrome" | Stop-Process -Force
Bước 3: Kiểm tra service lạ
# Xem tất cả service đang chạy
Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object Name, DisplayName | Sort-Object Name
# Xem service ngốn CPU (qua Task Manager hoặc)
Get-WmiObject Win32_Service | Where-Object {$_.State -eq "Running"} | Select-Object Name, ProcessId | ForEach-Object {
$proc = Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue
if ($proc) { [PSCustomObject]@{Name=$_.Name; CPU=$proc.CPU; PID=$_.ProcessId} }
} | Sort-Object CPU -Descending | Select-Object -First 10
Bước 4: Dọn RAM — tắt startup programs
# Xem chương trình tự khởi động
Get-CimInstance Win32_StartupCommand | Select-Object Name, Command, Location | Format-Table -AutoSize
# Tắt qua Task Manager: Ctrl+Shift+Esc → Startup tab → Disable những gì không cần
Bước 5: Kiểm tra Windows Update đang chạy nền
Get-Service wuauserv
# Nếu đang update → đợi xong hoặc tạm dừng
Stop-Service wuauserv
Set-Service wuauserv -StartupType Manual
==== VPS BỊ ĐẦY DISK ====
Bước 1: Xem dung lượng từng ổ
Get-PSDrive | Where-Object {$_.Used -gt 0} | Select-Object Name, @{N="Used(GB)";E={[math]::Round($_.Used/1GB,1)}}, @{N="Free(GB)";E={[math]::Round($_.Free/1GB,1)}} | Format-Table
Bước 2: Tìm thư mục chiếm nhiều dung lượng nhất
# Xem thư mục lớn nhất trong C:\
Get-ChildItem C:\ -Directory | ForEach-Object {
$size = (Get-ChildItem $_.FullName -Recurse -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum
[PSCustomObject]@{Folder=$_.Name; "Size(GB)"=[math]::Round($size/1GB,2)}
} | Sort-Object "Size(GB)" -Descending | Select-Object -First 10
Bước 3: Dọn Temp files
# Xóa temp files
Remove-Item "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
# Xóa Prefetch
Remove-Item "C:\Windows\Prefetch\*" -Force -ErrorAction SilentlyContinue
# Xóa thumbnail cache
Remove-Item "$env:LOCALAPPDATA\Microsoft\Windows\Explorer\thumbcache_*.db" -Force -ErrorAction SilentlyContinue
Bước 4: Dọn Windows Update cache
Stop-Service wuauserv -Force
Remove-Item "C:\Windows\SoftwareDistribution\Download\*" -Recurse -Force -ErrorAction SilentlyContinue
Start-Service wuauserv
Write-Host "Done! Check size:"
(Get-ChildItem "C:\Windows\SoftwareDistribution" -Recurse -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum / 1GB
Bước 5: Chạy Disk Cleanup
# Tự động dọn tất cả
cleanmgr /sagerun:65535
# Hoặc dọn system files (cần admin)
cleanmgr /sageset:65535
cleanmgr /sagerun:65535
Bước 6: Xóa log IIS cũ
# Xem log IIS
Get-ChildItem "C:\inetpub\logs" -Recurse | Sort-Object Length -Descending | Select-Object -First 10 | Format-Table Name, @{N="Size(MB)";E={[math]::Round($_.Length/1MB,1)}}, LastWriteTime
# Xóa log cũ hơn 30 ngày
Get-ChildItem "C:\inetpub\logs" -Recurse -File | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Remove-Item -Force
Bước 7: Xóa file dump/crash
Remove-Item "C:\Windows\Minidump\*" -Force -ErrorAction SilentlyContinue
Remove-Item "C:\Windows\memory.dmp" -Force -ErrorAction SilentlyContinue
Bước 8: Tìm file lớn
# Tìm file lớn hơn 500MB
Get-ChildItem C:\ -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 500MB} | Select-Object FullName, @{N="Size(GB)";E={[math]::Round($_.Length/1GB,2)}} | Sort-Object "Size(GB)" -Descending
Bước 9: Compact OS (nén hệ điều hành, tiết kiệm 1-2GB)
# Chạy trong CMD với quyền Admin
compact /compactos:always
Bước 10: Mở rộng disk C: nếu đã nâng cấp
Sau khi nâng cấp disk trên Virtualizor panel:
1. Mở Disk Management: diskmgmt.msc
2. Chuột phải vào ổ C: → Extend Volume
3. Next → nhập dung lượng muốn thêm → Next → Finish
Hoặc dùng DiskPart:
diskpart
list volume
select volume 0 # chọn volume C:
extend # mở rộng hết không gian còn lại
exit