增加l bbr加速 功能

This commit is contained in:
Olia Lisa
2026-05-28 08:43:55 +08:00
parent 900378b8ec
commit 4bd898a067
+47
View File
@@ -135,6 +135,48 @@ create_config(){
esac esac
} }
enable_kernel_bbr(){
if [ "$(id -u)" -ne 0 ]; then
echo "请使用 root 权限运行该操作"
return 1
fi
if [ "$(sysctl -n net.ipv4.tcp_congestion_control 2>/dev/null)" = "bbr" ]; then
echo "BBR加速 已经开启,无需重复操作"
return 0
fi
if command -v modprobe >/dev/null 2>&1; then
modprobe tcp_bbr 2>/dev/null || true
fi
if ! sysctl net.ipv4.tcp_available_congestion_control 2>/dev/null | grep -qw bbr; then
echo "当前系统内核不支持 BBR"
return 1
fi
set_sysctl_conf(){
local key="$1"
local value="$2"
local file="/etc/sysctl.conf"
touch "$file"
if grep -qE "^[[:space:]]*#?[[:space:]]*$key[[:space:]]*=" "$file"; then
sed -i "s|^[[:space:]]*#\?[[:space:]]*$key[[:space:]]*=.*|$key = $value|" "$file"
else
echo "$key = $value" >> "$file"
fi
}
set_sysctl_conf "net.core.default_qdisc" "fq"
set_sysctl_conf "net.ipv4.tcp_congestion_control" "bbr"
sysctl -w net.core.default_qdisc=fq >/dev/null
sysctl -w net.ipv4.tcp_congestion_control=bbr >/dev/null
echo "BBR加速 已开启"
}
main(){ main(){
local container_status=$(check_container_status) local container_status=$(check_container_status)
# 显示菜单 # 显示菜单
@@ -151,6 +193,7 @@ main(){
echo "7. 修改端口" echo "7. 修改端口"
echo "8. 更新镜像" echo "8. 更新镜像"
echo "9. 更新脚本" echo "9. 更新脚本"
echo "10. 开启BBR加速"
# 读取用户选择 # 读取用户选择
local choice local choice
@@ -212,6 +255,10 @@ main(){
# 更新脚本 # 更新脚本
git pull git pull
;; ;;
10)
# 开启BBR加速
enable_kernel_bbr
;;
*) *)
echo "无效的选择, 请重新选择." echo "无效的选择, 请重新选择."
;; ;;