tcp.sh 23 KB

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