1
0

tcp.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #!/bin/bash
  2. #19/12/2019
  3. source <(curl -sSL https://www.dropbox.com/s/yog8eklvcvz6zya/msg)
  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/ger-frm" && [[ ! -d ${SCPfrm} ]] && mkdir ${SCPfrm}
  9. BARRA1="\e[0;31m--------------------------------------------------------------------\e[0m"
  10. SCPinst="/etc/ger-inst" && [[ ! -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. echo -e " TCP Aceleración (BBR/Plus) ADM-ChumoGH By @ChumoGH ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
  333. $(msg -bar)
  334. ${Green_font_prefix}0.${Font_color_suffix} Script de actualización
  335. ————————————Gestión del Núcleo————————————
  336. ${Green_font_prefix}1.${Font_color_suffix} Instalación BBR/BBR Kernel Mágico
  337. ${Green_font_prefix}2.${Font_color_suffix} Instalación BBRplus Kernel
  338. ${Green_font_prefix}3.${Font_color_suffix} Instalación Lotserver Kernel (Velocidad Aguda)
  339. ————————————Gestión Acelerada————————————
  340. ${Green_font_prefix}4.${Font_color_suffix} Usar BBR Aceleración
  341. ${Green_font_prefix}5.${Font_color_suffix} Usar BBR Velocidad de revisión mágica
  342. ${Green_font_prefix}6.${Font_color_suffix} Usar BBR Aceleración Violenta de revisión mágica
  343. ${Green_font_prefix}7.${Font_color_suffix} Usar BBRplus Aceleración
  344. ${Green_font_prefix}8.${Font_color_suffix} Usar Lotserver (Velocidad Brusca) Aceleración
  345. ————————————Manejo misceláneo————————————
  346. ${Green_font_prefix}9.${Font_color_suffix} Desintalar Todas las Aceleraciones
  347. ${Green_font_prefix}10.${Font_color_suffix} Optimización de la configuración del sistema.
  348. ${Green_font_prefix}11.${Font_color_suffix} Salir del script
  349. ————————————————————————————————" && msg -bar
  350. check_status
  351. if [[ ${kernel_status} == "noinstall" ]]; then
  352. 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}"
  353. else
  354. 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}"
  355. fi
  356. msg -bar
  357. read -p " Por favor ingrese un número [0-11]:" num
  358. case "$num" in
  359. 0)
  360. Update_Shell
  361. ;;
  362. 1)
  363. check_sys_bbr
  364. ;;
  365. 2)
  366. check_sys_bbrplus
  367. ;;
  368. 3)
  369. check_sys_Lotsever
  370. ;;
  371. 4)
  372. startbbr
  373. ;;
  374. 5)
  375. startbbrmod
  376. ;;
  377. 6)
  378. startbbrmod_nanqinlang
  379. ;;
  380. 7)
  381. startbbrplus
  382. ;;
  383. 8)
  384. startlotserver
  385. ;;
  386. 9)
  387. remove_all
  388. ;;
  389. 10)
  390. optimizing_system
  391. ;;
  392. 11)
  393. exit 1
  394. ;;
  395. *)
  396. clear
  397. echo -e "${Error}:Por favor ingrese el número correcto [0-11]"
  398. sleep 5s
  399. start_menu
  400. ;;
  401. esac
  402. }
  403. ############# Componentes de gestión del núcleo #############
  404. # Eliminar kernel redundante
  405. detele_kernel(){
  406. if [[ "${release}" == "centos" ]]; then
  407. rpm_total=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l`
  408. if [ "${rpm_total}" > "1" ]; then
  409. echo -e "Detectado ${rpm_total} El resto del núcleo, comienza a desinstalar ..."
  410. for((integer = 1; integer <= ${rpm_total}; integer++)); do
  411. rpm_del=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer}`
  412. echo -e "Comience a desinstalar${rpm_del} Kernel ..."
  413. rpm --nodeps -e ${rpm_del}
  414. echo -e "Desinstalar ${rpm_del} La desinstalación del núcleo se ha completado, continúa ..."
  415. done
  416. echo --nodeps -e "El núcleo se desinstala y continúa ..."
  417. else
  418. echo -e " El número de núcleos detectados es incorrecto, ¡por favor verifique!" && exit 1
  419. fi
  420. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  421. deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
  422. if [ "${deb_total}" > "1" ]; then
  423. echo -e "Detectado ${deb_total} El resto del núcleo, comienza a desinstalar ..."
  424. for((integer = 1; integer <= ${deb_total}; integer++)); do
  425. deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
  426. echo -e "Comience a desinstalar ${deb_del} Kernel ..."
  427. apt-get purge -y ${deb_del}
  428. echo -e "Desinstalar ${deb_del} La desinstalación del núcleo se ha completado, continúa ..."
  429. done
  430. echo -e "El núcleo se desinstala y continúa ..."
  431. else
  432. echo -e " El número de núcleos detectados es incorrecto, ¡por favor verifique!" && exit 1
  433. fi
  434. fi
  435. }
  436. #Actualizar arranque
  437. BBR_grub(){
  438. if [[ "${release}" == "centos" ]]; then
  439. if [[ ${version} = "6" ]]; then
  440. if [ ! -f "/boot/grub/grub.conf" ]; then
  441. echo -e "${Error} /boot/grub/grub.conf No encontrado, verifique."
  442. exit 1
  443. fi
  444. sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
  445. elif [[ ${version} = "7" ]]; then
  446. if [ ! -f "/boot/grub2/grub.cfg" ]; then
  447. echo -e "${Error} /boot/grub2/grub.cfg No encontrado, verifique."
  448. exit 1
  449. fi
  450. grub2-set-default 0
  451. fi
  452. elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
  453. /usr/sbin/update-grub
  454. fi
  455. }
  456. #############Componente de gestión del kernel#############
  457. #############Componentes de detección del sistema#############
  458. #Sistema de inspección
  459. check_sys(){
  460. if [[ -f /etc/redhat-release ]]; then
  461. release="centos"
  462. elif cat /etc/issue | grep -q -E -i "debian"; then
  463. release="debian"
  464. elif cat /etc/issue | grep -q -E -i "ubuntu"; then
  465. release="ubuntu"
  466. elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
  467. release="centos"
  468. elif cat /proc/version | grep -q -E -i "debian"; then
  469. release="debian"
  470. elif cat /proc/version | grep -q -E -i "ubuntu"; then
  471. release="ubuntu"
  472. elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
  473. release="centos"
  474. fi
  475. }
  476. #Verifique la versión de Linux
  477. check_version(){
  478. if [[ -s /etc/redhat-release ]]; then
  479. version=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
  480. else
  481. version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
  482. fi
  483. bit=`uname -m`
  484. if [[ ${bit} = "x86_64" ]]; then
  485. bit="x64"
  486. else
  487. bit="x32"
  488. fi
  489. }
  490. #Verifique los requisitos del sistema para instalar bbr
  491. check_sys_bbr(){
  492. check_version
  493. if [[ "${release}" == "centos" ]]; then
  494. if [[ ${version} -ge "6" ]]; then
  495. installbbr
  496. else
  497. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  498. fi
  499. elif [[ "${release}" == "debian" ]]; then
  500. if [[ ${version} -ge "8" ]]; then
  501. installbbr
  502. else
  503. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  504. fi
  505. elif [[ "${release}" == "ubuntu" ]]; then
  506. if [[ ${version} -ge "14" ]]; then
  507. installbbr
  508. else
  509. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  510. fi
  511. else
  512. echo -e "${Error} BBR El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  513. fi
  514. }
  515. check_sys_bbrplus(){
  516. check_version
  517. if [[ "${release}" == "centos" ]]; then
  518. if [[ ${version} -ge "6" ]]; then
  519. installbbrplus
  520. else
  521. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  522. fi
  523. elif [[ "${release}" == "debian" ]]; then
  524. if [[ ${version} -ge "8" ]]; then
  525. installbbrplus
  526. else
  527. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  528. fi
  529. elif [[ "${release}" == "ubuntu" ]]; then
  530. if [[ ${version} -ge "14" ]]; then
  531. installbbrplus
  532. else
  533. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  534. fi
  535. else
  536. echo -e "${Error} BBRplus El núcleo no es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  537. fi
  538. }
  539. #Verifique los requisitos del sistema para instalar Lotsever
  540. check_sys_Lotsever(){
  541. check_version
  542. if [[ "${release}" == "centos" ]]; then
  543. if [[ ${version} == "6" ]]; then
  544. kernel_version="2.6.32-504"
  545. installlot
  546. elif [[ ${version} == "7" ]]; then
  547. yum -y install net-tools
  548. kernel_version="3.10.0-327"
  549. installlot
  550. else
  551. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  552. fi
  553. elif [[ "${release}" == "debian" ]]; then
  554. if [[ ${version} = "7" || ${version} = "8" ]]; then
  555. if [[ ${bit} == "x64" ]]; then
  556. kernel_version="3.16.0-4"
  557. installlot
  558. elif [[ ${bit} == "x32" ]]; then
  559. kernel_version="3.2.0-4"
  560. installlot
  561. fi
  562. elif [[ ${version} = "9" ]]; then
  563. if [[ ${bit} == "x64" ]]; then
  564. kernel_version="4.9.0-4"
  565. installlot
  566. fi
  567. else
  568. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  569. fi
  570. elif [[ "${release}" == "ubuntu" ]]; then
  571. if [[ ${version} -ge "12" ]]; then
  572. if [[ ${bit} == "x64" ]]; then
  573. kernel_version="4.4.0-47"
  574. installlot
  575. elif [[ ${bit} == "x32" ]]; then
  576. kernel_version="3.13.0-29"
  577. installlot
  578. fi
  579. else
  580. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  581. fi
  582. else
  583. echo -e "${Error} Lotsever No es compatible con el sistema actual ${release} ${version} ${bit} !" && exit 1
  584. fi
  585. }
  586. check_status(){
  587. kernel_version=`uname -r | awk -F "-" '{print $1}'`
  588. kernel_version_full=`uname -r`
  589. if [[ ${kernel_version_full} = "4.14.129-bbrplus" ]]; then
  590. kernel_status="BBRplus"
  591. 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
  592. kernel_status="Lotserver"
  593. 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
  594. kernel_status="BBR"
  595. else
  596. kernel_status="noinstall"
  597. fi
  598. if [[ ${kernel_status} == "Lotserver" ]]; then
  599. if [[ -e /appex/bin/lotServer.sh ]]; then
  600. run_status=`bash /appex/bin/lotServer.sh status | grep "LotServer" | awk '{print $3}'`
  601. if [[ ${run_status} = "running!" ]]; then
  602. run_status="Comenzó exitosamente"
  603. else
  604. run_status="No se pudo iniciar"
  605. fi
  606. else
  607. run_status="No hay un módulo de aceleración instalado"
  608. fi
  609. elif [[ ${kernel_status} == "BBR" ]]; then
  610. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
  611. if [[ ${run_status} == "bbr" ]]; then
  612. run_status=`lsmod | grep "bbr" | awk '{print $1}'`
  613. if [[ ${run_status} == "tcp_bbr" ]]; then
  614. run_status="BBR Comenzó exitosamente"
  615. else
  616. run_status="BBR Comenzó exitosamente"
  617. fi
  618. elif [[ ${run_status} == "tsunami" ]]; then
  619. run_status=`lsmod | grep "tsunami" | awk '{print $1}'`
  620. if [[ ${run_status} == "tcp_tsunami" ]]; then
  621. run_status="BBR La revisión mágica se lanzó con éxito"
  622. else
  623. run_status="BBR Inicio de modificación mágica fallido"
  624. fi
  625. elif [[ ${run_status} == "nanqinlang" ]]; then
  626. run_status=`lsmod | grep "nanqinlang" | awk '{print $1}'`
  627. if [[ ${run_status} == "tcp_nanqinlang" ]]; then
  628. run_status="El violento manifestante de BBR se lanzó con éxito"
  629. else
  630. run_status="Violenta revisión mágica de BBR no pudo comenzar"
  631. fi
  632. else
  633. run_status="No hay un módulo de aceleración instalado"
  634. fi
  635. elif [[ ${kernel_status} == "BBRplus" ]]; then
  636. run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
  637. if [[ ${run_status} == "bbrplus" ]]; then
  638. run_status=`lsmod | grep "bbrplus" | awk '{print $1}'`
  639. if [[ ${run_status} == "tcp_bbrplus" ]]; then
  640. run_status="BBRplus comenzó con éxito"
  641. else
  642. run_status="BBRplus comenzó con éxito"
  643. fi
  644. else
  645. run_status="No hay un módulo de aceleración instalado"
  646. fi
  647. fi
  648. }
  649. #############Componentes de detección del sistema#############
  650. check_sys
  651. check_version
  652. [[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} Este script no es compatible con el sistema actual. ${release} !" && exit 1
  653. start_menu