tcp.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #!/bin/bash
  2. #19/12/2019
  3. clear
  4. msg -bar
  5. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  6. export PATH
  7. SCPfrm="/etc/ger-frm" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
  8. BARRA1="\e[0;31m--------------------------------------------------------------------\e[0m"
  9. SCPinst="/etc/ger-inst" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
  10. #=================================================
  11. # System Required: CentOS 6/7,Debian 8/9,Ubuntu 16+
  12. # Description: BBR+BBRVersión mágica+BBRplus+Lotserver
  13. # Version: 1.3.1
  14. # Author: Mil sombras,cx9208
  15. # Blog: https://www.94ish.me/
  16. #=================================================
  17. sh_ver="1.3.1"
  18. github="raw.githubusercontent.com/cx9208/Linux-NetSpeed/master"
  19. 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"
  20. Info="${Green_font_prefix}[Informacion]${Font_color_suffix}"
  21. Error="${Red_font_prefix}[Error]${Font_color_suffix}"
  22. Tip="${Green_font_prefix}[Atencion]${Font_color_suffix}"
  23. #Instalar el núcleo BBR
  24. installbbr(){
  25. kernel_version="4.11.8"
  26. if [[ "${release}" == "centos" ]]; then
  27. rpm --import http://${github}/bbr/${release}/RPM-GPG-KEY-elrepo.org
  28. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-${kernel_version}.rpm
  29. yum remove -y kernel-headers
  30. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-headers-${kernel_version}.rpm
  31. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-devel-${kernel_version}.rpm
  32. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  33. mkdir bbr && cd bbr
  34. apt install libssl1.0.0 -y
  35. #wget https://debian.sipwise.com/debian-security/pool/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u10_amd64.deb
  36. #wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u12_amd64.deb
  37. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/linux-headers-${kernel_version}-all.deb
  38. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
  39. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
  40. #dpkg -i libssl1.0.0_1.0.1t-1+deb8u10_amd64.deb
  41. dpkg -i linux-headers-${kernel_version}-all.deb
  42. dpkg -i linux-headers-${kernel_version}.deb
  43. dpkg -i linux-image-${kernel_version}.deb
  44. cd .. && rm -rf bbr
  45. fi
  46. detele_kernel
  47. BBR_grub
  48. msg -bar
  49. echo -e "${Tip} Después de reiniciar el VPS, vuelva a ejecutar el script para abrir\n${Red_font_prefix} BBR/BBR Versión mágica${Font_color_suffix}"
  50. msg -bar
  51. stty erase '^H' && read -p "Debe reiniciar el VPS antes de poder habilitar BBR, reiniciar ahora. ? [Y/n] :" yn
  52. [ -z "${yn}" ] && yn="y"
  53. if [[ $yn == [Yy] ]]; then
  54. echo -e "${Info} VPS se reinicia ..."
  55. reboot
  56. fi
  57. }
  58. #Instale el núcleo BBRplus
  59. installbbrplus(){
  60. kernel_version="4.14.129-bbrplus"
  61. if [[ "${release}" == "centos" ]]; then
  62. wget -N --no-check-certificate https://${github}/bbrplus/${release}/${version}/kernel-${kernel_version}.rpm
  63. yum install -y kernel-${kernel_version}.rpm
  64. rm -f kernel-${kernel_version}.rpm
  65. kernel_version="4.14.129_bbrplus" #fix a bug
  66. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  67. mkdir bbrplus && cd bbrplus
  68. wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
  69. wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
  70. dpkg -i linux-headers-${kernel_version}.deb
  71. dpkg -i linux-image-${kernel_version}.deb
  72. cd .. && rm -rf bbrplus
  73. fi
  74. detele_kernel
  75. BBR_grub
  76. msg -bar
  77. echo -e "${Tip} Después de reiniciar el VPS, vuelva a ejecutar el script para abrir\n${Red_font_prefix} BBRplus${Font_color_suffix}"
  78. msg -bar
  79. stty erase '^H' && read -p "Debe reiniciar el VPS antes de poder habilitar BBRplus, reiniciar ahora ? [Y/n] :" yn
  80. [ -z "${yn}" ] && yn="y"
  81. if [[ $yn == [Yy] ]]; then
  82. echo -e "${Info} VPS se reinicia ..."
  83. reboot
  84. fi
  85. }
  86. #Instale el kernel de Lotserver
  87. installlot(){
  88. if [[ "${release}" == "centos" ]]; then
  89. rpm --import http://${github}/lotserver/${release}/RPM-GPG-KEY-elrepo.org
  90. yum remove -y kernel-firmware
  91. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-firmware-${kernel_version}.rpm
  92. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-${kernel_version}.rpm
  93. yum remove -y kernel-headers
  94. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-headers-${kernel_version}.rpm
  95. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-devel-${kernel_version}.rpm
  96. elif [[ "${release}" == "ubuntu" ]]; then
  97. bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
  98. elif [[ "${release}" == "debian" ]]; then
  99. bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
  100. fi
  101. detele_kernel
  102. BBR_grub
  103. msg -bar
  104. echo -e "${Tip} Después de reiniciar el VPS, vuelva a ejecutar el script para abrir\n${Red_font_prefix}Lotserver${Font_color_suffix}"
  105. msg -bar
  106. stty erase '^H' && read -p "Necesita reiniciar el VPS antes de poder abrir Lotserver, reiniciar ahora ? [Y/n] :" yn
  107. [ -z "${yn}" ] && yn="y"
  108. if [[ $yn == [Yy] ]]; then
  109. echo -e "${Info} VPS se reinicia ..."
  110. reboot
  111. fi
  112. }
  113. # Habilitar BBR
  114. startbbr(){
  115. remove_all
  116. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  117. echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
  118. sysctl -p
  119. echo -e "${Info}¡BBR comenzó con éxito!"
  120. msg -bar
  121. }
  122. #Habilitar BBRplus
  123. startbbrplus(){
  124. remove_all
  125. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  126. echo "net.ipv4.tcp_congestion_control=bbrplus" >> /etc/sysctl.conf
  127. sysctl -p
  128. echo -e "${Info}BBRplus comenzó con éxito!!"
  129. msg -bar
  130. }
  131. # Compilar y habilitar el cambio mágico BBR
  132. startbbrmod(){
  133. remove_all
  134. if [[ "${release}" == "centos" ]]; then
  135. yum install -y 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. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
  140. chmod +x ./tcp_tsunami.ko
  141. cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  142. insmod tcp_tsunami.ko
  143. depmod -a
  144. else
  145. apt-get update
  146. if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
  147. apt-get -y install build-essential
  148. apt-get -y install software-properties-common
  149. add-apt-repository ppa:ubuntu-toolchain-r/test -y
  150. apt-get update
  151. fi
  152. apt-get -y install make gcc
  153. mkdir bbrmod && cd bbrmod
  154. wget -N --no-check-certificate http://${github}/bbr/tcp_tsunami.c
  155. echo "obj-m:=tcp_tsunami.o" > Makefile
  156. ln -s /usr/bin/gcc /usr/bin/gcc-4.9
  157. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
  158. install tcp_tsunami.ko /lib/modules/$(uname -r)/kernel
  159. cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  160. depmod -a
  161. fi
  162. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  163. echo "net.ipv4.tcp_congestion_control=tsunami" >> /etc/sysctl.conf
  164. sysctl -p
  165. cd .. && rm -rf bbrmod
  166. echo -e "${Info}¡La versión mágica de BBR comenzó con éxito!"
  167. msg -bar
  168. }
  169. # Compilar y habilitar el cambio mágico BBR
  170. startbbrmod_nanqinlang(){
  171. remove_all
  172. if [[ "${release}" == "centos" ]]; then
  173. yum install -y make gcc
  174. mkdir bbrmod && cd bbrmod
  175. wget -N --no-check-certificate https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/bbr/centos/tcp_nanqinlang.c
  176. echo "obj-m := tcp_nanqinlang.o" > Makefile
  177. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
  178. chmod +x ./tcp_nanqinlang.ko
  179. cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  180. insmod tcp_nanqinlang.ko
  181. depmod -a
  182. else
  183. apt-get update
  184. if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
  185. apt-get -y install build-essential
  186. apt-get -y install software-properties-common
  187. add-apt-repository ppa:ubuntu-toolchain-r/test -y
  188. apt-get update
  189. fi
  190. apt-get -y install make gcc-4.9
  191. mkdir bbrmod && cd bbrmod
  192. wget -N --no-check-certificate https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/bbr/tcp_nanqinlang.c
  193. echo "obj-m := tcp_nanqinlang.o" > Makefile
  194. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
  195. install tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel
  196. cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  197. depmod -a
  198. fi
  199. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  200. echo "net.ipv4.tcp_congestion_control=nanqinlang" >> /etc/sysctl.conf
  201. sysctl -p
  202. echo -e "${Info}¡La versión mágica de BBR comenzó con éxito!"
  203. msg -bar
  204. }
  205. # Habilitar Lotserver
  206. startlotserver(){
  207. remove_all
  208. if [[ "${release}" == "centos" ]]; then
  209. yum install ethtool
  210. else
  211. apt-get update
  212. apt-get install ethtool
  213. fi
  214. bash <(wget --no-check-certificate -qO- https://github.com/MoeClub/lotServer/raw/master/Install.sh) install
  215. start_menu
  216. }
  217. # Desinstalar toda la aceleración
  218. remove_all(){
  219. rm -rf bbrmod
  220. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  221. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
  222. sed -i '/fs.file-max/d' /etc/sysctl.conf
  223. sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
  224. sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
  225. sed -i '/net.core.rmem_default/d' /etc/sysctl.conf
  226. sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
  227. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  228. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  229. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  230. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  231. sed -i '/net.ipv4.tcp_tw_recycle/d' /etc/sysctl.conf
  232. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  233. sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.conf
  234. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  235. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  236. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  237. sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf
  238. sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf
  239. sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.conf
  240. sed -i '/net.ipv4.ip_forward/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. if [[ -e /appex/bin/lotServer.sh ]]; then
  256. bash <(wget --no-check-certificate -qO- https://github.com/MoeClub/lotServer/raw/master/Install.sh) uninstall
  257. fi
  258. clear
  259. echo -e "${Info}:La aceleración está Desinstalada."
  260. sleep 1s
  261. }
  262. #Optimizar la configuración del sistema
  263. optimizing_system(){
  264. sed -i '/fs.file-max/d' /etc/sysctl.conf
  265. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  266. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  267. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  268. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  269. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  270. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  271. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  272. sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
  273. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
  274. sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
  275. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  276. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  277. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
  278. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
  279. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  280. echo "fs.file-max = 1000000
  281. fs.inotify.max_user_instances = 8192
  282. net.ipv4.tcp_syncookies = 1
  283. net.ipv4.tcp_fin_timeout = 30
  284. net.ipv4.tcp_tw_reuse = 1
  285. net.ipv4.ip_local_port_range = 1024 65000
  286. net.ipv4.tcp_max_syn_backlog = 16384
  287. net.ipv4.tcp_max_tw_buckets = 6000
  288. net.ipv4.route.gc_timeout = 100
  289. net.ipv4.tcp_syn_retries = 1
  290. net.ipv4.tcp_synack_retries = 1
  291. net.core.somaxconn = 32768
  292. net.core.netdev_max_backlog = 32768
  293. net.ipv4.tcp_timestamps = 0
  294. net.ipv4.tcp_max_orphans = 32768
  295. # forward ipv4
  296. net.ipv4.ip_forward = 1">>/etc/sysctl.conf
  297. sysctl -p
  298. echo "* soft nofile 1000000
  299. * hard nofile 1000000">/etc/security/limits.conf
  300. echo "ulimit -SHn 1000000">>/etc/profile
  301. read -p "Después de aplicar la configuracion al VPS necesita reiniciar, reiniciar ahora ? [Y/n] :" yn
  302. msg -bar
  303. [ -z "${yn}" ] && yn="y"
  304. if [[ $yn == [Yy] ]]; then
  305. echo -e "${Info} Reinicio de VPS..."
  306. reboot
  307. fi
  308. }
  309. # Script de actualización
  310. Update_Shell(){
  311. echo -e "La versión actual es [ ${sh_ver} ],Empieza a detectar la última versión..."
  312. sh_new_ver=$(wget --no-check-certificate -qO- "http://${github}/tcp.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
  313. [[ -z ${sh_new_ver} ]] && echo -e "${Error} Error al detectar la última versión !" && start_menu
  314. if [[ ${sh_new_ver} != ${sh_ver} ]]; then
  315. echo -e "Descubre nueva versión[ ${sh_new_ver} ],Ya sea para actualizar?[Y/n]"
  316. read -p "(Por defecto: y):" yn
  317. [[ -z "${yn}" ]] && yn="y"
  318. if [[ ${yn} == [Yy] ]]; then
  319. wget -N --no-check-certificate http://${github}/tcp.sh && chmod +x tcp.sh
  320. echo -e "El script ha sido actualizado a la última versión.[ ${sh_new_ver} ] !"
  321. else
  322. echo && echo " Cancelado ..." && echo
  323. fi
  324. else
  325. echo -e "Actualmente la última versión[ ${sh_new_ver} ] !"
  326. sleep 5s
  327. fi
  328. }
  329. # Menú de inicio
  330. start_menu(){
  331. clear
  332. msg -bar
  333. echo -e " TCP Aceleración (BBR/Plus) MOD By @Rufu99 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
  334. $(msg -bar)
  335. ${Green_font_prefix}0.${Font_color_suffix} Script de actualización
  336. ——————————————————Gestión del Núcleo—————————————————
  337. ${Green_font_prefix}1.${Font_color_suffix} Instalación BBR/BBR Kernel Mágico
  338. ${Green_font_prefix}2.${Font_color_suffix} Instalación BBRplus Kernel
  339. ${Green_font_prefix}3.${Font_color_suffix} Instalación Lotserver Kernel (Velocidad Aguda)
  340. ——————————————————Gestión Acelerada——————————————————
  341. ${Green_font_prefix}4.${Font_color_suffix} Usar BBR Aceleración
  342. ${Green_font_prefix}5.${Font_color_suffix} Usar BBR Velocidad de revisión mágica
  343. ${Green_font_prefix}6.${Font_color_suffix} Usar BBR Aceleración Violenta de revisión mágica
  344. ${Green_font_prefix}7.${Font_color_suffix} Usar BBRplus Aceleración
  345. ${Green_font_prefix}8.${Font_color_suffix} Usar Lotserver (Velocidad Brusca) Aceleración
  346. ——————————————————Manejo misceláneo——————————————————
  347. ${Green_font_prefix}9.${Font_color_suffix} Desintalar Todas las Aceleraciones
  348. ${Green_font_prefix}10.${Font_color_suffix} Optimización de la configuración del sistema.
  349. ${Green_font_prefix}11.${Font_color_suffix} Salir del script
  350. —————————————————————————————————————————————————————" && msg -bar
  351. check_status
  352. if [[ ${kernel_status} == "noinstall" ]]; then
  353. echo -e " Estado actual: ${Green_font_prefix}No instalado\n${Font_color_suffix} Kernel Acelerado ${Red_font_prefix}Por favor, instale el Núcleo primero.${Font_color_suffix}"
  354. else
  355. echo -e " Estado actual: ${Green_font_prefix}Instalado\n${Font_color_suffix} ${_font_prefix}${kernel_status}${Font_color_suffix} Kernel Acelerado, ${Green_font_prefix}${run_status}${Font_color_suffix}"
  356. fi
  357. msg -bar
  358. read -p " Por favor ingrese un número [0-11]:" num
  359. case "$num" in
  360. 0)
  361. Update_Shell
  362. ;;
  363. 1)
  364. check_sys_bbr
  365. ;;
  366. 2)
  367. check_sys_bbrplus
  368. ;;
  369. 3)
  370. check_sys_Lotsever
  371. ;;
  372. 4)
  373. startbbr
  374. ;;
  375. 5)
  376. startbbrmod
  377. ;;
  378. 6)
  379. startbbrmod_nanqinlang
  380. ;;
  381. 7)
  382. startbbrplus
  383. ;;
  384. 8)
  385. startlotserver
  386. ;;
  387. 9)
  388. remove_all
  389. ;;
  390. 10)
  391. optimizing_system
  392. ;;
  393. 11)
  394. exit 1
  395. ;;
  396. *)
  397. clear
  398. echo -e "${Error}:Por favor ingrese el número correcto [0-11]"
  399. sleep 5s
  400. start_menu
  401. ;;
  402. esac
  403. }
  404. ############# Componentes de gestión del núcleo #############
  405. # Eliminar kernel redundante
  406. detele_kernel(){
  407. if [[ "${release}" == "centos" ]]; then
  408. rpm_total=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l`
  409. if [ "${rpm_total}" > "1" ]; then
  410. echo -e "Detectado ${rpm_total} El resto del núcleo, comienza a desinstalar ..."
  411. for((integer = 1; integer <= ${rpm_total}; integer++)); do
  412. rpm_del=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer}`
  413. echo -e "Comience a desinstalar${rpm_del} Kernel ..."
  414. rpm --nodeps -e ${rpm_del}
  415. echo -e "Desinstalar ${rpm_del} La desinstalación del núcleo se ha completado, continúa ..."
  416. done
  417. echo --nodeps -e "El núcleo se desinstala y continúa ..."
  418. else
  419. echo -e " El número de núcleos detectados es incorrecto, ¡por favor verifique!" && exit 1
  420. fi
  421. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  422. deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
  423. if [ "${deb_total}" > "1" ]; then
  424. echo -e "Detectado ${deb_total} El resto del núcleo, comienza a desinstalar ..."
  425. for((integer = 1; integer <= ${deb_total}; integer++)); do
  426. deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
  427. echo -e "Comience a desinstalar ${deb_del} Kernel ..."
  428. apt-get purge -y ${deb_del}
  429. echo -e "Desinstalar ${deb_del} La desinstalación del núcleo se ha completado, continúa ..."
  430. done
  431. echo -e "El núcleo se desinstala y continúa ..."
  432. else
  433. echo -e " El número de núcleos detectados es incorrecto, ¡por favor verifique!" && exit 1
  434. fi
  435. fi
  436. }
  437. #Actualizar arranque
  438. BBR_grub(){
  439. if [[ "${release}" == "centos" ]]; then
  440. if [[ ${version} = "6" ]]; then
  441. if [ ! -f "/boot/grub/grub.conf" ]; then
  442. echo -e "${Error} /boot/grub/grub.conf No encontrado, verifique."
  443. exit 1
  444. fi
  445. sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
  446. elif [[ ${version} = "7" ]]; then
  447. if [ ! -f "/boot/grub2/grub.cfg" ]; then
  448. echo -e "${Error} /boot/grub2/grub.cfg No encontrado, verifique."
  449. exit 1
  450. fi
  451. grub2-set-default 0
  452. fi
  453. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  454. /usr/sbin/update-grub
  455. fi
  456. }
  457. #############Componente de gestión del kernel#############
  458. #############Componentes de detección del sistema#############
  459. #Sistema de inspección
  460. check_sys(){
  461. if [[ -f /etc/redhat-release ]]; then
  462. release="centos"
  463. elif cat /etc/issue | grep -q -E -i "debian"; then
  464. release="debian"
  465. elif cat /etc/issue | grep -q -E -i "ubuntu"; then
  466. release="ubuntu"
  467. elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
  468. release="centos"
  469. elif cat /proc/version | grep -q -E -i "debian"; then
  470. release="debian"
  471. elif cat /proc/version | grep -q -E -i "ubuntu"; then
  472. release="ubuntu"
  473. elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
  474. release="centos"
  475. fi
  476. }
  477. #Verifique la versión de Linux
  478. check_version(){
  479. if [[ -s /etc/redhat-release ]]; then
  480. version=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
  481. else
  482. version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
  483. fi
  484. bit=`uname -m`
  485. if [[ ${bit} = "x86_64" ]]; then
  486. bit="x64"
  487. else
  488. bit="x32"
  489. fi
  490. }
  491. #Verifique los requisitos del sistema para instalar bbr
  492. check_sys_bbr(){
  493. check_version
  494. if [[ "${release}" == "centos" ]]; then
  495. if [[ ${version} -ge "6" ]]; then
  496. installbbr
  497. else
  498. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  499. fi
  500. elif [[ "${release}" == "debian" ]]; then
  501. if [[ ${version} -ge "8" ]]; then
  502. installbbr
  503. else
  504. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  505. fi
  506. elif [[ "${release}" == "ubuntu" ]]; then
  507. if [[ ${version} -ge "14" ]]; then
  508. installbbr
  509. else
  510. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  511. fi
  512. else
  513. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  514. fi
  515. }
  516. check_sys_bbrplus(){
  517. check_version
  518. if [[ "${release}" == "centos" ]]; then
  519. if [[ ${version} -ge "6" ]]; then
  520. installbbrplus
  521. else
  522. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  523. fi
  524. elif [[ "${release}" == "debian" ]]; then
  525. if [[ ${version} -ge "8" ]]; then
  526. installbbrplus
  527. else
  528. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  529. fi
  530. elif [[ "${release}" == "ubuntu" ]]; then
  531. if [[ ${version} -ge "14" ]]; then
  532. installbbrplus
  533. else
  534. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  535. fi
  536. else
  537. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  538. fi
  539. }
  540. #Verifique los requisitos del sistema para instalar Lotsever
  541. check_sys_Lotsever(){
  542. check_version
  543. if [[ "${release}" == "centos" ]]; then
  544. if [[ ${version} == "6" ]]; then
  545. kernel_version="2.6.32-504"
  546. installlot
  547. elif [[ ${version} == "7" ]]; then
  548. yum -y install net-tools
  549. kernel_version="3.10.0-327"
  550. installlot
  551. else
  552. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  553. fi
  554. elif [[ "${release}" == "debian" ]]; then
  555. if [[ ${version} = "7" || ${version} = "8" ]]; then
  556. if [[ ${bit} == "x64" ]]; then
  557. kernel_version="3.16.0-4"
  558. installlot
  559. elif [[ ${bit} == "x32" ]]; then
  560. kernel_version="3.2.0-4"
  561. installlot
  562. fi
  563. elif [[ ${version} = "9" ]]; then
  564. if [[ ${bit} == "x64" ]]; then
  565. kernel_version="4.9.0-4"
  566. installlot
  567. fi
  568. else
  569. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  570. fi
  571. elif [[ "${release}" == "ubuntu" ]]; then
  572. if [[ ${version} -ge "12" ]]; then
  573. if [[ ${bit} == "x64" ]]; then
  574. kernel_version="4.4.0-47"
  575. installlot
  576. elif [[ ${bit} == "x32" ]]; then
  577. kernel_version="3.13.0-29"
  578. installlot
  579. fi
  580. else
  581. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  582. fi
  583. else
  584. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  585. fi
  586. }
  587. check_status(){
  588. kernel_version=`uname -r | awk -F "-" '{print $1}'`
  589. kernel_version_full=`uname -r`
  590. if [[ ${kernel_version_full} = "4.14.129-bbrplus" ]]; then
  591. kernel_status="BBRplus"
  592. 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
  593. kernel_status="Lotserver"
  594. 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
  595. kernel_status="BBR"
  596. else
  597. kernel_status="noinstall"
  598. fi
  599. if [[ ${kernel_status} == "Lotserver" ]]; then
  600. if [[ -e /appex/bin/lotServer.sh ]]; then
  601. run_status=`bash /appex/bin/lotServer.sh status | grep "LotServer" | awk '{print $3}'`
  602. if [[ ${run_status} = "running!" ]]; then
  603. run_status="Comenzó exitosamente"
  604. else
  605. run_status="No se pudo iniciar"
  606. fi
  607. else
  608. run_status="No hay un módulo de aceleración instalado"
  609. fi
  610. elif [[ ${kernel_status} == "BBR" ]]; then
  611. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
  612. if [[ ${run_status} == "bbr" ]]; then
  613. run_status=`lsmod | grep "bbr" | awk '{print $1}'`
  614. if [[ ${run_status} == "tcp_bbr" ]]; then
  615. run_status="BBR Comenzó exitosamente"
  616. else
  617. run_status="BBR Comenzó exitosamente"
  618. fi
  619. elif [[ ${run_status} == "tsunami" ]]; then
  620. run_status=`lsmod | grep "tsunami" | awk '{print $1}'`
  621. if [[ ${run_status} == "tcp_tsunami" ]]; then
  622. run_status="BBR La revisión mágica se lanzó con éxito"
  623. else
  624. run_status="BBR Inicio de modificación mágica fallido"
  625. fi
  626. elif [[ ${run_status} == "nanqinlang" ]]; then
  627. run_status=`lsmod | grep "nanqinlang" | awk '{print $1}'`
  628. if [[ ${run_status} == "tcp_nanqinlang" ]]; then
  629. run_status="El violento manifestante de BBR se lanzó con éxito"
  630. else
  631. run_status="Violenta revisión mágica de BBR no pudo comenzar"
  632. fi
  633. else
  634. run_status="No hay un módulo de aceleración instalado"
  635. fi
  636. elif [[ ${kernel_status} == "BBRplus" ]]; then
  637. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
  638. if [[ ${run_status} == "bbrplus" ]]; then
  639. run_status=`lsmod | grep "bbrplus" | awk '{print $1}'`
  640. if [[ ${run_status} == "tcp_bbrplus" ]]; then
  641. run_status="BBRplus comenzó con éxito"
  642. else
  643. run_status="BBRplus comenzó con éxito"
  644. fi
  645. else
  646. run_status="No hay un módulo de aceleración instalado"
  647. fi
  648. fi
  649. }
  650. #############Componentes de detección del sistema#############
  651. check_sys
  652. check_version
  653. [[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} Este script no es compatible con el sistema actual. ${release} !" && exit 1
  654. start_menu