tcp.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #!/bin/bash
  2. #27/01/2021
  3. clear
  4. clear
  5. msg -bar
  6. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  7. export PATH
  8. SCPfrm="/etc/VPS-MX/herramientas" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
  9. BARRA1="\e[0;31m————————————————————————————————————————————————————\e[0m"
  10. SCPinst="/etc/VPS-MX/controlador" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
  11. #=================================================
  12. # System Required: CentOS 6/7,Debian 8/9,Ubuntu 16+
  13. # Description: BBR+BBRVersión mágica+BBRplus+Lotserver
  14. # Version: 1.3.1
  15. # Author: Mil sombras,cx9208
  16. # Blog: https://www.94ish.me/
  17. #=================================================
  18. sh_ver="1.3.1"
  19. github="raw.githubusercontent.com/cx9208/Linux-NetSpeed/master"
  20. 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"
  21. Info="${Green_font_prefix}[Informacion]${Font_color_suffix}"
  22. Error="${Red_font_prefix}[Error]${Font_color_suffix}"
  23. Tip="${Green_font_prefix}[Atencion]${Font_color_suffix}"
  24. #Instalar el núcleo BBR
  25. installbbr(){
  26. kernel_version="4.11.8"
  27. if [[ "${release}" == "centos" ]]; then
  28. rpm --import http://${github}/bbr/${release}/RPM-GPG-KEY-elrepo.org
  29. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-${kernel_version}.rpm
  30. yum remove -y kernel-headers
  31. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-headers-${kernel_version}.rpm
  32. yum install -y http://${github}/bbr/${release}/${version}/${bit}/kernel-ml-devel-${kernel_version}.rpm
  33. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  34. mkdir bbr && cd bbr
  35. wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u10_amd64.deb
  36. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/linux-headers-${kernel_version}-all.deb
  37. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
  38. wget -N --no-check-certificate http://${github}/bbr/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
  39. dpkg -i libssl1.0.0_1.0.1t-1+deb8u10_amd64.deb
  40. dpkg -i linux-headers-${kernel_version}-all.deb
  41. dpkg -i linux-headers-${kernel_version}.deb
  42. dpkg -i linux-image-${kernel_version}.deb
  43. cd .. && rm -rf bbr
  44. fi
  45. detele_kernel
  46. BBR_grub
  47. msg -bar
  48. 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}"
  49. msg -bar
  50. stty erase '^H' && read -p "Debe reiniciar el VPS antes de poder habilitar BBR, reiniciar ahora. ? [Y/n] :" yn
  51. [ -z "${yn}" ] && yn="y"
  52. if [[ $yn == [Yy] ]]; then
  53. echo -e "${Info} VPS se reinicia ..."
  54. reboot
  55. fi
  56. }
  57. #Instale el núcleo BBRplus
  58. installbbrplus(){
  59. kernel_version="4.14.129-bbrplus"
  60. if [[ "${release}" == "centos" ]]; then
  61. wget -N --no-check-certificate https://${github}/bbrplus/${release}/${version}/kernel-${kernel_version}.rpm
  62. yum install -y kernel-${kernel_version}.rpm
  63. rm -f kernel-${kernel_version}.rpm
  64. kernel_version="4.14.129_bbrplus" #fix a bug
  65. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  66. mkdir bbrplus && cd bbrplus
  67. wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-headers-${kernel_version}.deb
  68. wget -N --no-check-certificate http://${github}/bbrplus/debian-ubuntu/${bit}/linux-image-${kernel_version}.deb
  69. dpkg -i linux-headers-${kernel_version}.deb
  70. dpkg -i linux-image-${kernel_version}.deb
  71. cd .. && rm -rf bbrplus
  72. fi
  73. detele_kernel
  74. BBR_grub
  75. msg -bar
  76. echo -e "${Tip} Después de reiniciar el VPS, vuelva a ejecutar el script para abrir\n${Red_font_prefix} BBRplus${Font_color_suffix}"
  77. msg -bar
  78. stty erase '^H' && read -p "Debe reiniciar el VPS antes de poder habilitar BBRplus, reiniciar ahora ? [Y/n] :" yn
  79. [ -z "${yn}" ] && yn="y"
  80. if [[ $yn == [Yy] ]]; then
  81. echo -e "${Info} VPS se reinicia ..."
  82. reboot
  83. fi
  84. }
  85. #Instale el kernel de Lotserver
  86. installlot(){
  87. if [[ "${release}" == "centos" ]]; then
  88. rpm --import http://${github}/lotserver/${release}/RPM-GPG-KEY-elrepo.org
  89. yum remove -y kernel-firmware
  90. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-firmware-${kernel_version}.rpm
  91. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-${kernel_version}.rpm
  92. yum remove -y kernel-headers
  93. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-headers-${kernel_version}.rpm
  94. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-devel-${kernel_version}.rpm
  95. elif [[ "${release}" == "ubuntu" ]]; then
  96. bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
  97. elif [[ "${release}" == "debian" ]]; then
  98. bash <(wget --no-check-certificate -qO- "http://${github}/Debian_Kernel.sh")
  99. fi
  100. detele_kernel
  101. BBR_grub
  102. msg -bar
  103. echo -e "${Tip} Después de reiniciar el VPS, vuelva a ejecutar el script para abrir\n${Red_font_prefix}Lotserver${Font_color_suffix}"
  104. msg -bar
  105. stty erase '^H' && read -p "Necesita reiniciar el VPS antes de poder abrir Lotserver, reiniciar ahora ? [Y/n] :" yn
  106. [ -z "${yn}" ] && yn="y"
  107. if [[ $yn == [Yy] ]]; then
  108. echo -e "${Info} VPS se reinicia ..."
  109. reboot
  110. fi
  111. }
  112. # Habilitar BBR
  113. startbbr(){
  114. remove_all
  115. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  116. echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
  117. sysctl -p
  118. echo -e "${Info}¡BBR comenzó con éxito!"
  119. msg -bar
  120. }
  121. #Habilitar BBRplus
  122. startbbrplus(){
  123. remove_all
  124. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  125. echo "net.ipv4.tcp_congestion_control=bbrplus" >> /etc/sysctl.conf
  126. sysctl -p
  127. echo -e "${Info}BBRplus comenzó con éxito!!"
  128. msg -bar
  129. }
  130. # Compilar y habilitar el cambio mágico BBR
  131. startbbrmod(){
  132. remove_all
  133. if [[ "${release}" == "centos" ]]; then
  134. yum install -y make gcc
  135. mkdir bbrmod && cd bbrmod
  136. wget -N --no-check-certificate http://${github}/bbr/tcp_tsunami.c
  137. echo "obj-m:=tcp_tsunami.o" > Makefile
  138. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
  139. chmod +x ./tcp_tsunami.ko
  140. cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  141. insmod tcp_tsunami.ko
  142. depmod -a
  143. else
  144. apt-get update
  145. if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
  146. apt-get -y install build-essential
  147. apt-get -y install software-properties-common
  148. add-apt-repository ppa:ubuntu-toolchain-r/test -y
  149. apt-get update
  150. fi
  151. apt-get -y install make gcc
  152. mkdir bbrmod && cd bbrmod
  153. wget -N --no-check-certificate http://${github}/bbr/tcp_tsunami.c
  154. echo "obj-m:=tcp_tsunami.o" > Makefile
  155. ln -s /usr/bin/gcc /usr/bin/gcc-4.9
  156. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
  157. install tcp_tsunami.ko /lib/modules/$(uname -r)/kernel
  158. cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  159. depmod -a
  160. fi
  161. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  162. echo "net.ipv4.tcp_congestion_control=tsunami" >> /etc/sysctl.conf
  163. sysctl -p
  164. cd .. && rm -rf bbrmod
  165. echo -e "${Info}¡La versión mágica de BBR comenzó con éxito!"
  166. msg -bar
  167. }
  168. # Compilar y habilitar el cambio mágico BBR
  169. startbbrmod_nanqinlang(){
  170. remove_all
  171. if [[ "${release}" == "centos" ]]; then
  172. yum install -y make gcc
  173. mkdir bbrmod && cd bbrmod
  174. wget -N --no-check-certificate https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/bbr/centos/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
  177. chmod +x ./tcp_nanqinlang.ko
  178. cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  179. insmod tcp_nanqinlang.ko
  180. depmod -a
  181. else
  182. apt-get update
  183. if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
  184. apt-get -y install build-essential
  185. apt-get -y install software-properties-common
  186. add-apt-repository ppa:ubuntu-toolchain-r/test -y
  187. apt-get update
  188. fi
  189. apt-get -y install make gcc-4.9
  190. mkdir bbrmod && cd bbrmod
  191. wget -N --no-check-certificate https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/bbr/tcp_nanqinlang.c
  192. echo "obj-m := tcp_nanqinlang.o" > Makefile
  193. make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc-4.9
  194. install tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel
  195. cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
  196. depmod -a
  197. fi
  198. echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
  199. echo "net.ipv4.tcp_congestion_control=nanqinlang" >> /etc/sysctl.conf
  200. sysctl -p
  201. echo -e "${Info}¡La versión mágica de BBR comenzó con éxito!"
  202. msg -bar
  203. }
  204. # Habilitar Lotserver
  205. startlotserver(){
  206. remove_all
  207. if [[ "${release}" == "centos" ]]; then
  208. yum install ethtool
  209. else
  210. apt-get update
  211. apt-get install ethtool
  212. fi
  213. bash <(wget --no-check-certificate -qO- https://github.com/MoeClub/lotServer/raw/master/Install.sh) install
  214. start_menu
  215. }
  216. # Desinstalar toda la aceleración
  217. remove_all(){
  218. rm -rf bbrmod
  219. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  220. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
  221. sed -i '/fs.file-max/d' /etc/sysctl.conf
  222. sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
  223. sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
  224. sed -i '/net.core.rmem_default/d' /etc/sysctl.conf
  225. sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
  226. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  227. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  228. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  229. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  230. sed -i '/net.ipv4.tcp_tw_recycle/d' /etc/sysctl.conf
  231. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  232. sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.conf
  233. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  234. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  235. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  236. sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf
  237. sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf
  238. sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.conf
  239. sed -i '/net.ipv4.ip_forward/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. if [[ -e /appex/bin/lotServer.sh ]]; then
  255. bash <(wget --no-check-certificate -qO- https://github.com/MoeClub/lotServer/raw/master/Install.sh) uninstall
  256. fi
  257. clear
  258. echo -e "${Info}:La aceleración está Desinstalada."
  259. sleep 1s
  260. }
  261. #Optimizar la configuración del sistema
  262. optimizing_system(){
  263. sed -i '/fs.file-max/d' /etc/sysctl.conf
  264. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  265. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  266. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  267. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  268. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  269. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  270. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  271. sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
  272. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
  273. sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
  274. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  275. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  276. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
  277. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
  278. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  279. echo "fs.file-max = 1000000
  280. fs.inotify.max_user_instances = 8192
  281. net.ipv4.tcp_syncookies = 1
  282. net.ipv4.tcp_fin_timeout = 30
  283. net.ipv4.tcp_tw_reuse = 1
  284. net.ipv4.ip_local_port_range = 1024 65000
  285. net.ipv4.tcp_max_syn_backlog = 16384
  286. net.ipv4.tcp_max_tw_buckets = 6000
  287. net.ipv4.route.gc_timeout = 100
  288. net.ipv4.tcp_syn_retries = 1
  289. net.ipv4.tcp_synack_retries = 1
  290. net.core.somaxconn = 32768
  291. net.core.netdev_max_backlog = 32768
  292. net.ipv4.tcp_timestamps = 0
  293. net.ipv4.tcp_max_orphans = 32768
  294. # forward ipv4
  295. net.ipv4.ip_forward = 1">>/etc/sysctl.conf
  296. sysctl -p
  297. echo "* soft nofile 1000000
  298. * hard nofile 1000000">/etc/security/limits.conf
  299. echo "ulimit -SHn 1000000">>/etc/profile
  300. read -p "Después de aplicar la configuracion al VPS necesita reiniciar, reiniciar ahora ? [Y/n] :" yn
  301. msg -bar
  302. [ -z "${yn}" ] && yn="y"
  303. if [[ $yn == [Yy] ]]; then
  304. echo -e "${Info} Reinicio de VPS..."
  305. reboot
  306. fi
  307. }
  308. # Script de actualización
  309. Update_Shell(){
  310. echo -e "La versión actual es [ ${sh_ver} ],Empieza a detectar la última versión..."
  311. sh_new_ver=$(wget --no-check-certificate -qO- "http://${github}/tcp.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
  312. [[ -z ${sh_new_ver} ]] && echo -e "${Error} Error al detectar la última versión !" && start_menu
  313. if [[ ${sh_new_ver} != ${sh_ver} ]]; then
  314. echo -e "Descubre nueva versión[ ${sh_new_ver} ],Ya sea para actualizar?[Y/n]"
  315. read -p "(Por defecto: y):" yn
  316. [[ -z "${yn}" ]] && yn="y"
  317. if [[ ${yn} == [Yy] ]]; then
  318. wget -N --no-check-certificate http://${github}/tcp.sh && chmod +x tcp.sh
  319. echo -e "El script ha sido actualizado a la última versión.[ ${sh_new_ver} ] !"
  320. else
  321. echo && echo " Cancelado ..." && echo
  322. fi
  323. else
  324. echo -e "Actualmente la última versión[ ${sh_new_ver} ] !"
  325. sleep 5s
  326. fi
  327. }
  328. # Menú de inicio
  329. start_menu(){
  330. clear
  331. msg -bar
  332. msg -tit
  333. echo -e " TCP Aceleración (BBR/Plus) VPS-MX By @Kalix1\n ${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