如何一键部署ssr,ssr占用率( 二 )

BBR脚本
#!/usr/bin/env bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATH#=================================================# System Required: CentOS 6/7,Debian 8/9,Ubuntu 16+# Description: BBR+BBR魔改版+BBRplus+Lotserver# Version: 1.4.0# Author: 千影,cx9208# Blog: ***/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"Info="${Green_font_prefix}[信息]${Font_color_suffix}"Error="${Red_font_prefix}[错误]${Font_color_suffix}"Tip="${Green_font_prefix}[注意]${Font_color_suffix}"#安装BBR内核installbbr(){ kernel_version="4.11.8" if [[ "${release}" == "centos" ]]; then rpm --import *** yum install -y ***/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1d-0+deb10u2_amd64.deb wget -N --no-check-certificate ***} VPS 重启中..." reboot fi}#安装BBRplus内核installbbrplus(){ kernel_version="4.14.129-bbrplus" if [[ "${release}" == "centos" ]]; then wget -N --no-check-certificate ***} VPS 重启中..." reboot fi}#安装Lotserver内核installlot(){ if [[ "${release}" == "centos" ]]; then rpm --import *** yum remove -y kernel-firmware yum install -y ***} VPS 重启中..." reboot fi}#启用BBRstartbbr(){ remove_all 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启动成功!"}#启用BBRplusstartbbrplus(){ remove_all echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_cOntrol=bbrplus" >> /etc/sysctl.conf sysctl -p echo -e "${Info}BBRplus启动成功!"}#编译并启用BBR魔改startbbrmod(){ remove_all if [[ "${release}" == "centos" ]]; then yum install -y make gcc mkdir bbrmod && cd bbrmod wget -N --no-check-certificate ***=/usr/bin/gcc chmod +x ./tcp_tsunami.ko cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4 insmod tcp_tsunami.ko depmod -a else apt-get update if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then apt-get -y install build-essential apt-get -y install software-properties-common add-apt-repository ppa:ubuntu-toolchain-r/test -y apt-get update fi apt-get -y install make gcc mkdir bbrmod && cd bbrmod wget -N --no-check-certificate *** /usr/bin/gcc-4.9 make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9 install tcp_tsunami.ko /lib/modules/$(uname -r)/kernel cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4 depmod -a fi echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_cOntrol=tsunami" >> /etc/sysctl.conf sysctl -p cd .. && rm -rf bbrmod echo -e "${Info}魔改版BBR启动成功!"}#编译并启用BBR魔改startbbrmod_nanqinlang(){ remove_all if [[ "${release}" == "centos" ]]; then yum install -y make gcc mkdir bbrmod && cd bbrmod wget -N --no-check-certificate ***/chiakge/Linux-NetSpeed/master/bbr/centos/tcp_nanqinlang.c echo "obj-m := tcp_nanqinlang.o" > Makefile make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc chmod +x ./tcp_nanqinlang.ko cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4 insmod tcp_nanqinlang.ko depmod -a else apt-get update if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then apt-get -y install build-essential apt-get -y install software-properties-common add-apt-repository ppa:ubuntu-toolchain-r/test -y apt-get update fi apt-get -y install make gcc-4.9 mkdir bbrmod && cd bbrmod wget -N --no-check-certificate ***/chiakge/Linux-NetSpeed/master/bbr/tcp_nanqinlang.c echo "obj-m := tcp_nanqinlang.o" > Makefile make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9 install tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4 depmod -a fi echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_cOntrol=nanqinlang" >> /etc/sysctl.conf sysctl -p echo -e "${Info}魔改版BBR启动成功!"}#启用Lotserverstartlotserver(){ remove_all if [[ "${release}" == "centos" ]]; then yum install ethtool else apt-get update apt-get install ethtool fi bash <(wget --no-check-certificate -qO- ***/chiakge/lotServer/master/Install.sh) install sed -i '/advinacc/d' /appex/etc/config sed -i '/maxmode/d' /appex/etc/config echo -e "advinacc=\"1\"maxmode=\"1\"">>/appex/etc/config /appex/bin/lotServer.sh restart start_menu}#卸载全部加速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_default/d' /etc/sysctl.conf sed -i '/net.core.wmem_default/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 sed -i '/net.ipv4.tcp_tw_recycle/d' /etc/sysctl.conf 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_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 sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.conf sed -i '/net.ipv4.ip_forward/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.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_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- ***/MoeClub/lotServer/raw/master/Install.sh) uninstall fi clear echo -e "${Info}:清除加速完成 。" sleep 1s}#优化系统配置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_tw_reuse/d' /etc/sysctl.conf sed -i '/net.ipv4.ip_local_port_range/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_slow_start_after_idle/d' /etc/sysctl.conf sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf echo "fs.file-max = 1000000fs.inotify.max_user_instances = 8192net.ipv4.tcp_tw_reuse = 1net.ipv4.ip_local_port_range = 1024 65535net.ipv4.tcp_rmem = 16384 262144 8388608net.ipv4.tcp_wmem = 32768 524288 16777216net.core.somaxcOnn= 8192net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.wmem_default = 2097152net.ipv4.tcp_max_tw_buckets = 5000net.ipv4.tcp_max_syn_backlog = 10240net.core.netdev_max_backlog = 10240net.ipv4.tcp_slow_start_after_idle = 0# forward ipv4net.ipv4.ip_forward = 1">>/etc/sysctl.conf sysctl -p echo "* soft nofile 1000000* hard nofile 1000000">/etc/security/limits.conf echo "ulimit -SHn 1000000">>/etc/profile read -p "需要重启VPS后 , 才能生效系统优化配置 , 是否现在重启 ? [Y/n] :" yn [ -z "${yn}" ] && yn="y" if [[ $yn == [Yy] ]]; then echo -e "${Info} VPS 重启中..." reboot fi}#更新脚本Update_Shell(){ echo -e "当前版本为 [ ${sh_ver} ] , 开始检测最新版本..." sh_new_ver=$(wget --no-check-certificate -qO- "***-tools kernel_version="3.10.0-327" installlot else echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1 fi elif [[ "${release}" == "debian" ]]; then if [[ ${version} = "7" || ${version} = "8" ]]; then if [[ ${bit} == "x64" ]]; then kernel_version="3.16.0-4" installlot elif [[ ${bit} == "x32" ]]; then kernel_version="3.2.0-4" installlot fi elif [[ ${version} = "9" ]]; then if [[ ${bit} == "x64" ]]; then kernel_version="4.9.0-4" installlot fi else echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1 fi elif [[ "${release}" == "ubuntu" ]]; then if [[ ${version} -ge "12" ]]; then if [[ ${bit} == "x64" ]]; then kernel_version="4.8.0-36" installlot elif [[ ${bit} == "x32" ]]; then kernel_version="3.13.0-29" installlot fi else echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1 fi else echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1 fi}check_status(){ kernel_version=`uname -r | awk -F "-" '{print $1}'` 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.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}'` -ge "5" ]]; then kernel_status="BBR" else kernel_status="noinstall" fi if [[ ${kernel_status} == "Lotserver" ]]; then if [[ -e /appex/bin/lotServer.sh ]]; then run_status=`bash /appex/bin/lotServer.sh status | grep "LotServer" | awk '{print $3}'` if [[ ${run_status} = "running!" ]]; then run_status="启动成功" else run_status="启动失败" fi else run_status="未安装加速模块" fi elif [[ ${kernel_status} == "BBR" ]]; then 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 run_status="BBR启动成功" else run_status="BBR启动失败" fi elif [[ ${run_status} == "tsunami" ]]; then run_status=`lsmod | grep "tsunami" | awk '{print $1}'` if [[ ${run_status} == "tcp_tsunami" ]]; then run_status="BBR魔改版启动成功" else run_status="BBR魔改版启动失败" fi elif [[ ${run_status} == "nanqinlang" ]]; then run_status=`lsmod | grep "nanqinlang" | awk '{print $1}'` if [[ ${run_status} == "tcp_nanqinlang" ]]; then run_status="暴力BBR魔改版启动成功" else run_status="暴力BBR魔改版启动失败" fi else run_status="未安装加速模块" fi elif [[ ${kernel_status} == "BBRplus" ]]; then 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 run_status="BBRplus启动成功" else run_status="BBRplus启动失败" fi else run_status="未安装加速模块" fi fi}#############系统检测组件#############check_syscheck_version[[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1start_menu

推荐阅读