feat: 集成 BBR Blast Smooth v2 加速优化

This commit is contained in:
mango
2026-02-14 21:26:06 +08:00
parent e74c0f584d
commit 4a4ad8b821

View File

@@ -380,6 +380,91 @@ with open('/etc/shadowsocks-rust/config.json','w') as f:
show_result
}
# ============ BBR 优化 ============
setup_bbr() {
echo ""
echo -e "${CYAN}════════════════════════════════════════${NC}"
echo -e "${CYAN} ⚡ BBR Blast Smooth v2${NC}"
echo -e "${CYAN}════════════════════════════════════════${NC}"
echo ""
# 检测是否已启用
local cc=$(sysctl -n net.ipv4.tcp_congestion_control 2>/dev/null)
local qd=$(sysctl -n net.core.default_qdisc 2>/dev/null)
if [[ "$cc" == "bbr" && "$qd" == "fq" ]]; then
info "BBR 已启用 (congestion=$cc, qdisc=$qd)"
grep -q "BBR Blast" /etc/sysctl.conf 2>/dev/null && info "BBR Blast 配置已存在" && return 0
fi
# 检测系统
if [[ ! -f /etc/os-release ]]; then
warn "无法检测系统,跳过 BBR"; return 1
fi
. /etc/os-release
local os_name="$ID $VERSION_ID"
info "系统: $os_name"
# 检测内存,选择 profile
local mem=$(free -m | awk '/^Mem:/{print $2}')
local profile rmem wmem tcp_rmem tcp_wmem
if [[ "$mem" -lt 512 ]]; then
profile="micro"; rmem=8388608; wmem=8388608
tcp_rmem="4096 32768 8388608"; tcp_wmem="4096 32768 8388608"
elif [[ "$mem" -lt 1024 ]]; then
profile="small"; rmem=16777216; wmem=16777216
tcp_rmem="4096 65536 16777216"; tcp_wmem="4096 65536 16777216"
elif [[ "$mem" -lt 2048 ]]; then
profile="medium"; rmem=33554432; wmem=33554432
tcp_rmem="4096 87380 33554432"; tcp_wmem="4096 65536 33554432"
elif [[ "$mem" -lt 4096 ]]; then
profile="large"; rmem=67108864; wmem=67108864
tcp_rmem="4096 87380 67108864"; tcp_wmem="4096 65536 67108864"
else
profile="xlarge"; rmem=134217728; wmem=134217728
tcp_rmem="4096 87380 134217728"; tcp_wmem="4096 65536 134217728"
fi
info "内存: ${mem}MB | Profile: $profile | Buffer: $((rmem/1024/1024))MB"
# 备份
if [[ -f /etc/sysctl.conf ]]; then
cp /etc/sysctl.conf /etc/sysctl.conf.bak.$(date +%Y%m%d%H%M%S)
fi
# 写入配置
sed -i '/# === BBR Blast/,/# === END BBR/d' /etc/sysctl.conf 2>/dev/null || true
cat >> /etc/sysctl.conf <<SYSCTL
# === BBR Blast Smooth v2 (Profile: $profile) ===
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.core.rmem_max=$rmem
net.core.wmem_max=$wmem
net.ipv4.tcp_rmem=$tcp_rmem
net.ipv4.tcp_wmem=$tcp_wmem
net.ipv4.tcp_fin_timeout=8
net.ipv4.tcp_tw_reuse=1
net.ipv4.tcp_window_scaling=1
net.ipv4.tcp_timestamps=1
net.ipv4.tcp_sack=1
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn=65535
net.ipv4.tcp_max_syn_backlog=65535
net.ipv4.tcp_fastopen=3
# === END BBR ===
SYSCTL
sysctl -p >/dev/null 2>&1
# 验证
cc=$(sysctl -n net.ipv4.tcp_congestion_control 2>/dev/null)
qd=$(sysctl -n net.core.default_qdisc 2>/dev/null)
if [[ "$cc" == "bbr" && "$qd" == "fq" ]]; then
info "BBR 启用成功 ✓ (congestion=$cc, qdisc=$qd)"
else
warn "BBR 可能需要重启生效"
fi
}
# ============ 卸载 ============
uninstall() {
warn "卸载 shadowsocks-rust..."
@@ -402,6 +487,10 @@ do_install() {
setup_service
gen_subscribe
show_result
echo ""
read -rp "是否开启 BBR 加速? [Y/n]: " bbr_choice
bbr_choice=${bbr_choice:-Y}
[[ "$bbr_choice" =~ ^[Yy]$ ]] && setup_bbr
}
# ============ 管理菜单 ============
@@ -419,10 +508,11 @@ show_menu() {
echo -e " ${GREEN}6.${NC} 停止服务"
echo -e " ${GREEN}7.${NC} 重启服务"
echo -e " ${GREEN}8.${NC} 查看日志"
echo -e " ${GREEN}10.${NC} ⚡ BBR 加速优化"
echo -e " ${RED}9.${NC} 卸载"
echo -e " ${YELLOW}0.${NC} 退出"
echo ""
read -rp "请选择 [0-9]: " choice
read -rp "请选择 [0-10]: " choice
case "$choice" in
1) do_install ;;
@@ -434,6 +524,7 @@ show_menu() {
7) systemctl restart ss-rust && info "已重启" ;;
8) journalctl -u ss-rust --no-pager -n 30 ;;
9) uninstall ;;
10) setup_bbr ;;
0) exit 0 ;;
*) warn "无效选择" ;;
esac
@@ -451,6 +542,7 @@ main() {
stop) systemctl stop ss-rust && info "已停止" ;;
log|logs) journalctl -u ss-rust --no-pager -n 30 ;;
reset) reset_keys ;;
bbr) setup_bbr ;;
*)
if [[ -f /etc/shadowsocks-rust/config.json ]]; then
show_menu