tcp.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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://moeclub.org/attachment/LinuxShell/Debian_Kernel.sh')
  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/serverSpeeder.sh ]]; then
  231. wget --no-check-certificate -O appex.sh https://raw.githubusercontent.com/0oVicero0/serverSpeeder_Install/master/appex.sh && chmod +x appex.sh && bash appex.sh uninstall
  232. rm -f appex.sh
  233. fi
  234. clear
  235. echo -e "${Info}:清除加速完成。"
  236. sleep 1s
  237. }
  238. #优化系统配置
  239. optimizing_system(){
  240. sed -i '/fs.file-max/d' /etc/sysctl.conf
  241. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  242. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  243. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  244. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  245. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  246. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  247. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  248. sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
  249. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
  250. sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
  251. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  252. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  253. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
  254. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
  255. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  256. echo "fs.file-max = 1000000
  257. fs.inotify.max_user_instances = 8192
  258. net.ipv4.tcp_syncookies = 1
  259. net.ipv4.tcp_fin_timeout = 30
  260. net.ipv4.tcp_tw_reuse = 1
  261. net.ipv4.ip_local_port_range = 1024 65000
  262. net.ipv4.tcp_max_syn_backlog = 16384
  263. net.ipv4.tcp_max_tw_buckets = 6000
  264. net.ipv4.route.gc_timeout = 100
  265. net.ipv4.tcp_syn_retries = 1
  266. net.ipv4.tcp_synack_retries = 1
  267. net.core.somaxconn = 32768
  268. net.core.netdev_max_backlog = 32768
  269. net.ipv4.tcp_timestamps = 0
  270. net.ipv4.tcp_max_orphans = 32768
  271. # forward ipv4
  272. net.ipv4.ip_forward = 1">>/etc/sysctl.conf
  273. sysctl -p
  274. echo "* soft nofile 1000000
  275. * hard nofile 1000000">/etc/security/limits.conf
  276. echo "ulimit -SHn 1000000">>/etc/profile
  277. read -p "需要重启VPS后,才能生效系统优化配置,是否现在重启 ? [Y/n] :" yn
  278. [ -z "${yn}" ] && yn="y"
  279. if [[ $yn == [Yy] ]]; then
  280. echo -e "${Info} VPS 重启中..."
  281. reboot
  282. fi
  283. }
  284. #更新脚本
  285. Update_Shell(){
  286. echo -e "当前版本为 [ ${sh_ver} ],开始检测最新版本..."
  287. sh_new_ver=$(wget --no-check-certificate -qO- "http://${github}/tcp.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
  288. [[ -z ${sh_new_ver} ]] && echo -e "${Error} 检测最新版本失败 !" && start_menu
  289. if [[ ${sh_new_ver} != ${sh_ver} ]]; then
  290. echo -e "发现新版本[ ${sh_new_ver} ],是否更新?[Y/n]"
  291. read -p "(默认: y):" yn
  292. [[ -z "${yn}" ]] && yn="y"
  293. if [[ ${yn} == [Yy] ]]; then
  294. wget -N --no-check-certificate http://${github}/tcp.sh && chmod +x tcp.sh
  295. echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !"
  296. else
  297. echo && echo " 已取消..." && echo
  298. fi
  299. else
  300. echo -e "当前已是最新版本[ ${sh_new_ver} ] !"
  301. sleep 5s
  302. fi
  303. }
  304. #开始菜单
  305. start_menu(){
  306. clear
  307. echo && echo -e " TCP加速 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
  308. -- 就是爱生活 | 94ish.me --
  309. ${Green_font_prefix}0.${Font_color_suffix} 升级脚本
  310. ————————————内核管理————————————
  311. ${Green_font_prefix}1.${Font_color_suffix} 安装 BBR/BBR魔改版内核
  312. ${Green_font_prefix}2.${Font_color_suffix} 安装 BBRplus版内核
  313. ${Green_font_prefix}3.${Font_color_suffix} 安装 Lotserver(锐速)内核
  314. ————————————加速管理————————————
  315. ${Green_font_prefix}4.${Font_color_suffix} 使用BBR加速
  316. ${Green_font_prefix}5.${Font_color_suffix} 使用BBR魔改版加速
  317. ${Green_font_prefix}6.${Font_color_suffix} 使用暴力BBR魔改版加速(不支持部分系统)
  318. ${Green_font_prefix}7.${Font_color_suffix} 使用BBRplus版加速
  319. ${Green_font_prefix}8.${Font_color_suffix} 使用Lotserver(锐速)加速
  320. ————————————杂项管理————————————
  321. ${Green_font_prefix}9.${Font_color_suffix} 卸载全部加速
  322. ${Green_font_prefix}10.${Font_color_suffix} 系统配置优化
  323. ${Green_font_prefix}11.${Font_color_suffix} 退出脚本
  324. ————————————————————————————————" && echo
  325. check_status
  326. if [[ ${kernel_status} == "noinstall" ]]; then
  327. echo -e " 当前状态: ${Green_font_prefix}未安装${Font_color_suffix} 加速内核 ${Red_font_prefix}请先安装内核${Font_color_suffix}"
  328. else
  329. echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} ${_font_prefix}${kernel_status}${Font_color_suffix} 加速内核 , ${Green_font_prefix}${run_status}${Font_color_suffix}"
  330. fi
  331. echo
  332. read -p " 请输入数字 [0-11]:" num
  333. case "$num" in
  334. 0)
  335. Update_Shell
  336. ;;
  337. 1)
  338. check_sys_bbr
  339. ;;
  340. 2)
  341. check_sys_bbrplus
  342. ;;
  343. 3)
  344. check_sys_Lotsever
  345. ;;
  346. 4)
  347. startbbr
  348. ;;
  349. 5)
  350. startbbrmod
  351. ;;
  352. 6)
  353. startbbrmod_nanqinlang
  354. ;;
  355. 7)
  356. startbbrplus
  357. ;;
  358. 8)
  359. startlotserver
  360. ;;
  361. 9)
  362. remove_all
  363. ;;
  364. 10)
  365. optimizing_system
  366. ;;
  367. 11)
  368. exit 1
  369. ;;
  370. *)
  371. clear
  372. echo -e "${Error}:请输入正确数字 [0-11]"
  373. sleep 5s
  374. start_menu
  375. ;;
  376. esac
  377. }
  378. #############内核管理组件#############
  379. #删除多余内核
  380. detele_kernel(){
  381. if [[ "${release}" == "centos" ]]; then
  382. rpm_total=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l`
  383. if [ "${rpm_total}" > "1" ]; then
  384. echo -e "检测到 ${rpm_total} 个其余内核,开始卸载..."
  385. for((integer = 1; integer <= ${rpm_total}; integer++)); do
  386. rpm_del=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer}`
  387. echo -e "开始卸载 ${rpm_del} 内核..."
  388. rpm --nodeps -e ${rpm_del}
  389. echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
  390. done
  391. echo --nodeps -e "内核卸载完毕,继续..."
  392. else
  393. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  394. fi
  395. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  396. deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
  397. if [ "${deb_total}" > "1" ]; then
  398. echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
  399. for((integer = 1; integer <= ${deb_total}; integer++)); do
  400. deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
  401. echo -e "开始卸载 ${deb_del} 内核..."
  402. apt-get purge -y ${deb_del}
  403. echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
  404. done
  405. echo -e "内核卸载完毕,继续..."
  406. else
  407. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  408. fi
  409. fi
  410. }
  411. #更新引导
  412. BBR_grub(){
  413. if [[ "${release}" == "centos" ]]; then
  414. if [[ ${version} = "6" ]]; then
  415. if [ ! -f "/boot/grub/grub.conf" ]; then
  416. echo -e "${Error} /boot/grub/grub.conf 找不到,请检查."
  417. exit 1
  418. fi
  419. sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
  420. elif [[ ${version} = "7" ]]; then
  421. if [ ! -f "/boot/grub2/grub.cfg" ]; then
  422. echo -e "${Error} /boot/grub2/grub.cfg 找不到,请检查."
  423. exit 1
  424. fi
  425. grub2-set-default 0
  426. fi
  427. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  428. /usr/sbin/update-grub
  429. fi
  430. }
  431. #############内核管理组件#############
  432. #############系统检测组件#############
  433. #检查系统
  434. check_sys(){
  435. if [[ -f /etc/redhat-release ]]; then
  436. release="centos"
  437. elif cat /etc/issue | grep -q -E -i "debian"; then
  438. release="debian"
  439. elif cat /etc/issue | grep -q -E -i "ubuntu"; then
  440. release="ubuntu"
  441. elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
  442. release="centos"
  443. elif cat /proc/version | grep -q -E -i "debian"; then
  444. release="debian"
  445. elif cat /proc/version | grep -q -E -i "ubuntu"; then
  446. release="ubuntu"
  447. elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
  448. release="centos"
  449. fi
  450. }
  451. #检查Linux版本
  452. check_version(){
  453. if [[ -s /etc/redhat-release ]]; then
  454. version=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
  455. else
  456. version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
  457. fi
  458. bit=`uname -m`
  459. if [[ ${bit} = "x86_64" ]]; then
  460. bit="x64"
  461. else
  462. bit="x32"
  463. fi
  464. }
  465. #检查安装bbr的系统要求
  466. check_sys_bbr(){
  467. check_version
  468. if [[ "${release}" == "centos" ]]; then
  469. if [[ ${version} -ge "6" ]]; then
  470. installbbr
  471. else
  472. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  473. fi
  474. elif [[ "${release}" == "debian" ]]; then
  475. if [[ ${version} -ge "8" ]]; then
  476. installbbr
  477. else
  478. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  479. fi
  480. elif [[ "${release}" == "ubuntu" ]]; then
  481. if [[ ${version} -ge "14" ]]; then
  482. installbbr
  483. else
  484. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  485. fi
  486. else
  487. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  488. fi
  489. }
  490. check_sys_bbrplus(){
  491. check_version
  492. if [[ "${release}" == "centos" ]]; then
  493. if [[ ${version} -ge "6" ]]; then
  494. installbbrplus
  495. else
  496. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  497. fi
  498. elif [[ "${release}" == "debian" ]]; then
  499. if [[ ${version} -ge "8" ]]; then
  500. installbbrplus
  501. else
  502. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  503. fi
  504. elif [[ "${release}" == "ubuntu" ]]; then
  505. if [[ ${version} -ge "14" ]]; then
  506. installbbrplus
  507. else
  508. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  509. fi
  510. else
  511. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  512. fi
  513. }
  514. #检查安装Lotsever的系统要求
  515. check_sys_Lotsever(){
  516. check_version
  517. if [[ "${release}" == "centos" ]]; then
  518. if [[ ${version} == "6" ]]; then
  519. kernel_version="2.6.32-504"
  520. installlot
  521. elif [[ ${version} == "7" ]]; then
  522. yum -y install net-tools
  523. kernel_version="3.10.0-327"
  524. installlot
  525. else
  526. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  527. fi
  528. elif [[ "${release}" == "debian" ]]; then
  529. if [[ ${version} = "7" || ${version} = "8" ]]; then
  530. if [[ ${bit} == "x64" ]]; then
  531. kernel_version="3.16.0-4"
  532. installlot
  533. elif [[ ${bit} == "x32" ]]; then
  534. kernel_version="3.2.0-4"
  535. installlot
  536. fi
  537. elif [[ ${version} = "9" ]]; then
  538. if [[ ${bit} == "x64" ]]; then
  539. kernel_version="4.9.0-4"
  540. installlot
  541. fi
  542. else
  543. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  544. fi
  545. elif [[ "${release}" == "ubuntu" ]]; then
  546. if [[ ${version} -ge "12" ]]; then
  547. if [[ ${bit} == "x64" ]]; then
  548. kernel_version="4.4.0-47"
  549. installlot
  550. elif [[ ${bit} == "x32" ]]; then
  551. kernel_version="3.13.0-29"
  552. installlot
  553. fi
  554. else
  555. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  556. fi
  557. else
  558. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  559. fi
  560. }
  561. check_status(){
  562. kernel_version=`uname -r | awk -F "-" '{print $1}'`
  563. kernel_version_full=`uname -r`
  564. if [[ ${kernel_version_full} = "4.14.91-bbrplus" ]]; then
  565. kernel_status="BBRplus"
  566. 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
  567. kernel_status="Lotserver"
  568. 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
  569. kernel_status="BBR"
  570. else
  571. kernel_status="noinstall"
  572. fi
  573. if [[ ${kernel_status} == "Lotserver" ]]; then
  574. if [[ -e /appex/bin/serverSpeeder.sh ]]; then
  575. run_status=`bash /appex/bin/lotServer.sh status | grep "ServerSpeeder" | awk '{print $3}'`
  576. if [[ ${run_status} = "running!" ]]; then
  577. run_status="启动成功"
  578. else
  579. run_status="启动失败"
  580. fi
  581. else
  582. run_status="未安装加速模块"
  583. fi
  584. elif [[ ${kernel_status} == "BBR" ]]; then
  585. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
  586. if [[ ${run_status} == "bbr" ]]; then
  587. run_status=`lsmod | grep "bbr" | awk '{print $1}'`
  588. if [[ ${run_status} == "tcp_bbr" ]]; then
  589. run_status="BBR启动成功"
  590. else
  591. run_status="BBR启动失败"
  592. fi
  593. elif [[ ${run_status} == "tsunami" ]]; then
  594. run_status=`lsmod | grep "tsunami" | awk '{print $1}'`
  595. if [[ ${run_status} == "tcp_tsunami" ]]; then
  596. run_status="BBR魔改版启动成功"
  597. else
  598. run_status="BBR魔改版启动失败"
  599. fi
  600. elif [[ ${run_status} == "nanqinlang" ]]; then
  601. run_status=`lsmod | grep "nanqinlang" | awk '{print $1}'`
  602. if [[ ${run_status} == "tcp_nanqinlang" ]]; then
  603. run_status="暴力BBR魔改版启动成功"
  604. else
  605. run_status="暴力BBR魔改版启动失败"
  606. fi
  607. else
  608. run_status="未安装加速模块"
  609. fi
  610. elif [[ ${kernel_status} == "BBRplus" ]]; then
  611. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
  612. if [[ ${run_status} == "bbrplus" ]]; then
  613. run_status=`lsmod | grep "bbrplus" | awk '{print $1}'`
  614. if [[ ${run_status} == "tcp_bbrplus" ]]; then
  615. run_status="BBRplus启动成功"
  616. else
  617. run_status="BBRplus启动失败"
  618. fi
  619. else
  620. run_status="未安装加速模块"
  621. fi
  622. fi
  623. }
  624. #############系统检测组件#############
  625. check_sys
  626. check_version
  627. [[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
  628. start_menu