diff --git a/README.md b/README.md index b3ace69d..c2cb84b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Linux-NetSpeed +本脚本已不更新,推荐使用5.5以上内核自带的bbr速度最佳 +- https://roov.org/2020/03/bbr-bbrplus-bbr2/ +- 推荐使用该脚本:bash <(curl -Lso- https://git.io/kernel.sh) ``` wget -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh" chmod +x tcp.sh diff --git a/tcp.sh b/tcp.sh index e67380e3..1107ea93 100755 --- a/tcp.sh +++ b/tcp.sh @@ -5,12 +5,13 @@ export PATH #================================================= # System Required: CentOS 6/7,Debian 8/9,Ubuntu 16+ # Description: BBR+BBR魔改版+BBRplus+Lotserver -# Version: 1.3.2 +# Version: 1.4.0 # Author: 千影,cx9208 -# Blog: https://www.94ish.me/ +# Blog: https://www.939.me/ +# 推荐使用5.5以上内核直接开启的bbr速度最佳 #================================================= -sh_ver="1.3.2" +sh_ver="1.4.0" github="raw.githubusercontent.com/chiakge/Linux-NetSpeed/master" Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" @@ -29,12 +30,12 @@ installbbr(){ yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-devel-${kernel_version}.rpm elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then mkdir bbr && cd bbr - wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u10_amd64.deb + wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1d-0+deb10u2_amd64.deb wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/linux-headers-${kernel_version}-all.deb wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb - dpkg -i libssl1.0.0_1.0.1t-1+deb8u10_amd64.deb + dpkg -i libssl1.1_1.1.1d-0+deb10u2_amd64.deb dpkg -i linux-headers-${kernel_version}-all.deb dpkg -i linux-headers-${kernel_version}.deb dpkg -i linux-image-${kernel_version}.deb @@ -107,8 +108,13 @@ installlot(){ #启用BBR startbbr(){ remove_all - echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf - echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf + if [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` -ge "5" ]]; then + echo "net.core.default_qdisc=cake" >> /etc/sysctl.conf + echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf + else + echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf + echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf + fi sysctl -p echo -e "${Info}BBR启动成功!" } @@ -222,13 +228,10 @@ maxmode=\"1\"">>/appex/etc/config remove_all(){ rm -rf bbrmod sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf - sed -i '/fs.file-max/d' /etc/sysctl.conf - sed -i '/net.core.rmem_max/d' /etc/sysctl.conf - sed -i '/net.core.wmem_max/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf + sed -i '/fs.file-max/d' /etc/sysctl.conf sed -i '/net.core.rmem_default/d' /etc/sysctl.conf sed -i '/net.core.wmem_default/d' /etc/sysctl.conf - sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf sed -i '/net.core.somaxconn/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf @@ -236,7 +239,6 @@ remove_all(){ sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.conf sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf @@ -245,17 +247,17 @@ remove_all(){ sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf - sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf - sed -i '/net.core.somaxconn/d' /etc/sysctl.conf - sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf + sed -i '/net.core.rmem_max/d' /etc/sysctl.conf + sed -i '/net.core.wmem_max/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf + sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.conf + sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf if [[ -e /appex/bin/lotServer.sh ]]; then bash <(wget --no-check-certificate -qO- https://github.com/MoeClub/lotServer/raw/master/Install.sh) uninstall fi @@ -268,35 +270,33 @@ remove_all(){ optimizing_system(){ sed -i '/fs.file-max/d' /etc/sysctl.conf sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf - sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf sed -i '/net.core.somaxconn/d' /etc/sysctl.conf + sed -i '/net.core.rmem_max/d' /etc/sysctl.conf + sed -i '/net.core.wmem_max/d' /etc/sysctl.conf + sed -i '/net.core.wmem_default/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf - sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf + sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.conf sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf echo "fs.file-max = 1000000 fs.inotify.max_user_instances = 8192 -net.ipv4.tcp_syncookies = 1 -net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_tw_reuse = 1 -net.ipv4.ip_local_port_range = 1024 65000 -net.ipv4.tcp_max_syn_backlog = 16384 -net.ipv4.tcp_max_tw_buckets = 6000 -net.ipv4.route.gc_timeout = 100 -net.ipv4.tcp_syn_retries = 1 -net.ipv4.tcp_synack_retries = 1 -net.core.somaxconn = 32768 -net.core.netdev_max_backlog = 32768 -net.ipv4.tcp_timestamps = 0 -net.ipv4.tcp_max_orphans = 32768 +net.ipv4.ip_local_port_range = 1024 65535 +net.ipv4.tcp_rmem = 16384 262144 8388608 +net.ipv4.tcp_wmem = 32768 524288 16777216 +net.core.somaxconn = 8192 +net.core.rmem_max = 16777216 +net.core.wmem_max = 16777216 +net.core.wmem_default = 2097152 +net.ipv4.tcp_max_tw_buckets = 5000 +net.ipv4.tcp_max_syn_backlog = 10240 +net.core.netdev_max_backlog = 10240 +net.ipv4.tcp_slow_start_after_idle = 0 # forward ipv4 net.ipv4.ip_forward = 1">>/etc/sysctl.conf sysctl -p @@ -590,7 +590,7 @@ check_sys_Lotsever(){ elif [[ "${release}" == "ubuntu" ]]; then if [[ ${version} -ge "12" ]]; then if [[ ${bit} == "x64" ]]; then - kernel_version="4.4.0-47" + kernel_version="4.8.0-36" installlot elif [[ ${bit} == "x32" ]]; then kernel_version="3.13.0-29" @@ -609,9 +609,9 @@ check_status(){ kernel_version_full=`uname -r` if [[ ${kernel_version_full} = "4.14.129-bbrplus" ]]; then kernel_status="BBRplus" - elif [[ ${kernel_version} = "3.10.0" || ${kernel_version} = "3.16.0" || ${kernel_version} = "3.2.0" || ${kernel_version} = "4.4.0" || ${kernel_version} = "3.13.0" || ${kernel_version} = "2.6.32" || ${kernel_version} = "4.9.0" ]]; then + elif [[ ${kernel_version} = "3.10.0" || ${kernel_version} = "3.16.0" || ${kernel_version} = "3.2.0" || ${kernel_version} = "4.8.0" || ${kernel_version} = "3.13.0" || ${kernel_version} = "2.6.32" || ${kernel_version} = "4.9.0" ]]; then kernel_status="Lotserver" - elif [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` == "4" ]] && [[ `echo ${kernel_version} | awk -F'.' '{print $2}'` -ge 9 ]] || [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` == "5" ]]; then + elif [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` == "4" ]] && [[ `echo ${kernel_version} | awk -F'.' '{print $2}'` -ge 9 ]] || [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` -ge "5" ]]; then kernel_status="BBR" else kernel_status="noinstall" @@ -629,7 +629,7 @@ check_status(){ run_status="未安装加速模块" fi elif [[ ${kernel_status} == "BBR" ]]; then - run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'` + run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{gsub("^[ \t]+|[ \t]+$", "", $2);print $2}'` if [[ ${run_status} == "bbr" ]]; then run_status=`lsmod | grep "bbr" | awk '{print $1}'` if [[ ${run_status} == "tcp_bbr" ]]; then @@ -655,7 +655,7 @@ check_status(){ run_status="未安装加速模块" fi elif [[ ${kernel_status} == "BBRplus" ]]; then - run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'` + run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{gsub("^[ \t]+|[ \t]+$", "", $2);print $2}'` if [[ ${run_status} == "bbrplus" ]]; then run_status=`lsmod | grep "bbrplus" | awk '{print $1}'` if [[ ${run_status} == "tcp_bbrplus" ]]; then