增加vps-xray部署自建vpn

This commit is contained in:
2026-04-08 15:06:33 +08:00
parent 889f977dc7
commit e0d8c09bb9
4 changed files with 703 additions and 0 deletions

239
vps-xray/vps-xray-fast.md Normal file
View File

@@ -0,0 +1,239 @@
# VPS 一键部署 Xray VLESS TCP极速方案
> 纯 VLESS + TCP无 TLS 加密开销,追求最大传输速度。
---
## 〇、推荐配置
### 系统
| 系统 | 推荐 | 说明 |
|------|-----|------|
| **Debian 12** | ⭐ 首选 | 内核新6.1+,原生 BBR、资源占用最低、Xray 兼容性最好 |
| Ubuntu 22.04 / 24.04 | 可用 | 比 Debian 略重snap 占内存 |
| CentOS / AlmaLinux | 不推荐 | 内核旧、防火墙复杂、包管理慢 |
> 优先选 **Debian 12 x86_64 最小安装**,不要装桌面环境。
### VPS 配置
| 项目 | 最低 | 推荐 | 说明 |
|------|------|------|------|
| **CPU** | 1 核 | 1 核 | VLESS TCP 无加密CPU 几乎无负载 |
| **内存** | 256 MB | 512 MB | Xray 内存占用 < 30MB512MB 留余量给系统 |
| **硬盘** | 5 GB | 10 GB | 系统 + Xray 总共约 2GB |
| **带宽** | 200 Mbps | 1 Gbps | 带宽是速度瓶颈,越大越好 |
| **流量** | 500 GB/月 | 1 TB+/月 | 按实际用量选,看视频消耗大 |
| **位置** | — | 日本 / 新加坡 / 美西 | 离你物理距离越近延迟越低 |
### 推荐 VPS 厂商
| 厂商 | 最低价 | 特点 |
|------|--------|------|
| **Vultr** | $3.5/月 | 按小时计费,随时删机换 IP机房多 |
| **Bandwagon (搬瓦工)** | $49.99/年 | CN2 GIA 线路,国内直连速度快 |
| **RackNerd** | $10.98/年 | 性价比极高,适合轻度使用 |
| **DMIT** | $6.9/月 | 三网 CN2 GIA / CMIN2延迟低 |
| **Akile** | ¥15/月起 | 中转 / IPLC 专线,速度顶级但贵 |
> **选机关键**:带宽 > 线路 > 位置 > 配置。1 核 512MB 即可跑满千兆带宽。
### 线路优先级(国内访问)
| 线路 | 延迟 | 高峰稳定性 | 价格 |
|------|------|-----------|------|
| IPLC / IEPL 专线 | ★★★★★ | ★★★★★ | 极贵 |
| CN2 GIA (AS4809) | ★★★★ | ★★★★ | 贵 |
| CMIN2 (移动精品) | ★★★★ | ★★★★ | 中等 |
| CN2 GT | ★★★ | ★★★ | 中等 |
| 普通线路 (163) | ★★ | ★★ | 便宜 |
---
## 一、一键部署脚本
SSH 登录 VPS 后,复制下面**整段**以 root 运行:
```bash
#!/bin/bash
set -e
# ==================== 安装 Xray ====================
bash <(curl -fsSL https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh)
# ==================== 生成 UUID ====================
uuid=$(cat /proc/sys/kernel/random/uuid)
# ==================== 写入配置 ====================
cat > /usr/local/etc/xray/config.json << EOF
{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$uuid"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "none"
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls", "quic"],
"routeOnly": true
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "block"
}
],
"routing": {
"rules": [
{
"type": "field",
"outboundTag": "block",
"protocol": ["bittorrent"]
}
]
}
}
EOF
# ==================== 防火墙 ====================
if command -v ufw &> /dev/null; then
ufw allow 443/tcp
ufw allow 22/tcp
ufw --force enable
elif command -v firewall-cmd &> /dev/null; then
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload
fi
# ==================== 网络调优 ====================
cat > /etc/sysctl.d/99-xray-turbo.conf << 'SYSEOF'
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.ipv4.tcp_fastopen=3
net.ipv4.tcp_slow_start_after_idle=0
net.ipv4.tcp_mtu_probing=1
net.ipv4.tcp_fin_timeout=15
net.ipv4.tcp_keepalive_time=300
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=5
net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_max_syn_backlog=8192
net.core.somaxconn=8192
net.core.netdev_max_backlog=8192
SYSEOF
sysctl --system > /dev/null 2>&1
# ==================== 启动服务 ====================
systemctl daemon-reload
systemctl restart xray
systemctl enable xray
# ==================== 验证状态 ====================
sleep 2
if systemctl is-active --quiet xray; then
STATUS="✅ 运行中"
else
STATUS="❌ 启动失败,请检查: journalctl -u xray"
fi
# ==================== 输出配置 ====================
SERVER_IP=$(curl -s --max-time 5 ipv4.ip.sb || curl -s --max-time 5 ifconfig.me)
clear
cat << RESULT
==========================================================
Xray VLESS TCP 部署完成 ${STATUS}
==========================================================
IP : ${SERVER_IP}
端口 : 443
协议 : VLESS
UUID : ${uuid}
传输 : tcp
安全 : none
==========================================================
⚠️ 请保存以上信息!
配置文件: /usr/local/etc/xray/config.json
查看日志: journalctl -u xray -f
重启服务: systemctl restart xray
==========================================================
RESULT
```
---
## 二、Clash Meta 全局配置
`【你的IP】``【你的UUID】` 替换为部署脚本输出的值:
```yaml
mixed-port: 7890
allow-lan: false
mode: global
log-level: info
tcp-concurrent: true
proxies:
- name: "VPS_VLESS"
type: vless
server: 【你的IP】
port: 443
uuid: 【你的UUID】
network: tcp
tls: false
udp: false
skip-cert-verify: true
proxy-groups:
- name: "Proxy"
type: select
proxies:
- VPS_VLESS
```
---
## 三、运维速查
```bash
systemctl status xray # 查看状态
journalctl -u xray -f # 实时日志
systemctl restart xray # 重启
ss -tlnp | grep 443 # 验证端口
sysctl net.ipv4.tcp_congestion_control # 确认 BBR
# 更新 Xray
bash <(curl -fsSL https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh)
# 测试配置语法
/usr/local/bin/xray run -test -config /usr/local/etc/xray/config.json
```