tcp.sh 23 KB

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