From 4a4ad8b821ee56501165af1ad5037d90f8eaa565 Mon Sep 17 00:00:00 2001 From: mango Date: Sat, 14 Feb 2026 21:26:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9B=86=E6=88=90=20BBR=20Blast=20Smoo?= =?UTF-8?q?th=20v2=20=E5=8A=A0=E9=80=9F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ss-rust.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/ss-rust.sh b/ss-rust.sh index 61640b4..26ca581 100644 --- a/ss-rust.sh +++ b/ss-rust.sh @@ -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 </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