tcp.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. #!/usr/bin/env bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. #=================================================
  5. # System Required: CentOS 6/7,Debian 8/9,Ubuntu 16+
  6. # Description: BBR+BBR魔改版+BBRplus+Lotserver
  7. # Version: 1.4.0
  8. # Author: 千影,cx9208
  9. # Blog: https://www.939.me/
  10. # 推荐使用5.5以上内核直接开启的bbr速度最佳
  11. #=================================================
  12. sh_ver="1.4.0"
  13. github="raw.githubusercontent.com/chiakge/Linux-NetSpeed/master"
  14. 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"
  15. Info="${Green_font_prefix}[信息]${Font_color_suffix}"
  16. Error="${Red_font_prefix}[错误]${Font_color_suffix}"
  17. Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
  18. #安装BBR内核
  19. installbbr(){
  20. kernel_version="4.11.8"
  21. if [[ "${release}" == "centos" ]]; then
  22. rpm --import http://${github}/bbr/${release}/RPM-GPG-KEY-elrepo.org
  23. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-${kernel_version}.rpm
  24. yum remove -y kernel-headers
  25. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-headers-${kernel_version}.rpm
  26. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-devel-${kernel_version}.rpm
  27. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  28. mkdir bbr && cd bbr
  29. wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.1d-0+deb10u2_amd64.deb
  30. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/linux-headers-${kernel_version}-all.deb
  31. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
  32. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
  33. dpkg -i libssl1.1_1.1.1d-0+deb10u2_amd64.deb
  34. dpkg -i linux-headers-${kernel_version}-all.deb
  35. dpkg -i linux-headers-${kernel_version}.deb
  36. dpkg -i linux-image-${kernel_version}.deb
  37. cd .. && rm -rf bbr
  38. fi
  39. detele_kernel
  40. BBR_grub
  41. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBR/BBR魔改版${Font_color_suffix}"
  42. stty erase '^H' && read -p "需要重启VPS后,才能开启BBR/BBR魔改版,是否现在重启 ? [Y/n] :" yn
  43. [ -z "${yn}" ] && yn="y"
  44. if [[ $yn == [Yy] ]]; then
  45. echo -e "${Info} VPS 重启中..."
  46. reboot
  47. fi
  48. }
  49. #安装BBRplus内核
  50. installbbrplus(){
  51. kernel_version="4.14.129-bbrplus"
  52. if [[ "${release}" == "centos" ]]; then
  53. wget -N --no-check-certificate https://${github}/bbrplus/${release}/${version}/kernel-${kernel_version}.rpm
  54. yum install -y kernel-${kernel_version}.rpm
  55. rm -f kernel-${kernel_version}.rpm
  56. kernel_version="4.14.129_bbrplus" #fix a bug
  57. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  58. mkdir bbrplus && cd bbrplus
  59. wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
  60. wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
  61. dpkg -i linux-headers-${kernel_version}.deb
  62. dpkg -i linux-image-${kernel_version}.deb
  63. cd .. && rm -rf bbrplus
  64. fi
  65. detele_kernel
  66. BBR_grub
  67. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBRplus${Font_color_suffix}"
  68. stty erase '^H' && read -p "需要重启VPS后,才能开启BBRplus,是否现在重启 ? [Y/n] :" yn
  69. [ -z "${yn}" ] && yn="y"
  70. if [[ $yn == [Yy] ]]; then
  71. echo -e "${Info} VPS 重启中..."
  72. reboot
  73. fi
  74. }
  75. #安装Lotserver内核
  76. installlot(){
  77. if [[ "${release}" == "centos" ]]; then
  78. rpm --import http://${github}/lotserver/${release}/RPM-GPG-KEY-elrepo.org
  79. yum remove -y kernel-firmware
  80. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-firmware-${kernel_version}.rpm
  81. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-${kernel_version}.rpm
  82. yum remove -y kernel-headers
  83. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-headers-${kernel_version}.rpm
  84. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-devel-${kernel_version}.rpm
  85. elif [[ "${release}" == "ubuntu" ]]; then
  86. bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
  87. elif [[ "${release}" == "debian" ]]; then
  88. bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
  89. fi
  90. detele_kernel
  91. BBR_grub
  92. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}Lotserver${Font_color_suffix}"
  93. stty erase '^H' && read -p "需要重启VPS后,才能开启Lotserver,是否现在重启 ? [Y/n] :" yn
  94. [ -z "${yn}" ] && yn="y"
  95. if [[ $yn == [Yy] ]]; then
  96. echo -e "${Info} VPS 重启中..."
  97. reboot
  98. fi
  99. }
  100. #启用BBR
  101. startbbr(){
  102. remove_all
  103. if [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` -ge "5" ]]; then
  104. echo "net.core.default_qdisc=cake" >> /etc/sysctl.conf
  105. echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
  106. else
  107. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  108. echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
  109. fi
  110. sysctl -p
  111. echo -e "${Info}BBR启动成功!"
  112. }
  113. #启用BBRplus
  114. startbbrplus(){
  115. remove_all
  116. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  117. echo "net.ipv4.tcp_congestion_control=bbrplus" >> /etc/sysctl.conf
  118. sysctl -p
  119. echo -e "${Info}BBRplus启动成功!"
  120. }
  121. #编译并启用BBR魔改
  122. startbbrmod(){
  123. remove_all
  124. if [[ "${release}" == "centos" ]]; then
  125. yum install -y make gcc
  126. mkdir bbrmod && cd bbrmod
  127. wget -N --no-check-certificate http://${github}/bbr/tcp_tsunami.c
  128. echo "obj-m:=tcp_tsunami.o" > Makefile
  129. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
  130. chmod +x ./tcp_tsunami.ko
  131. cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  132. insmod tcp_tsunami.ko
  133. depmod -a
  134. else
  135. apt-get update
  136. if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
  137. apt-get -y install build-essential
  138. apt-get -y install software-properties-common
  139. add-apt-repository ppa:ubuntu-toolchain-r/test -y
  140. apt-get update
  141. fi
  142. apt-get -y install make gcc
  143. mkdir bbrmod && cd bbrmod
  144. wget -N --no-check-certificate http://${github}/bbr/tcp_tsunami.c
  145. echo "obj-m:=tcp_tsunami.o" > Makefile
  146. ln -s /usr/bin/gcc /usr/bin/gcc-4.9
  147. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
  148. install tcp_tsunami.ko /lib/modules/$(uname -r)/kernel
  149. cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  150. depmod -a
  151. fi
  152. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  153. echo "net.ipv4.tcp_congestion_control=tsunami" >> /etc/sysctl.conf
  154. sysctl -p
  155. cd .. && rm -rf bbrmod
  156. echo -e "${Info}魔改版BBR启动成功!"
  157. }
  158. #编译并启用BBR魔改
  159. startbbrmod_nanqinlang(){
  160. remove_all
  161. if [[ "${release}" == "centos" ]]; then
  162. yum install -y make gcc
  163. mkdir bbrmod && cd bbrmod
  164. wget -N --no-check-certificate https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/bbr/centos/tcp_nanqinlang.c
  165. echo "obj-m := tcp_nanqinlang.o" > Makefile
  166. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
  167. chmod +x ./tcp_nanqinlang.ko
  168. cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  169. insmod tcp_nanqinlang.ko
  170. depmod -a
  171. else
  172. apt-get update
  173. if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
  174. apt-get -y install build-essential
  175. apt-get -y install software-properties-common
  176. add-apt-repository ppa:ubuntu-toolchain-r/test -y
  177. apt-get update
  178. fi
  179. apt-get -y install make gcc-4.9
  180. mkdir bbrmod && cd bbrmod
  181. wget -N --no-check-certificate https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/bbr/tcp_nanqinlang.c
  182. echo "obj-m := tcp_nanqinlang.o" > Makefile
  183. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
  184. install tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel
  185. cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  186. depmod -a
  187. fi
  188. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  189. echo "net.ipv4.tcp_congestion_control=nanqinlang" >> /etc/sysctl.conf
  190. sysctl -p
  191. echo -e "${Info}魔改版BBR启动成功!"
  192. }
  193. #启用Lotserver
  194. startlotserver(){
  195. remove_all
  196. if [[ "${release}" == "centos" ]]; then
  197. yum install ethtool
  198. else
  199. apt-get update
  200. apt-get install ethtool
  201. fi
  202. bash <(wget --no-check-certificate -qO- https://raw.githubusercontent.com/chiakge/lotServer/master/Install.sh) install
  203. sed -i '/advinacc/d' /appex/etc/config
  204. sed -i '/maxmode/d' /appex/etc/config
  205. echo -e "advinacc=\"1\"
  206. maxmode=\"1\"">>/appex/etc/config
  207. /appex/bin/lotServer.sh restart
  208. start_menu
  209. }
  210. #卸载全部加速
  211. remove_all(){
  212. rm -rf bbrmod
  213. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  214. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
  215. sed -i '/fs.file-max/d' /etc/sysctl.conf
  216. sed -i '/net.core.rmem_default/d' /etc/sysctl.conf
  217. sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
  218. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  219. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  220. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  221. sed -i '/net.ipv4.tcp_tw_recycle/d' /etc/sysctl.conf
  222. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  223. sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.conf
  224. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  225. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  226. sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf
  227. sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf
  228. sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.conf
  229. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  230. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  231. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  232. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  233. sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
  234. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
  235. sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
  236. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
  237. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
  238. sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
  239. sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
  240. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  241. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  242. sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.conf
  243. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  244. if [[ -e /appex/bin/lotServer.sh ]]; then
  245. bash <(wget --no-check-certificate -qO- https://github.com/MoeClub/lotServer/raw/master/Install.sh) uninstall
  246. fi
  247. clear
  248. echo -e "${Info}:清除加速完成。"
  249. sleep 1s
  250. }
  251. #优化系统配置
  252. optimizing_system(){
  253. sed -i '/fs.file-max/d' /etc/sysctl.conf
  254. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  255. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  256. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  257. sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf
  258. sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf
  259. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  260. sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
  261. sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
  262. sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
  263. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  264. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  265. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  266. sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.conf
  267. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  268. echo "fs.file-max = 1000000
  269. fs.inotify.max_user_instances = 8192
  270. net.ipv4.tcp_tw_reuse = 1
  271. net.ipv4.ip_local_port_range = 1024 65535
  272. net.ipv4.tcp_rmem = 16384 262144 8388608
  273. net.ipv4.tcp_wmem = 32768 524288 16777216
  274. net.core.somaxconn = 8192
  275. net.core.rmem_max = 16777216
  276. net.core.wmem_max = 16777216
  277. net.core.wmem_default = 2097152
  278. net.ipv4.tcp_max_tw_buckets = 5000
  279. net.ipv4.tcp_max_syn_backlog = 10240
  280. net.core.netdev_max_backlog = 10240
  281. net.ipv4.tcp_slow_start_after_idle = 0
  282. # forward ipv4
  283. net.ipv4.ip_forward = 1">>/etc/sysctl.conf
  284. sysctl -p
  285. echo "* soft nofile 1000000
  286. * hard nofile 1000000">/etc/security/limits.conf
  287. echo "ulimit -SHn 1000000">>/etc/profile
  288. read -p "需要重启VPS后,才能生效系统优化配置,是否现在重启 ? [Y/n] :" yn
  289. [ -z "${yn}" ] && yn="y"
  290. if [[ $yn == [Yy] ]]; then
  291. echo -e "${Info} VPS 重启中..."
  292. reboot
  293. fi
  294. }
  295. #更新脚本
  296. Update_Shell(){
  297. echo -e "当前版本为 [ ${sh_ver} ],开始检测最新版本..."
  298. sh_new_ver=$(wget --no-check-certificate -qO- "http://${github}/tcp.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
  299. [[ -z ${sh_new_ver} ]] && echo -e "${Error} 检测最新版本失败 !" && start_menu
  300. if [[ ${sh_new_ver} != ${sh_ver} ]]; then
  301. echo -e "发现新版本[ ${sh_new_ver} ],是否更新?[Y/n]"
  302. read -p "(默认: y):" yn
  303. [[ -z "${yn}" ]] && yn="y"
  304. if [[ ${yn} == [Yy] ]]; then
  305. wget -N --no-check-certificate http://${github}/tcp.sh && chmod +x tcp.sh
  306. echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !"
  307. else
  308. echo && echo " 已取消..." && echo
  309. fi
  310. else
  311. echo -e "当前已是最新版本[ ${sh_new_ver} ] !"
  312. sleep 5s
  313. fi
  314. }
  315. #开始菜单
  316. start_menu(){
  317. clear
  318. echo && echo -e " TCP加速 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
  319. -- 就是爱生活 | 94ish.me --
  320. ${Green_font_prefix}0.${Font_color_suffix} 升级脚本
  321. ————————————内核管理————————————
  322. ${Green_font_prefix}1.${Font_color_suffix} 安装 BBR/BBR魔改版内核
  323. ${Green_font_prefix}2.${Font_color_suffix} 安装 BBRplus版内核
  324. ${Green_font_prefix}3.${Font_color_suffix} 安装 Lotserver(锐速)内核
  325. ————————————加速管理————————————
  326. ${Green_font_prefix}4.${Font_color_suffix} 使用BBR加速
  327. ${Green_font_prefix}5.${Font_color_suffix} 使用BBR魔改版加速
  328. ${Green_font_prefix}6.${Font_color_suffix} 使用暴力BBR魔改版加速(不支持部分系统)
  329. ${Green_font_prefix}7.${Font_color_suffix} 使用BBRplus版加速
  330. ${Green_font_prefix}8.${Font_color_suffix} 使用Lotserver(锐速)加速
  331. ————————————杂项管理————————————
  332. ${Green_font_prefix}9.${Font_color_suffix} 卸载全部加速
  333. ${Green_font_prefix}10.${Font_color_suffix} 系统配置优化
  334. ${Green_font_prefix}11.${Font_color_suffix} 退出脚本
  335. ————————————————————————————————" && echo
  336. check_status
  337. if [[ ${kernel_status} == "noinstall" ]]; then
  338. echo -e " 当前状态: ${Green_font_prefix}未安装${Font_color_suffix} 加速内核 ${Red_font_prefix}请先安装内核${Font_color_suffix}"
  339. else
  340. echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} ${_font_prefix}${kernel_status}${Font_color_suffix} 加速内核 , ${Green_font_prefix}${run_status}${Font_color_suffix}"
  341. fi
  342. echo
  343. read -p " 请输入数字 [0-11]:" num
  344. case "$num" in
  345. 0)
  346. Update_Shell
  347. ;;
  348. 1)
  349. check_sys_bbr
  350. ;;
  351. 2)
  352. check_sys_bbrplus
  353. ;;
  354. 3)
  355. check_sys_Lotsever
  356. ;;
  357. 4)
  358. startbbr
  359. ;;
  360. 5)
  361. startbbrmod
  362. ;;
  363. 6)
  364. startbbrmod_nanqinlang
  365. ;;
  366. 7)
  367. startbbrplus
  368. ;;
  369. 8)
  370. startlotserver
  371. ;;
  372. 9)
  373. remove_all
  374. ;;
  375. 10)
  376. optimizing_system
  377. ;;
  378. 11)
  379. exit 1
  380. ;;
  381. *)
  382. clear
  383. echo -e "${Error}:请输入正确数字 [0-11]"
  384. sleep 5s
  385. start_menu
  386. ;;
  387. esac
  388. }
  389. #############内核管理组件#############
  390. #删除多余内核
  391. detele_kernel(){
  392. if [[ "${release}" == "centos" ]]; then
  393. rpm_total=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l`
  394. if [ "${rpm_total}" > "1" ]; then
  395. echo -e "检测到 ${rpm_total} 个其余内核,开始卸载..."
  396. for((integer = 1; integer <= ${rpm_total}; integer++)); do
  397. rpm_del=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer}`
  398. echo -e "开始卸载 ${rpm_del} 内核..."
  399. rpm --nodeps -e ${rpm_del}
  400. echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
  401. done
  402. echo --nodeps -e "内核卸载完毕,继续..."
  403. else
  404. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  405. fi
  406. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  407. deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
  408. if [ "${deb_total}" > "1" ]; then
  409. echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
  410. for((integer = 1; integer <= ${deb_total}; integer++)); do
  411. deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
  412. echo -e "开始卸载 ${deb_del} 内核..."
  413. apt-get purge -y ${deb_del}
  414. echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
  415. done
  416. echo -e "内核卸载完毕,继续..."
  417. else
  418. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  419. fi
  420. fi
  421. }
  422. #更新引导
  423. BBR_grub(){
  424. if [[ "${release}" == "centos" ]]; then
  425. if [[ ${version} = "6" ]]; then
  426. if [ ! -f "/boot/grub/grub.conf" ]; then
  427. echo -e "${Error} /boot/grub/grub.conf 找不到,请检查."
  428. exit 1
  429. fi
  430. sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
  431. elif [[ ${version} = "7" ]]; then
  432. if [ ! -f "/boot/grub2/grub.cfg" ]; then
  433. echo -e "${Error} /boot/grub2/grub.cfg 找不到,请检查."
  434. exit 1
  435. fi
  436. grub2-set-default 0
  437. fi
  438. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  439. /usr/sbin/update-grub
  440. fi
  441. }
  442. #############内核管理组件#############
  443. #############系统检测组件#############
  444. #检查系统
  445. check_sys(){
  446. if [[ -f /etc/redhat-release ]]; then
  447. release="centos"
  448. elif cat /etc/issue | grep -q -E -i "debian"; then
  449. release="debian"
  450. elif cat /etc/issue | grep -q -E -i "ubuntu"; then
  451. release="ubuntu"
  452. elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
  453. release="centos"
  454. elif cat /proc/version | grep -q -E -i "debian"; then
  455. release="debian"
  456. elif cat /proc/version | grep -q -E -i "ubuntu"; then
  457. release="ubuntu"
  458. elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
  459. release="centos"
  460. fi
  461. }
  462. #检查Linux版本
  463. check_version(){
  464. if [[ -s /etc/redhat-release ]]; then
  465. version=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
  466. else
  467. version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
  468. fi
  469. bit=`uname -m`
  470. if [[ ${bit} = "x86_64" ]]; then
  471. bit="x64"
  472. else
  473. bit="x32"
  474. fi
  475. }
  476. #检查安装bbr的系统要求
  477. check_sys_bbr(){
  478. check_version
  479. if [[ "${release}" == "centos" ]]; then
  480. if [[ ${version} -ge "6" ]]; then
  481. installbbr
  482. else
  483. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  484. fi
  485. elif [[ "${release}" == "debian" ]]; then
  486. if [[ ${version} -ge "8" ]]; then
  487. installbbr
  488. else
  489. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  490. fi
  491. elif [[ "${release}" == "ubuntu" ]]; then
  492. if [[ ${version} -ge "14" ]]; then
  493. installbbr
  494. else
  495. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  496. fi
  497. else
  498. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  499. fi
  500. }
  501. check_sys_bbrplus(){
  502. check_version
  503. if [[ "${release}" == "centos" ]]; then
  504. if [[ ${version} -ge "6" ]]; then
  505. installbbrplus
  506. else
  507. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  508. fi
  509. elif [[ "${release}" == "debian" ]]; then
  510. if [[ ${version} -ge "8" ]]; then
  511. installbbrplus
  512. else
  513. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  514. fi
  515. elif [[ "${release}" == "ubuntu" ]]; then
  516. if [[ ${version} -ge "14" ]]; then
  517. installbbrplus
  518. else
  519. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  520. fi
  521. else
  522. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  523. fi
  524. }
  525. #检查安装Lotsever的系统要求
  526. check_sys_Lotsever(){
  527. check_version
  528. if [[ "${release}" == "centos" ]]; then
  529. if [[ ${version} == "6" ]]; then
  530. kernel_version="2.6.32-504"
  531. installlot
  532. elif [[ ${version} == "7" ]]; then
  533. yum -y install net-tools
  534. kernel_version="3.10.0-327"
  535. installlot
  536. else
  537. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  538. fi
  539. elif [[ "${release}" == "debian" ]]; then
  540. if [[ ${version} = "7" || ${version} = "8" ]]; then
  541. if [[ ${bit} == "x64" ]]; then
  542. kernel_version="3.16.0-4"
  543. installlot
  544. elif [[ ${bit} == "x32" ]]; then
  545. kernel_version="3.2.0-4"
  546. installlot
  547. fi
  548. elif [[ ${version} = "9" ]]; then
  549. if [[ ${bit} == "x64" ]]; then
  550. kernel_version="4.9.0-4"
  551. installlot
  552. fi
  553. else
  554. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  555. fi
  556. elif [[ "${release}" == "ubuntu" ]]; then
  557. if [[ ${version} -ge "12" ]]; then
  558. if [[ ${bit} == "x64" ]]; then
  559. kernel_version="4.8.0-36"
  560. installlot
  561. elif [[ ${bit} == "x32" ]]; then
  562. kernel_version="3.13.0-29"
  563. installlot
  564. fi
  565. else
  566. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  567. fi
  568. else
  569. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  570. fi
  571. }
  572. check_status(){
  573. kernel_version=`uname -r | awk -F "-" '{print $1}'`
  574. kernel_version_full=`uname -r`
  575. if [[ ${kernel_version_full} = "4.14.129-bbrplus" ]]; then
  576. kernel_status="BBRplus"
  577. 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
  578. kernel_status="Lotserver"
  579. 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
  580. kernel_status="BBR"
  581. else
  582. kernel_status="noinstall"
  583. fi
  584. if [[ ${kernel_status} == "Lotserver" ]]; then
  585. if [[ -e /appex/bin/lotServer.sh ]]; then
  586. run_status=`bash /appex/bin/lotServer.sh status | grep "LotServer" | awk '{print $3}'`
  587. if [[ ${run_status} = "running!" ]]; then
  588. run_status="启动成功"
  589. else
  590. run_status="启动失败"
  591. fi
  592. else
  593. run_status="未安装加速模块"
  594. fi
  595. elif [[ ${kernel_status} == "BBR" ]]; then
  596. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{gsub("^[ \t]+|[ \t]+$", "", $2);print $2}'`
  597. if [[ ${run_status} == "bbr" ]]; then
  598. run_status=`lsmod | grep "bbr" | awk '{print $1}'`
  599. if [[ ${run_status} == "tcp_bbr" ]]; then
  600. run_status="BBR启动成功"
  601. else
  602. run_status="BBR启动失败"
  603. fi
  604. elif [[ ${run_status} == "tsunami" ]]; then
  605. run_status=`lsmod | grep "tsunami" | awk '{print $1}'`
  606. if [[ ${run_status} == "tcp_tsunami" ]]; then
  607. run_status="BBR魔改版启动成功"
  608. else
  609. run_status="BBR魔改版启动失败"
  610. fi
  611. elif [[ ${run_status} == "nanqinlang" ]]; then
  612. run_status=`lsmod | grep "nanqinlang" | awk '{print $1}'`
  613. if [[ ${run_status} == "tcp_nanqinlang" ]]; then
  614. run_status="暴力BBR魔改版启动成功"
  615. else
  616. run_status="暴力BBR魔改版启动失败"
  617. fi
  618. else
  619. run_status="未安装加速模块"
  620. fi
  621. elif [[ ${kernel_status} == "BBRplus" ]]; then
  622. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{gsub("^[ \t]+|[ \t]+$", "", $2);print $2}'`
  623. if [[ ${run_status} == "bbrplus" ]]; then
  624. run_status=`lsmod | grep "bbrplus" | awk '{print $1}'`
  625. if [[ ${run_status} == "tcp_bbrplus" ]]; then
  626. run_status="BBRplus启动成功"
  627. else
  628. run_status="BBRplus启动失败"
  629. fi
  630. else
  631. run_status="未安装加速模块"
  632. fi
  633. fi
  634. }
  635. #############系统检测组件#############
  636. check_sys
  637. check_version
  638. [[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
  639. start_menu