Script Test Tốc Độ Server
Công cụ kiểm tra hiệu năng server và tốc độ mạng với một câu lệnh đơn giản.
Tính năng
Thông tin hệ thống
- CPU model, số cores, tốc độ
- RAM tổng và đã sử dụng
- Dung lượng ổ đĩa
- Phiên bản OS, kernel
- Uptime và load average
Test tốc độ ổ đĩa
- Sequential write với
dd - Random I/O với
fio(nếu có) - IOPS read/write
Test tốc độ mạng
- Download speed từ nhiều locations
- Latency test (ping)
- Kiểm tra kết nối các CDN nodes
Cách sử dụng
Linux / macOS
curl -Lso- bacpv.com/speedtest.sh | bash
Hoặc tải về và chạy:
curl -O https://bacpv.com/speedtest.sh
chmod +x speedtest.sh
./speedtest.sh
Windows PowerShell
Chạy trực tiếp:
Invoke-Expression (Invoke-WebRequest -Uri "https://bacpv.com/speedtest.ps1" -UseBasicParsing).Content
Viết tắt:
iwr https://bacpv.com/speedtest.ps1 | iex
Tải về và chạy:
Invoke-WebRequest -Uri "https://bacpv.com/speedtest.ps1" -OutFile speedtest.ps1
.\speedtest.ps1
Yêu cầu PowerShell
Script yêu cầu PowerShell 5.0 trở lên. Chạy $PSVersionTable.PSVersion để kiểm tra phiên bản.
Kết quả mẫu
╔══════════════════════════════════════════════════════════════════╗
║ BacPV Server Speedtest ║
╚══════════════════════════════════════════════════════════════════╝
═══════════════════════════════════════════════════════════════════
System Information
═══════════════════════════════════════════════════════════════════
CPU Model: Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
CPU Cores: 8
Total RAM: 16.0 GB
Used RAM: 4.2 GB
Total Disk: 100.0 GB
Used Disk: 25.5 GB (25%)
Operating System: Ubuntu 22.04.5 LTS
Kernel: 5.15.0-161-generic
Architecture: x86_64
Uptime: 15 days, 4 hours, 23 minutes
Load Average: 0.15, 0.08, 0.05
═══════════════════════════════════════════════════════════════════
Disk Speed Test
═══════════════════════════════════════════════════════════════════
Sequential Write (dd):
Run 1: 425 MB/s
Run 2: 438 MB/s
Run 3: 442 MB/s
═══════════════════════════════════════════════════════════════════
Network Speed Test
═══════════════════════════════════════════════════════════════════
Server IP Address Speed
─────────────────────────────────────────────────────────────────
BacPV Test Server 103.x.x.x 45.20 MB/s
CloudFlare CDN 104.16.x.x 89.50 MB/s
Google 142.250.x.x 120.30 MB/s
Latency Test:
Google DNS: 8.5ms
CloudFlare DNS: 5.2ms
Local Gateway: 0.8ms
Cài đặt cho trang web của bạn
1. Chuẩn bị file test
Tạo các file test để đo tốc độ download:
# Tạo file 10MB
dd if=/dev/urandom of=10mb.bin bs=1M count=10
# Tạo file 100MB
dd if=/dev/urandom of=100mb.bin bs=1M count=100
# Tạo file 1GB
dd if=/dev/urandom of=1gb.bin bs=1M count=1024
2. Cấu hình Nginx
Thêm vào file config nginx:
# Speedtest scripts at root
location ~ ^/(speedtest\.(sh|ps1))$ {
alias /path/to/bacpv/build/$1;
add_header Content-Type "text/plain; charset=utf-8";
add_header Access-Control-Allow-Origin "*";
}
# Test files directory
location /files/ {
alias /path/to/bacpv/build/files/;
autoindex on;
# Disable caching cho file test
location ~* \.(bin|test)$ {
add_header Cache-Control "no-store, no-cache, must-revalidate";
add_header Access-Control-Allow-Origin "*";
}
}
Reload nginx:
sudo nginx -t
sudo systemctl reload nginx
3. Tùy chỉnh script
Download script mẫu:
curl -O https://bacpv.com/speedtest.sh
curl -O https://bacpv.com/speedtest.ps1
Sửa URL trong script:
# Trong speedtest.sh
BASE_URL="https://yourdomain.com/files"
# Trong speedtest.ps1
$BaseURL = "https://yourdomain.com/files"
4. Deploy automation
Sử dụng script tự động:
cd static/speedtest
chmod +x deploy.sh
bash deploy.sh
Script sẽ tự động:
- Tạo file test
- Build Docusaurus
- Copy files vào thư mục build
- Generate nginx config
- Tạo hướng dẫn sử dụng
Lưu ý bảo mật
Rate Limiting
Thêm rate limiting để tránh abuse:
# Trong http block
limit_req_zone $binary_remote_addr zone=speedtest:10m rate=10r/m;
# Trong location block
location ~ ^/(speedtest\.(sh|ps1))$ {
limit_req zone=speedtest burst=5;
# ... các config khác
}
Monitor bandwidth
# Cài đặt vnstat
sudo apt install vnstat
# Monitor real-time
vnstat -l -i eth0
# Xem thống kê
vnstat -h
Fail2ban (optional)
Tạo filter để block IP abuse:
sudo nano /etc/fail2ban/filter.d/speedtest.conf
[Definition]
failregex = ^<HOST> .* "GET /speedtest/.*\.bin
ignoreregex =
sudo nano /etc/fail2ban/jail.local
[speedtest]
enabled = true
port = http,https
filter = speedtest
logpath = /var/log/nginx/access.log
maxretry = 20
findtime = 3600
bantime = 86400
Source Code
- speedtest.sh - Script cho Linux
- speedtest.ps1 - Script cho Windows
- GitHub Repository - Full source code
Công cụ tương tự
- tocdo.net - Script gốc (Vietnamese)
- bench.sh - Server benchmark
- speedtest-cli - Ookla Speedtest CLI
- LibreSpeed - Self-hosted HTML5 speedtest
- iPerf3 - Network performance tool
Hỗ trợ
Nếu gặp vấn đề hoặc cần tùy chỉnh, liên hệ qua trang liên hệ.