BBR && SSR
BBR
wget -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh"
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================
# System Required: CentOS 6/7,Debian 8/9,Ubuntu 16+
# Description: BBR+BBR魔改版+BBRplus+Lotserver
# Version: 1.3.2
# Author: 千影,cx9208
# Blog: https://www.94ish.me/
#=================================================
sh_ver="1.3.2"
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"
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 http://${github}/bbr/${release}/RPM-GPG-KEY-elrepo.org
yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-${kernel_version}.rpm
yum remove -y kernel-headers
yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-headers-${kernel_version}.rpm
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 -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 linux-headers-${kernel_version}-all.deb
dpkg -i linux-headers-${kernel_version}.deb
dpkg -i linux-image-${kernel_version}.deb
cd .. && rm -rf bbr
fi
detele_kernel
BBR_grub
echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBR/BBR魔改版${Font_color_suffix}"
stty erase '^H' && read -p "需要重启VPS后,才能开启BBR/BBR魔改版,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
#安装BBRplus内核
installbbrplus(){
kernel_version="4.14.129-bbrplus"
if [[ "${release}" == "centos" ]]; then
wget -N --no-check-certificate https://${github}/bbrplus/${release}/${version}/kernel-${kernel_version}.rpm
yum install -y kernel-${kernel_version}.rpm
rm -f kernel-${kernel_version}.rpm
kernel_version="4.14.129_bbrplus" #fix a bug
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
mkdir bbrplus && cd bbrplus
wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
dpkg -i linux-headers-${kernel_version}.deb
dpkg -i linux-image-${kernel_version}.deb
cd .. && rm -rf bbrplus
fi
detele_kernel
BBR_grub
echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBRplus${Font_color_suffix}"
stty erase '^H' && read -p "需要重启VPS后,才能开启BBRplus,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
#安装Lotserver内核
installlot(){
if [[ "${release}" == "centos" ]]; then
rpm --import http://${github}/lotserver/${release}/RPM-GPG-KEY-elrepo.org
yum remove -y kernel-firmware
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-firmware-${kernel_version}.rpm
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-${kernel_version}.rpm
yum remove -y kernel-headers
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-headers-${kernel_version}.rpm
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-devel-${kernel_version}.rpm
elif [[ "${release}" == "ubuntu" ]]; then
bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
elif [[ "${release}" == "debian" ]]; then
bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
fi
detele_kernel
BBR_grub
echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}Lotserver${Font_color_suffix}"
stty erase '^H' && read -p "需要重启VPS后,才能开启Lotserver,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
#启用BBR
startbbr(){
remove_all
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
echo -e "${Info}BBR启动成功!"
}
#启用BBRplus
startbbrplus(){
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 http://${github}/bbr/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/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 http://${github}/bbr/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
ln -s /usr/bin/gcc /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 https://raw.githubusercontent.com/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 https://raw.githubusercontent.com/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启动成功!"
}
#启用Lotserver
startlotserver(){
remove_all
if [[ "${release}" == "centos" ]]; then
yum install ethtool
else
apt-get update
apt-get install ethtool
fi
bash <(wget --no-check-certificate -qO- https://raw.githubusercontent.com/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_max/d' /etc/sysctl.conf
sed -i '/net.core.wmem_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
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_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
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.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
if [[ -e /appex/bin/lotServer.sh ]]; then
bash <(wget --no-check-certificate -qO- https://github.com/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_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.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
# forward ipv4
net.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- "http://${github}/tcp.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
[[ -z ${sh_new_ver} ]] && echo -e "${Error} 检测最新版本失败 !" && start_menu
if [[ ${sh_new_ver} != ${sh_ver} ]]; then
echo -e "发现新版本[ ${sh_new_ver} ],是否更新?[Y/n]"
read -p "(默认: y):" yn
[[ -z "${yn}" ]] && yn="y"
if [[ ${yn} == [Yy] ]]; then
wget -N --no-check-certificate http://${github}/tcp.sh && chmod +x tcp.sh
echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !"
else
echo && echo " 已取消..." && echo
fi
else
echo -e "当前已是最新版本[ ${sh_new_ver} ] !"
sleep 5s
fi
}
#开始菜单
start_menu(){
clear
echo && echo -e " TCP加速 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
-- 就是爱生活 | 94ish.me --
${Green_font_prefix}0.${Font_color_suffix} 升级脚本
————————————内核管理————————————
${Green_font_prefix}1.${Font_color_suffix} 安装 BBR/BBR魔改版内核
${Green_font_prefix}2.${Font_color_suffix} 安装 BBRplus版内核
${Green_font_prefix}3.${Font_color_suffix} 安装 Lotserver(锐速)内核
————————————加速管理————————————
${Green_font_prefix}4.${Font_color_suffix} 使用BBR加速
${Green_font_prefix}5.${Font_color_suffix} 使用BBR魔改版加速
${Green_font_prefix}6.${Font_color_suffix} 使用暴力BBR魔改版加速(不支持部分系统)
${Green_font_prefix}7.${Font_color_suffix} 使用BBRplus版加速
${Green_font_prefix}8.${Font_color_suffix} 使用Lotserver(锐速)加速
————————————杂项管理————————————
${Green_font_prefix}9.${Font_color_suffix} 卸载全部加速
${Green_font_prefix}10.${Font_color_suffix} 系统配置优化
${Green_font_prefix}11.${Font_color_suffix} 退出脚本
————————————————————————————————" && echo
check_status
if [[ ${kernel_status} == "noinstall" ]]; then
echo -e " 当前状态: ${Green_font_prefix}未安装${Font_color_suffix} 加速内核 ${Red_font_prefix}请先安装内核${Font_color_suffix}"
else
echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} ${_font_prefix}${kernel_status}${Font_color_suffix} 加速内核 , ${Green_font_prefix}${run_status}${Font_color_suffix}"
fi
echo
read -p " 请输入数字 [0-11]:" num
case "$num" in
0)
Update_Shell
;;
1)
check_sys_bbr
;;
2)
check_sys_bbrplus
;;
3)
check_sys_Lotsever
;;
4)
startbbr
;;
5)
startbbrmod
;;
6)
startbbrmod_nanqinlang
;;
7)
startbbrplus
;;
8)
startlotserver
;;
9)
remove_all
;;
10)
optimizing_system
;;
11)
exit 1
;;
*)
clear
echo -e "${Error}:请输入正确数字 [0-11]"
sleep 5s
start_menu
;;
esac
}
#############内核管理组件#############
#删除多余内核
detele_kernel(){
if [[ "${release}" == "centos" ]]; then
rpm_total=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l`
if [ "${rpm_total}" > "1" ]; then
echo -e "检测到 ${rpm_total} 个其余内核,开始卸载..."
for((integer = 1; integer <= ${rpm_total}; integer++)); do
rpm_del=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer}`
echo -e "开始卸载 ${rpm_del} 内核..."
rpm --nodeps -e ${rpm_del}
echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
done
echo --nodeps -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
if [ "${deb_total}" > "1" ]; then
echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
for((integer = 1; integer <= ${deb_total}; integer++)); do
deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
echo -e "开始卸载 ${deb_del} 内核..."
apt-get purge -y ${deb_del}
echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
done
echo -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
fi
}
#更新引导
BBR_grub(){
if [[ "${release}" == "centos" ]]; then
if [[ ${version} = "6" ]]; then
if [ ! -f "/boot/grub/grub.conf" ]; then
echo -e "${Error} /boot/grub/grub.conf 找不到,请检查."
exit 1
fi
sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
elif [[ ${version} = "7" ]]; then
if [ ! -f "/boot/grub2/grub.cfg" ]; then
echo -e "${Error} /boot/grub2/grub.cfg 找不到,请检查."
exit 1
fi
grub2-set-default 0
fi
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
/usr/sbin/update-grub
fi
}
#############内核管理组件#############
#############系统检测组件#############
#检查系统
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
}
#检查Linux版本
check_version(){
if [[ -s /etc/redhat-release ]]; then
version=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
else
version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
fi
bit=`uname -m`
if [[ ${bit} = "x86_64" ]]; then
bit="x64"
else
bit="x32"
fi
}
#检查安装bbr的系统要求
check_sys_bbr(){
check_version
if [[ "${release}" == "centos" ]]; then
if [[ ${version} -ge "6" ]]; then
installbbr
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "debian" ]]; then
if [[ ${version} -ge "8" ]]; then
installbbr
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "ubuntu" ]]; then
if [[ ${version} -ge "14" ]]; then
installbbr
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
}
check_sys_bbrplus(){
check_version
if [[ "${release}" == "centos" ]]; then
if [[ ${version} -ge "6" ]]; then
installbbrplus
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "debian" ]]; then
if [[ ${version} -ge "8" ]]; then
installbbrplus
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "ubuntu" ]]; then
if [[ ${version} -ge "14" ]]; then
installbbrplus
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
}
#检查安装Lotsever的系统要求
check_sys_Lotsever(){
check_version
if [[ "${release}" == "centos" ]]; then
if [[ ${version} == "6" ]]; then
kernel_version="2.6.32-504"
installlot
elif [[ ${version} == "7" ]]; then
yum -y install net-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.4.0-47"
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.4.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
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 "=" '{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 "=" '{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_sys
check_version
[[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
start_menu
SSR
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh && chmod +x ssr.sh && bash ssr.sh
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================
# System Required: CentOS 6+/Debian 6+/Ubuntu 14.04+
# Description: Install the ShadowsocksR server
# Version: 2.0.38
# Author: Toyo
# Blog: https://doub.io/ss-jc42/
#=================================================
sh_ver="2.0.38"
filepath=$(cd "$(dirname "$0")"; pwd)
file=$(echo -e "${filepath}"|awk -F "$0" '{print $1}')
ssr_folder="/usr/local/shadowsocksr"
ssr_ss_file="${ssr_folder}/shadowsocks"
config_file="${ssr_folder}/config.json"
config_folder="/etc/shadowsocksr"
config_user_file="${config_folder}/user-config.json"
ssr_log_file="${ssr_ss_file}/ssserver.log"
Libsodiumr_file="/usr/local/lib/libsodium.so"
Libsodiumr_ver_backup="1.0.13"
Server_Speeder_file="/serverspeeder/bin/serverSpeeder.sh"
LotServer_file="/appex/bin/serverSpeeder.sh"
BBR_file="${file}/bbr.sh"
jq_file="${ssr_folder}/jq"
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}"
Separator_1="——————————————————————————————"
check_root(){
[[ $EUID != 0 ]] && echo -e "${Error} 当前账号非ROOT(或没有ROOT权限),无法继续操作,请使用${Green_background_prefix} sudo su ${Font_color_suffix}来获取临时ROOT权限(执行后会提示输入当前账号的密码)。" && exit 1
}
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
bit=`uname -m`
}
check_pid(){
PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
}
SSR_installation_status(){
[[ ! -e ${config_user_file} ]] && echo -e "${Error} 没有发现 ShadowsocksR 配置文件,请检查 !" && exit 1
[[ ! -e ${ssr_folder} ]] && echo -e "${Error} 没有发现 ShadowsocksR 文件夹,请检查 !" && exit 1
}
Server_Speeder_installation_status(){
[[ ! -e ${Server_Speeder_file} ]] && echo -e "${Error} 没有安装 锐速(Server Speeder),请检查 !" && exit 1
}
LotServer_installation_status(){
[[ ! -e ${LotServer_file} ]] && echo -e "${Error} 没有安装 LotServer,请检查 !" && exit 1
}
BBR_installation_status(){
if [[ ! -e ${BBR_file} ]]; then
echo -e "${Error} 没有发现 BBR脚本,开始下载..."
cd "${file}"
if ! wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/bbr.sh; then
echo -e "${Error} BBR 脚本下载失败 !" && exit 1
else
echo -e "${Info} BBR 脚本下载完成 !"
chmod +x bbr.sh
fi
fi
}
# 设置 防火墙规则
Add_iptables(){
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssr_port} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssr_port} -j ACCEPT
ip6tables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssr_port} -j ACCEPT
ip6tables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssr_port} -j ACCEPT
}
Del_iptables(){
iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
ip6tables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
ip6tables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
}
Save_iptables(){
if [[ ${release} == "centos" ]]; then
service iptables save
service ip6tables save
else
iptables-save > /etc/iptables.up.rules
ip6tables-save > /etc/ip6tables.up.rules
fi
}
Set_iptables(){
if [[ ${release} == "centos" ]]; then
service iptables save
service ip6tables save
chkconfig --level 2345 iptables on
chkconfig --level 2345 ip6tables on
else
iptables-save > /etc/iptables.up.rules
ip6tables-save > /etc/ip6tables.up.rules
echo -e '#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules\n/sbin/ip6tables-restore < /etc/ip6tables.up.rules' > /etc/network/if-pre-up.d/iptables
chmod +x /etc/network/if-pre-up.d/iptables
fi
}
# 读取 配置信息
Get_IP(){
ip=$(wget -qO- -t1 -T2 ipinfo.io/ip)
if [[ -z "${ip}" ]]; then
ip=$(wget -qO- -t1 -T2 api.ip.sb/ip)
if [[ -z "${ip}" ]]; then
ip=$(wget -qO- -t1 -T2 members.3322.org/dyndns/getip)
if [[ -z "${ip}" ]]; then
ip="VPS_IP"
fi
fi
fi
}
Get_User(){
[[ ! -e ${jq_file} ]] && echo -e "${Error} JQ解析器 不存在,请检查 !" && exit 1
port=`${jq_file} '.server_port' ${config_user_file}`
password=`${jq_file} '.password' ${config_user_file} | sed 's/^.//;s/.$//'`
method=`${jq_file} '.method' ${config_user_file} | sed 's/^.//;s/.$//'`
protocol=`${jq_file} '.protocol' ${config_user_file} | sed 's/^.//;s/.$//'`
obfs=`${jq_file} '.obfs' ${config_user_file} | sed 's/^.//;s/.$//'`
protocol_param=`${jq_file} '.protocol_param' ${config_user_file} | sed 's/^.//;s/.$//'`
speed_limit_per_con=`${jq_file} '.speed_limit_per_con' ${config_user_file}`
speed_limit_per_user=`${jq_file} '.speed_limit_per_user' ${config_user_file}`
connect_verbose_info=`${jq_file} '.connect_verbose_info' ${config_user_file}`
}
urlsafe_base64(){
date=$(echo -n "$1"|base64|sed ':a;N;s/\n/ /g;ta'|sed 's/ //g;s/=//g;s/+/-/g;s/\//_/g')
echo -e "${date}"
}
ss_link_qr(){
SSbase64=$(urlsafe_base64 "${method}:${password}@${ip}:${port}")
SSurl="ss://${SSbase64}"
SSQRcode="http://doub.pw/qr/qr.php?text=${SSurl}"
ss_link=" SS 链接 : ${Green_font_prefix}${SSurl}${Font_color_suffix} \n SS 二维码 : ${Green_font_prefix}${SSQRcode}${Font_color_suffix}"
}
ssr_link_qr(){
SSRprotocol=$(echo ${protocol} | sed 's/_compatible//g')
SSRobfs=$(echo ${obfs} | sed 's/_compatible//g')
SSRPWDbase64=$(urlsafe_base64 "${password}")
SSRbase64=$(urlsafe_base64 "${ip}:${port}:${SSRprotocol}:${method}:${SSRobfs}:${SSRPWDbase64}")
SSRurl="ssr://${SSRbase64}"
SSRQRcode="http://doub.pw/qr/qr.php?text=${SSRurl}"
ssr_link=" SSR 链接 : ${Red_font_prefix}${SSRurl}${Font_color_suffix} \n SSR 二维码 : ${Red_font_prefix}${SSRQRcode}${Font_color_suffix} \n "
}
ss_ssr_determine(){
protocol_suffix=`echo ${protocol} | awk -F "_" '{print $NF}'`
obfs_suffix=`echo ${obfs} | awk -F "_" '{print $NF}'`
if [[ ${protocol} = "origin" ]]; then
if [[ ${obfs} = "plain" ]]; then
ss_link_qr
ssr_link=""
else
if [[ ${obfs_suffix} != "compatible" ]]; then
ss_link=""
else
ss_link_qr
fi
fi
else
if [[ ${protocol_suffix} != "compatible" ]]; then
ss_link=""
else
if [[ ${obfs_suffix} != "compatible" ]]; then
if [[ ${obfs_suffix} = "plain" ]]; then
ss_link_qr
else
ss_link=""
fi
else
ss_link_qr
fi
fi
fi
ssr_link_qr
}
# 显示 配置信息
View_User(){
SSR_installation_status
Get_IP
Get_User
now_mode=$(cat "${config_user_file}"|grep '"port_password"')
[[ -z ${protocol_param} ]] && protocol_param="0(无限)"
if [[ -z "${now_mode}" ]]; then
ss_ssr_determine
clear && echo "===================================================" && echo
echo -e " ShadowsocksR账号 配置信息:" && echo
echo -e " I P\t : ${Green_font_prefix}${ip}${Font_color_suffix}"
echo -e " 端口\t : ${Green_font_prefix}${port}${Font_color_suffix}"
echo -e " 密码\t : ${Green_font_prefix}${password}${Font_color_suffix}"
echo -e " 加密\t : ${Green_font_prefix}${method}${Font_color_suffix}"
echo -e " 协议\t : ${Red_font_prefix}${protocol}${Font_color_suffix}"
echo -e " 混淆\t : ${Red_font_prefix}${obfs}${Font_color_suffix}"
echo -e " 设备数限制 : ${Green_font_prefix}${protocol_param}${Font_color_suffix}"
echo -e " 单线程限速 : ${Green_font_prefix}${speed_limit_per_con} KB/S${Font_color_suffix}"
echo -e " 端口总限速 : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}"
echo -e "${ss_link}"
echo -e "${ssr_link}"
echo -e " ${Green_font_prefix} 提示: ${Font_color_suffix}
在浏览器中,打开二维码链接,就可以看到二维码图片。
协议和混淆后面的[ _compatible ],指的是 兼容原版协议/混淆。"
echo && echo "==================================================="
else
user_total=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
[[ ${user_total} = "0" ]] && echo -e "${Error} 没有发现 多端口用户,请检查 !" && exit 1
clear && echo "===================================================" && echo
echo -e " ShadowsocksR账号 配置信息:" && echo
echo -e " I P\t : ${Green_font_prefix}${ip}${Font_color_suffix}"
echo -e " 加密\t : ${Green_font_prefix}${method}${Font_color_suffix}"
echo -e " 协议\t : ${Red_font_prefix}${protocol}${Font_color_suffix}"
echo -e " 混淆\t : ${Red_font_prefix}${obfs}${Font_color_suffix}"
echo -e " 设备数限制 : ${Green_font_prefix}${protocol_param}${Font_color_suffix}"
echo -e " 单线程限速 : ${Green_font_prefix}${speed_limit_per_con} KB/S${Font_color_suffix}"
echo -e " 端口总限速 : ${Green_font_prefix}${speed_limit_per_user} KB/S${Font_color_suffix}" && echo
for((integer = ${user_total}; integer >= 1; integer--))
do
port=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'`
password=`${jq_file} '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | sed -r 's/.*\"(.+)\".*/\1/'`
ss_ssr_determine
echo -e ${Separator_1}
echo -e " 端口\t : ${Green_font_prefix}${port}${Font_color_suffix}"
echo -e " 密码\t : ${Green_font_prefix}${password}${Font_color_suffix}"
echo -e "${ss_link}"
echo -e "${ssr_link}"
done
echo -e " ${Green_font_prefix} 提示: ${Font_color_suffix}
在浏览器中,打开二维码链接,就可以看到二维码图片。
协议和混淆后面的[ _compatible ],指的是 兼容原版协议/混淆。"
echo && echo "==================================================="
fi
}
# 设置 配置信息
Set_config_port(){
while true
do
echo -e "请输入要设置的ShadowsocksR账号 端口"
read -e -p "(默认: 2333):" ssr_port
[[ -z "$ssr_port" ]] && ssr_port="233
正文到此结束