tcp.sh 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337
  1. #!/usr/bin/env bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4. #=================================================
  5. # System Required: CentOS 7/8,Debian/ubuntu,oraclelinux
  6. # Description: BBR+BBRplus+Lotserver
  7. # Version: 100.0.4.2
  8. # Author: 千影,cx9208,YLX
  9. # 更新内容及反馈: https://blog.ylx.me/archives/783.html
  10. #=================================================
  11. # RED='\033[0;31m'
  12. # GREEN='\033[0;32m'
  13. # YELLOW='\033[0;33m'
  14. # SKYBLUE='\033[0;36m'
  15. # PLAIN='\033[0m'
  16. sh_ver="100.0.4.2"
  17. github="raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master"
  18. imgurl=""
  19. headurl=""
  20. github_network=1
  21. Green_font_prefix="\033[32m"
  22. Red_font_prefix="\033[31m"
  23. Font_color_suffix="\033[0m"
  24. Info="${Green_font_prefix}[信息]${Font_color_suffix}"
  25. Error="${Red_font_prefix}[错误]${Font_color_suffix}"
  26. Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
  27. if [ -f "/etc/sysctl.d/bbr.conf" ]; then
  28. rm -rf /etc/sysctl.d/bbr.conf
  29. fi
  30. # 检查当前用户是否为 root 用户
  31. if [ "$EUID" -ne 0 ]; then
  32. echo "请使用 root 用户身份运行此脚本"
  33. exit
  34. fi
  35. #优化系统配置
  36. optimizing_system_old() {
  37. if [ ! -f "/etc/sysctl.d/99-sysctl.conf" ]; then
  38. touch /etc/sysctl.d/99-sysctl.conf
  39. fi
  40. sed -i '/net.ipv4.tcp_retries2/d' /etc/sysctl.conf
  41. sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.conf
  42. sed -i '/net.ipv4.tcp_fastopen/d' /etc/sysctl.conf
  43. sed -i '/fs.file-max/d' /etc/sysctl.conf
  44. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  45. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  46. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  47. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  48. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  49. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  50. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  51. sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
  52. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
  53. sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
  54. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  55. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  56. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
  57. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
  58. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  59. echo "net.ipv4.tcp_retries2 = 8
  60. net.ipv4.tcp_slow_start_after_idle = 0
  61. fs.file-max = 1000000
  62. fs.inotify.max_user_instances = 8192
  63. net.ipv4.tcp_syncookies = 1
  64. net.ipv4.tcp_fin_timeout = 30
  65. net.ipv4.tcp_tw_reuse = 1
  66. net.ipv4.ip_local_port_range = 1024 65000
  67. net.ipv4.tcp_max_syn_backlog = 16384
  68. net.ipv4.tcp_max_tw_buckets = 6000
  69. net.ipv4.route.gc_timeout = 100
  70. net.ipv4.tcp_syn_retries = 1
  71. net.ipv4.tcp_synack_retries = 1
  72. net.core.somaxconn = 32768
  73. net.core.netdev_max_backlog = 32768
  74. net.ipv4.tcp_timestamps = 0
  75. net.ipv4.tcp_max_orphans = 32768
  76. # forward ipv4
  77. #net.ipv4.ip_forward = 1" >>/etc/sysctl.d/99-sysctl.conf
  78. sysctl -p
  79. echo "* soft nofile 1000000
  80. * hard nofile 1000000" >/etc/security/limits.conf
  81. echo "ulimit -SHn 1000000" >>/etc/profile
  82. read -p "需要重启VPS后,才能生效系统优化配置,是否现在重启 ? [Y/n] :" yn
  83. [ -z "${yn}" ] && yn="y"
  84. if [[ $yn == [Yy] ]]; then
  85. echo -e "${Info} VPS 重启中..."
  86. reboot
  87. fi
  88. }
  89. optimizing_system_johnrosen1() {
  90. if [ ! -f "/etc/sysctl.d/99-sysctl.conf" ]; then
  91. touch /etc/sysctl.d/99-sysctl.conf
  92. fi
  93. sed -i '/net.ipv4.tcp_fack/d' /etc/sysctl.d/99-sysctl.conf
  94. sed -i '/net.ipv4.tcp_early_retrans/d' /etc/sysctl.d/99-sysctl.conf
  95. sed -i '/net.ipv4.neigh.default.unres_qlen/d' /etc/sysctl.d/99-sysctl.conf
  96. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.d/99-sysctl.conf
  97. sed -i '/net.netfilter.nf_conntrack_buckets/d' /etc/sysctl.d/99-sysctl.conf
  98. sed -i '/kernel.pid_max/d' /etc/sysctl.d/99-sysctl.conf
  99. sed -i '/vm.nr_hugepages/d' /etc/sysctl.d/99-sysctl.conf
  100. sed -i '/net.core.optmem_max/d' /etc/sysctl.d/99-sysctl.conf
  101. sed -i '/net.ipv4.conf.all.route_localnet/d' /etc/sysctl.d/99-sysctl.conf
  102. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.d/99-sysctl.conf
  103. sed -i '/net.ipv4.conf.all.forwarding/d' /etc/sysctl.d/99-sysctl.conf
  104. sed -i '/net.ipv4.conf.default.forwarding/d' /etc/sysctl.d/99-sysctl.conf
  105. sed -i '/net.ipv6.conf.all.forwarding/d' /etc/sysctl.d/99-sysctl.conf
  106. sed -i '/net.ipv6.conf.default.forwarding/d' /etc/sysctl.d/99-sysctl.conf
  107. sed -i '/net.ipv6.conf.lo.forwarding/d' /etc/sysctl.d/99-sysctl.conf
  108. sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  109. sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  110. sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  111. sed -i '/net.ipv6.conf.all.accept_ra/d' /etc/sysctl.d/99-sysctl.conf
  112. sed -i '/net.ipv6.conf.default.accept_ra/d' /etc/sysctl.d/99-sysctl.conf
  113. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.d/99-sysctl.conf
  114. sed -i '/net.core.netdev_budget/d' /etc/sysctl.d/99-sysctl.conf
  115. sed -i '/net.core.netdev_budget_usecs/d' /etc/sysctl.d/99-sysctl.conf
  116. sed -i '/fs.file-max /d' /etc/sysctl.d/99-sysctl.conf
  117. sed -i '/net.core.rmem_max/d' /etc/sysctl.d/99-sysctl.conf
  118. sed -i '/net.core.wmem_max/d' /etc/sysctl.d/99-sysctl.conf
  119. sed -i '/net.core.rmem_default/d' /etc/sysctl.d/99-sysctl.conf
  120. sed -i '/net.core.wmem_default/d' /etc/sysctl.d/99-sysctl.conf
  121. sed -i '/net.core.somaxconn/d' /etc/sysctl.d/99-sysctl.conf
  122. sed -i '/net.ipv4.icmp_echo_ignore_all/d' /etc/sysctl.d/99-sysctl.conf
  123. sed -i '/net.ipv4.icmp_echo_ignore_broadcasts/d' /etc/sysctl.d/99-sysctl.conf
  124. sed -i '/net.ipv4.icmp_ignore_bogus_error_responses/d' /etc/sysctl.d/99-sysctl.conf
  125. sed -i '/net.ipv4.conf.all.accept_redirects/d' /etc/sysctl.d/99-sysctl.conf
  126. sed -i '/net.ipv4.conf.default.accept_redirects/d' /etc/sysctl.d/99-sysctl.conf
  127. sed -i '/net.ipv4.conf.all.secure_redirects/d' /etc/sysctl.d/99-sysctl.conf
  128. sed -i '/net.ipv4.conf.default.secure_redirects/d' /etc/sysctl.d/99-sysctl.conf
  129. sed -i '/net.ipv4.conf.all.send_redirects/d' /etc/sysctl.d/99-sysctl.conf
  130. sed -i '/net.ipv4.conf.default.send_redirects/d' /etc/sysctl.d/99-sysctl.conf
  131. sed -i '/net.ipv4.conf.default.rp_filter/d' /etc/sysctl.d/99-sysctl.conf
  132. sed -i '/net.ipv4.conf.all.rp_filter/d' /etc/sysctl.d/99-sysctl.conf
  133. sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.d/99-sysctl.conf
  134. sed -i '/net.ipv4.tcp_keepalive_intvl/d' /etc/sysctl.d/99-sysctl.conf
  135. sed -i '/net.ipv4.tcp_keepalive_probes/d' /etc/sysctl.d/99-sysctl.conf
  136. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.d/99-sysctl.conf
  137. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.d/99-sysctl.conf
  138. sed -i '/net.ipv4.tcp_rfc1337/d' /etc/sysctl.d/99-sysctl.conf
  139. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.d/99-sysctl.conf
  140. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.d/99-sysctl.conf
  141. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.d/99-sysctl.conf
  142. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.d/99-sysctl.conf
  143. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.d/99-sysctl.conf
  144. sed -i '/net.ipv4.tcp_fastopen/d' /etc/sysctl.d/99-sysctl.conf
  145. sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.d/99-sysctl.conf
  146. sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.d/99-sysctl.conf
  147. sed -i '/net.ipv4.udp_rmem_min/d' /etc/sysctl.d/99-sysctl.conf
  148. sed -i '/net.ipv4.udp_wmem_min/d' /etc/sysctl.d/99-sysctl.conf
  149. sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.d/99-sysctl.conf
  150. sed -i '/net.ipv4.conf.all.arp_ignore /d' /etc/sysctl.d/99-sysctl.conf
  151. sed -i '/net.ipv4.conf.default.arp_ignore/d' /etc/sysctl.d/99-sysctl.conf
  152. sed -i '/net.ipv4.conf.all.arp_announce/d' /etc/sysctl.d/99-sysctl.conf
  153. sed -i '/net.ipv4.conf.default.arp_announce/d' /etc/sysctl.d/99-sysctl.conf
  154. sed -i '/net.ipv4.tcp_autocorking/d' /etc/sysctl.d/99-sysctl.conf
  155. sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.d/99-sysctl.conf
  156. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.d/99-sysctl.conf
  157. sed -i '/net.core.default_qdisc/d' /etc/sysctl.d/99-sysctl.conf
  158. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.d/99-sysctl.conf
  159. sed -i '/net.ipv4.tcp_notsent_lowat/d' /etc/sysctl.d/99-sysctl.conf
  160. sed -i '/net.ipv4.tcp_no_metrics_save/d' /etc/sysctl.d/99-sysctl.conf
  161. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.d/99-sysctl.conf
  162. sed -i '/net.ipv4.tcp_ecn_fallback/d' /etc/sysctl.d/99-sysctl.conf
  163. sed -i '/net.ipv4.tcp_frto/d' /etc/sysctl.d/99-sysctl.conf
  164. sed -i '/net.ipv6.conf.all.accept_redirects/d' /etc/sysctl.d/99-sysctl.conf
  165. sed -i '/net.ipv6.conf.default.accept_redirects/d' /etc/sysctl.d/99-sysctl.conf
  166. sed -i '/vm.swappiness/d' /etc/sysctl.d/99-sysctl.conf
  167. sed -i '/net.ipv4.ip_unprivileged_port_start/d' /etc/sysctl.d/99-sysctl.conf
  168. sed -i '/vm.overcommit_memory/d' /etc/sysctl.d/99-sysctl.conf
  169. sed -i '/net.ipv4.neigh.default.gc_thresh3/d' /etc/sysctl.d/99-sysctl.conf
  170. sed -i '/net.ipv4.neigh.default.gc_thresh2/d' /etc/sysctl.d/99-sysctl.conf
  171. sed -i '/net.ipv4.neigh.default.gc_thresh1/d' /etc/sysctl.d/99-sysctl.conf
  172. sed -i '/net.ipv6.neigh.default.gc_thresh3/d' /etc/sysctl.d/99-sysctl.conf
  173. sed -i '/net.ipv6.neigh.default.gc_thresh2/d' /etc/sysctl.d/99-sysctl.conf
  174. sed -i '/net.ipv6.neigh.default.gc_thresh1/d' /etc/sysctl.d/99-sysctl.conf
  175. sed -i '/net.netfilter.nf_conntrack_max/d' /etc/sysctl.d/99-sysctl.conf
  176. sed -i '/net.nf_conntrack_max/d' /etc/sysctl.d/99-sysctl.conf
  177. sed -i '/net.netfilter.nf_conntrack_tcp_timeout_fin_wait/d' /etc/sysctl.d/99-sysctl.conf
  178. sed -i '/net.netfilter.nf_conntrack_tcp_timeout_time_wait/d' /etc/sysctl.d/99-sysctl.conf
  179. sed -i '/net.netfilter.nf_conntrack_tcp_timeout_close_wait/d' /etc/sysctl.d/99-sysctl.conf
  180. sed -i '/net.netfilter.nf_conntrack_tcp_timeout_established/d' /etc/sysctl.d/99-sysctl.conf
  181. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.d/99-sysctl.conf
  182. sed -i '/fs.inotify.max_user_watches/d' /etc/sysctl.d/99-sysctl.conf
  183. sed -i '/net.ipv4.tcp_low_latency/d' /etc/sysctl.d/99-sysctl.conf
  184. cat >'/etc/sysctl.d/99-sysctl.conf' <<EOF
  185. net.ipv4.tcp_fack = 1
  186. net.ipv4.tcp_early_retrans = 3
  187. net.ipv4.neigh.default.unres_qlen=10000
  188. net.ipv4.conf.all.route_localnet=1
  189. net.ipv4.ip_forward = 1
  190. net.ipv4.conf.all.forwarding = 1
  191. net.ipv4.conf.default.forwarding = 1
  192. #net.ipv6.conf.all.forwarding = 1 #awsipv6问题
  193. net.ipv6.conf.default.forwarding = 1
  194. net.ipv6.conf.lo.forwarding = 1
  195. net.ipv6.conf.all.disable_ipv6 = 0
  196. net.ipv6.conf.default.disable_ipv6 = 0
  197. net.ipv6.conf.lo.disable_ipv6 = 0
  198. net.ipv6.conf.all.accept_ra = 2
  199. net.ipv6.conf.default.accept_ra = 2
  200. net.core.netdev_max_backlog = 100000
  201. net.core.netdev_budget = 50000
  202. net.core.netdev_budget_usecs = 5000
  203. #fs.file-max = 51200
  204. net.core.rmem_max = 67108864
  205. net.core.wmem_max = 67108864
  206. net.core.rmem_default = 67108864
  207. net.core.wmem_default = 67108864
  208. net.core.optmem_max = 65536
  209. net.core.somaxconn = 1000000
  210. net.ipv4.icmp_echo_ignore_all = 0
  211. net.ipv4.icmp_echo_ignore_broadcasts = 1
  212. net.ipv4.icmp_ignore_bogus_error_responses = 1
  213. net.ipv4.conf.all.accept_redirects = 0
  214. net.ipv4.conf.default.accept_redirects = 0
  215. net.ipv4.conf.all.secure_redirects = 0
  216. net.ipv4.conf.default.secure_redirects = 0
  217. net.ipv4.conf.all.send_redirects = 0
  218. net.ipv4.conf.default.send_redirects = 0
  219. net.ipv4.conf.default.rp_filter = 0
  220. net.ipv4.conf.all.rp_filter = 0
  221. net.ipv4.tcp_keepalive_time = 600
  222. net.ipv4.tcp_keepalive_intvl = 15
  223. net.ipv4.tcp_keepalive_probes = 2
  224. net.ipv4.tcp_synack_retries = 1
  225. net.ipv4.tcp_syncookies = 1
  226. net.ipv4.tcp_rfc1337 = 0
  227. net.ipv4.tcp_timestamps = 1
  228. net.ipv4.tcp_tw_reuse = 0
  229. net.ipv4.tcp_fin_timeout = 15
  230. net.ipv4.ip_local_port_range = 1024 65535
  231. net.ipv4.tcp_max_tw_buckets = 5000
  232. net.ipv4.tcp_fastopen = 3
  233. net.ipv4.tcp_rmem = 4096 87380 67108864
  234. net.ipv4.tcp_wmem = 4096 65536 67108864
  235. net.ipv4.udp_rmem_min = 8192
  236. net.ipv4.udp_wmem_min = 8192
  237. net.ipv4.tcp_mtu_probing = 1
  238. net.ipv4.tcp_autocorking = 0
  239. net.ipv4.tcp_slow_start_after_idle = 0
  240. net.ipv4.tcp_max_syn_backlog = 819200
  241. net.ipv4.tcp_notsent_lowat = 16384
  242. net.ipv4.tcp_no_metrics_save = 0
  243. net.ipv4.tcp_ecn = 1
  244. net.ipv4.tcp_ecn_fallback = 1
  245. net.ipv4.tcp_frto = 0
  246. net.ipv6.conf.all.accept_redirects = 0
  247. net.ipv6.conf.default.accept_redirects = 0
  248. net.ipv4.neigh.default.gc_thresh3=8192
  249. net.ipv4.neigh.default.gc_thresh2=4096
  250. net.ipv4.neigh.default.gc_thresh1=2048
  251. net.ipv6.neigh.default.gc_thresh3=8192
  252. net.ipv6.neigh.default.gc_thresh2=4096
  253. net.ipv6.neigh.default.gc_thresh1=2048
  254. net.ipv4.tcp_orphan_retries = 1
  255. net.ipv4.tcp_retries2 = 5
  256. vm.swappiness = 1
  257. vm.overcommit_memory = 1
  258. kernel.pid_max=64000
  259. net.netfilter.nf_conntrack_max = 262144
  260. net.nf_conntrack_max = 262144
  261. ## Enable bbr
  262. net.core.default_qdisc = fq
  263. net.ipv4.tcp_congestion_control = bbr
  264. net.ipv4.tcp_low_latency = 1
  265. EOF
  266. sysctl -p
  267. sysctl --system
  268. echo always >/sys/kernel/mm/transparent_hugepage/enabled
  269. cat >'/etc/systemd/system.conf' <<EOF
  270. [Manager]
  271. #DefaultTimeoutStartSec=90s
  272. DefaultTimeoutStopSec=30s
  273. #DefaultRestartSec=100ms
  274. DefaultLimitCORE=infinity
  275. DefaultLimitNOFILE=infinity
  276. DefaultLimitNPROC=infinity
  277. DefaultTasksMax=infinity
  278. EOF
  279. cat >'/etc/security/limits.conf' <<EOF
  280. root soft nofile 1000000
  281. root hard nofile 1000000
  282. root soft nproc unlimited
  283. root hard nproc unlimited
  284. root soft core unlimited
  285. root hard core unlimited
  286. root hard memlock unlimited
  287. root soft memlock unlimited
  288. * soft nofile 1000000
  289. * hard nofile 1000000
  290. * soft nproc unlimited
  291. * hard nproc unlimited
  292. * soft core unlimited
  293. * hard core unlimited
  294. * hard memlock unlimited
  295. * soft memlock unlimited
  296. EOF
  297. sed -i '/ulimit -SHn/d' /etc/profile
  298. sed -i '/ulimit -SHu/d' /etc/profile
  299. echo "ulimit -SHn 1000000" >>/etc/profile
  300. if grep -q "pam_limits.so" /etc/pam.d/common-session; then
  301. :
  302. else
  303. sed -i '/required pam_limits.so/d' /etc/pam.d/common-session
  304. echo "session required pam_limits.so" >>/etc/pam.d/common-session
  305. fi
  306. systemctl daemon-reload
  307. echo -e "${Info}优化方案2应用结束,可能需要重启!"
  308. }
  309. # 函数:生成并写入 Linux 内核网络优化配置
  310. # 参数(可选,按顺序):
  311. # $1: 延迟 (ms,默认 100)
  312. # $2: 本地带宽 (Mbps,默认 1000)
  313. # $3: VPS 带宽 (Mbps,默认 1000)
  314. # $4: VPS 内存 (MB,默认自动获取)
  315. optimizing_system_radicalizate() {
  316. # 设置默认值
  317. local latency_default=100
  318. local local_bw_default=1000
  319. local vps_bw_default=1000
  320. local vps_mem_default=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo)
  321. # 提示用户输入参数
  322. echo -e "请输入参数(用空格隔开):延迟(ms) 本地带宽(Mbps) VPS带宽(Mbps) VPS内存(MB)"
  323. echo -e "可以输入单个或多个参数,未提供的参数将使用默认值"
  324. echo -e "示例1(完整参数):180 500 500 1024"
  325. echo -e "示例2(单个参数):200 # 结果:延迟=200ms, 本地带宽=1000Mbps, VPS带宽=1000Mbps, 内存=自动获取"
  326. echo -e "默认参数:延迟=$latency_default ms, 本地带宽=$local_bw_default Mbps, VPS带宽=$vps_bw_default Mbps, 内存=自动获取($vps_mem_default MB)"
  327. echo -e "将在 12 秒后使用默认参数,请输入参数并按回车提交(留空使用默认值):"
  328. # 设置 12 秒倒计时,静默等待输入
  329. local input
  330. if ! read -t 12 -r input; then
  331. echo -e "\n未输入参数或超时,使用默认参数..."
  332. local latency=$latency_default
  333. local local_bw=$local_bw_default
  334. local vps_bw=$vps_bw_default
  335. local vps_mem=$vps_mem_default
  336. else
  337. # 分割用户输入
  338. read -r latency local_bw vps_bw vps_mem <<<"$input"
  339. # 使用默认值补齐未提供的参数
  340. latency=${latency:-$latency_default}
  341. local_bw=${local_bw:-$local_bw_default}
  342. vps_bw=${vps_bw:-$vps_bw_default}
  343. vps_mem=${vps_mem:-$vps_mem_default}
  344. fi
  345. # 显示最终提交的参数信息
  346. echo -e "最终提交参数:延迟=$latency ms, 本地带宽=$local_bw Mbps, VPS带宽=$vps_bw Mbps, 内存=$vps_mem MB"
  347. sleep 1 # 延迟 1 秒
  348. # 检查输入参数是否有效
  349. if ! [[ "$latency" =~ ^[0-9]+$ ]] || ! [[ "$local_bw" =~ ^[0-9]+$ ]] ||
  350. ! [[ "$vps_bw" =~ ^[0-9]+$ ]] || ! [[ "$vps_mem" =~ ^[0-9]+$ ]]; then
  351. echo -e "Error: All parameters must be positive integers."
  352. return 1
  353. fi
  354. # 检查是否有 root 权限
  355. if [ "$EUID" -ne 0 ]; then
  356. echo -e "Error: This script requires root privileges to write to /etc/sysctl.d/99-sysctl.conf."
  357. return 1
  358. fi
  359. # 计算带宽延迟积 (BDP, 字节):min(local_bw, vps_bw) * latency / 8
  360. local min_bw=$((local_bw < vps_bw ? local_bw : vps_bw))
  361. local bdp=$((min_bw * 1000000 * latency / 8 / 1000))
  362. # 根据内存和 BDP 设置缓冲区大小 (上限不超过内存的 50%),使用整数运算
  363. local rmem_max=$((bdp * 2)) # 2 倍 BDP
  364. local wmem_max=$((bdp * 3 / 2)) # 1.5 倍 BDP
  365. local max_mem_bytes=$((vps_mem * 1024 * 1024 * 50 / 100))
  366. [[ $rmem_max -gt $max_mem_bytes ]] && rmem_max=$max_mem_bytes
  367. [[ $wmem_max -gt $max_mem_bytes ]] && wmem_max=$max_mem_bytes
  368. [[ $rmem_max -lt 1048576 ]] && rmem_max=1048576 # 最小 1MB
  369. [[ $wmem_max -lt 1048576 ]] && wmem_max=1048576 # 最小 1MB
  370. # 根据带宽和内存设置队列长度
  371. local netdev_max_backlog=$((min_bw * 10))
  372. [[ $netdev_max_backlog -gt 10000 ]] && netdev_max_backlog=10000
  373. [[ $netdev_max_backlog -lt 1000 ]] && netdev_max_backlog=1000
  374. local somaxconn=$((vps_mem * 20))
  375. [[ $somaxconn -gt 16384 ]] && somaxconn=16384
  376. [[ $somaxconn -lt 512 ]] && somaxconn=512
  377. local tcp_max_syn_backlog=$((somaxconn * 4))
  378. [[ $tcp_max_syn_backlog -gt 65536 ]] && tcp_max_syn_backlog=65536
  379. # 根据延迟设置初始拥塞窗口
  380. local tcp_init_cwnd=$((latency / 20 + 10))
  381. [[ $tcp_init_cwnd -gt 32 ]] && tcp_init_cwnd=32
  382. [[ $tcp_init_cwnd -lt 10 ]] && tcp_init_cwnd=10
  383. # 根据内存设置最小空闲内存 (约 10-15% 内存)
  384. local min_free_kbytes=$((vps_mem * 1024 * 12 / 100))
  385. [[ $min_free_kbytes -gt 524288 ]] && min_free_kbytes=524288 # 最大 512MB
  386. [[ $min_free_kbytes -lt 65536 ]] && min_free_kbytes=65536 # 最小 64MB
  387. # 目标配置文件
  388. local config_file="/etc/sysctl.d/99-sysctl.conf"
  389. local temp_file=$(mktemp)
  390. # 定义所有参数和值(包含测试中发现的额外参数)
  391. declare -A sysctl_params=(
  392. ["kernel.pid_max"]="65535"
  393. ["kernel.panic"]="1"
  394. ["kernel.sysrq"]="1"
  395. ["kernel.core_pattern"]="core_%e"
  396. ["kernel.printk"]="3 4 1 3"
  397. ["kernel.numa_balancing"]="0"
  398. ["kernel.sched_autogroup_enabled"]="0"
  399. ["vm.swappiness"]="5"
  400. ["vm.dirty_ratio"]="5"
  401. ["vm.dirty_background_ratio"]="2"
  402. ["vm.panic_on_oom"]="1"
  403. ["vm.overcommit_memory"]="1"
  404. ["vm.min_free_kbytes"]="$min_free_kbytes"
  405. ["net.core.netdev_max_backlog"]="$netdev_max_backlog"
  406. ["net.core.rmem_max"]="$rmem_max"
  407. ["net.core.wmem_max"]="$wmem_max"
  408. ["net.core.rmem_default"]="262144"
  409. ["net.core.wmem_default"]="262144"
  410. ["net.core.somaxconn"]="$somaxconn"
  411. ["net.core.optmem_max"]="262144"
  412. ["net.netfilter.nf_conntrack_max"]="262144"
  413. ["net.nf_conntrack_max"]="262144"
  414. ["net.ipv4.tcp_fastopen"]="3"
  415. ["net.ipv4.tcp_timestamps"]="1"
  416. ["net.ipv4.tcp_tw_reuse"]="1"
  417. ["net.ipv4.tcp_fin_timeout"]="10"
  418. ["net.ipv4.tcp_slow_start_after_idle"]="0"
  419. ["net.ipv4.tcp_max_tw_buckets"]="32768"
  420. ["net.ipv4.tcp_sack"]="1"
  421. ["net.ipv4.tcp_fack"]="1"
  422. ["net.ipv4.tcp_rmem"]="32768 262144 $rmem_max"
  423. ["net.ipv4.tcp_wmem"]="32768 262144 $wmem_max"
  424. ["net.ipv4.tcp_mtu_probing"]="1"
  425. ["net.ipv4.tcp_notsent_lowat"]="16384"
  426. ["net.ipv4.tcp_window_scaling"]="1"
  427. ["net.ipv4.tcp_adv_win_scale"]="2"
  428. ["net.ipv4.tcp_moderate_rcvbuf"]="1"
  429. ["net.ipv4.tcp_no_metrics_save"]="1"
  430. ["net.ipv4.tcp_init_cwnd"]="$tcp_init_cwnd"
  431. ["net.ipv4.tcp_max_syn_backlog"]="$tcp_max_syn_backlog"
  432. ["net.ipv4.tcp_max_orphans"]="32768"
  433. ["net.ipv4.tcp_synack_retries"]="2"
  434. ["net.ipv4.tcp_syn_retries"]="2"
  435. ["net.ipv4.tcp_abort_on_overflow"]="0"
  436. ["net.ipv4.tcp_stdurg"]="0"
  437. ["net.ipv4.tcp_rfc1337"]="0"
  438. ["net.ipv4.tcp_syncookies"]="1"
  439. ["net.ipv4.tcp_low_latency"]="1"
  440. ["net.ipv4.ip_local_port_range"]="1024 65535"
  441. ["net.ipv4.ip_no_pmtu_disc"]="0"
  442. ["net.ipv4.route.gc_timeout"]="100"
  443. ["net.ipv4.neigh.default.gc_stale_time"]="120"
  444. ["net.ipv4.neigh.default.gc_thresh3"]="4096"
  445. ["net.ipv4.neigh.default.gc_thresh2"]="2048"
  446. ["net.ipv4.neigh.default.gc_thresh1"]="512"
  447. ["net.ipv4.icmp_echo_ignore_broadcasts"]="1"
  448. ["net.ipv4.icmp_ignore_bogus_error_responses"]="1"
  449. ["net.ipv4.conf.all.rp_filter"]="1"
  450. ["net.ipv4.conf.default.rp_filter"]="1"
  451. ["net.ipv4.conf.all.arp_announce"]="2"
  452. ["net.ipv4.conf.default.arp_announce"]="2"
  453. ["net.ipv4.conf.all.arp_ignore"]="1"
  454. ["net.ipv4.conf.default.arp_ignore"]="1"
  455. )
  456. # 添加文件头部注释
  457. echo "# Generated sysctl configuration" >"$temp_file"
  458. echo "# Latency: $latency ms" >>"$temp_file"
  459. echo "# Local Bandwidth: $local_bw Mbps" >>"$temp_file"
  460. echo "# VPS Bandwidth: $vps_bw Mbps" >>"$temp_file"
  461. echo "# VPS Memory: $vps_mem MB" >>"$temp_file"
  462. echo "" >>"$temp_file"
  463. # 如果配置文件不存在,直接写入所有参数
  464. if [ ! -f "$config_file" ]; then
  465. for key in "${!sysctl_params[@]}"; do
  466. echo "$key=${sysctl_params[$key]}" >>"$temp_file"
  467. done
  468. else
  469. # 读取现有配置文件内容,去除多余空格
  470. cp "$config_file" "$temp_file.bak"
  471. while IFS='=' read -r key value; do
  472. key=$(echo "$key" | xargs) # 去除首尾空格
  473. value=$(echo "$value" | xargs) # 去除值中的多余空格
  474. if [ -n "$key" ] && [[ ! "$key" =~ ^# ]]; then
  475. if [[ -n "${sysctl_params[$key]}" ]]; then
  476. echo "$key=${sysctl_params[$key]}" >>"$temp_file.new"
  477. unset sysctl_params["$key"]
  478. else
  479. echo "$key=$value" >>"$temp_file.new"
  480. fi
  481. fi
  482. done <"$config_file"
  483. # 将新参数追加到临时文件
  484. for key in "${!sysctl_params[@]}"; do
  485. echo "$key=${sysctl_params[$key]}" >>"$temp_file.new"
  486. done
  487. # 合并并替换临时文件
  488. cat "$temp_file" >"$temp_file.final"
  489. cat "$temp_file.new" >>"$temp_file.final"
  490. mv "$temp_file.final" "$temp_file"
  491. rm -f "$temp_file.new" "$temp_file.bak"
  492. fi
  493. # 写入目标文件并应用配置
  494. mv "$temp_file" "$config_file"
  495. chmod 644 "$config_file"
  496. sysctl -p "$config_file" >/dev/null 2>&1
  497. sysctl --system >/dev/null 2>&1
  498. echo -e "${Info}激进方案应用完毕,有些设置可能需要重启生效!"
  499. }
  500. #处理传进来的参数 直接优化
  501. err() {
  502. echo "错误: $1"
  503. exit 1
  504. }
  505. while [ $# -gt 0 ]; do
  506. case $1 in
  507. op)
  508. optimizing_system_old # 调用函数
  509. exit
  510. ;;
  511. op2)
  512. optimizing_system_johnrosen1 # 调用函数
  513. exit
  514. ;;
  515. op3)
  516. optimizing_system_radicalizate # 调用函数
  517. exit
  518. ;;
  519. *)
  520. err "未知选项: \"$1\""
  521. ;;
  522. esac
  523. shift # 移动到下一个参数
  524. done
  525. # 检查github网络
  526. check_github() {
  527. # 检测域名的可访问性函数
  528. check_domain() {
  529. local domain="$1"
  530. if ! curl --max-time 5 --head --silent --fail "$domain" >/dev/null; then
  531. echo -e "${Error}无法访问 $domain,请检查网络或者本地DNS 或者访问频率过快而受限"
  532. github_network=0
  533. fi
  534. }
  535. # 检测所有域名的可访问性
  536. check_domain "https://raw.githubusercontent.com"
  537. check_domain "https://api.github.com"
  538. check_domain "https://github.com"
  539. if [ "$github_network" -eq 0 ]; then
  540. echo -e "${Error}github网络访问受限,将影响内核的安装以及脚本的检查更新,1秒后继续运行脚本"
  541. sleep 1
  542. else
  543. # 所有域名均可访问,打印成功提示
  544. echo -e "${Green_font_prefix}github可访问${Font_color_suffix},继续执行脚本..."
  545. fi
  546. }
  547. #检查连接
  548. checkurl() {
  549. local url="$1"
  550. local maxRetries=3
  551. local retryDelay=2
  552. if [[ -z "$url" ]]; then
  553. echo "错误:缺少URL参数!"
  554. exit 1
  555. fi
  556. local retries=0
  557. local responseCode=""
  558. while [[ -z "$responseCode" && $retries -lt $maxRetries ]]; do
  559. responseCode=$(curl --max-time 6 -s -L -m 10 --connect-timeout 5 -o /dev/null -w "%{http_code}" "$url")
  560. if [[ -z "$responseCode" ]]; then
  561. ((retries++))
  562. sleep $retryDelay
  563. fi
  564. done
  565. if [[ -n "$responseCode" && ("$responseCode" == "200" || "$responseCode" =~ ^3[0-9]{2}$) ]]; then
  566. echo "下载地址检查OK,继续!"
  567. else
  568. echo "下载地址检查出错,退出!"
  569. exit 1
  570. fi
  571. }
  572. #cn处理github加速
  573. check_cn() {
  574. # 检查是否安装了jq命令,如果没有安装则进行安装
  575. if ! command -v jq >/dev/null 2>&1; then
  576. if command -v yum >/dev/null 2>&1; then
  577. sudo yum install epel-release -y
  578. sudo yum install -y jq
  579. elif command -v apt-get >/dev/null 2>&1; then
  580. sudo apt-get update
  581. sudo apt-get install -y jq
  582. else
  583. echo "无法安装jq命令。请手动安装jq后再试。"
  584. exit 1
  585. fi
  586. fi
  587. # 获取当前IP地址,设置超时为3秒
  588. current_ip=$(curl -s --max-time 3 https://api.ipify.org)
  589. # 使用ip-api.com查询IP所在国家,设置超时为3秒
  590. response=$(curl -s --max-time 3 "http://ip-api.com/json/$current_ip")
  591. # 检查国家是否为中国
  592. country=$(echo "$response" | jq -r '.countryCode')
  593. if [[ "$country" == "CN" ]]; then
  594. local suffixes=(
  595. "https://gh.con.sh/"
  596. "https://gh-proxy.com/"
  597. "https://ghp.ci/"
  598. "https://gh.m-l.cc/"
  599. "https://down.npee.cn/?"
  600. "https://mirror.ghproxy.com/"
  601. "https://ghps.cc/"
  602. "https://gh.api.99988866.xyz/"
  603. "https://git.886.be/"
  604. "https://hub.gitmirror.com/"
  605. "https://pd.zwc365.com/"
  606. "https://gh.ddlc.top/"
  607. "https://slink.ltd/"
  608. "https://github.moeyy.xyz/"
  609. "https://ghproxy.crazypeace.workers.dev/"
  610. "https://gh.h233.eu.org/"
  611. )
  612. # 循环遍历每个后缀并测试组合的链接
  613. for suffix in "${suffixes[@]}"; do
  614. # 组合后缀和原始链接
  615. combined_url="$suffix$1"
  616. # 使用 curl -I 获取头部信息,提取状态码
  617. local response_code=$(curl --max-time 2 -sL -w "%{http_code}" -I "$combined_url" | head -n 1 | awk '{print $2}')
  618. # 检查响应码是否表示成功 (2xx)
  619. if [[ $response_code -ge 200 && $response_code -lt 300 ]]; then
  620. echo "$combined_url"
  621. return 0 # 返回可用链接,结束函数
  622. fi
  623. done
  624. # 如果没有找到有效链接,返回原始链接
  625. else
  626. echo "$1"
  627. return 1
  628. fi
  629. }
  630. #下载
  631. download_file() {
  632. url="$1"
  633. filename="$2"
  634. wget "$url" -O "$filename"
  635. status=$?
  636. if [ $status -eq 0 ]; then
  637. echo -e "\e[32m文件下载成功或已经是最新。\e[0m"
  638. else
  639. echo -e "\e[31m文件下载失败,退出状态码: $status\e[0m"
  640. exit 1
  641. fi
  642. }
  643. #檢查賦值
  644. check_empty() {
  645. local var_value=$1
  646. if [[ -z $var_value ]]; then
  647. echo "$var_value 是空值,退出!"
  648. exit 1
  649. fi
  650. }
  651. #安装BBR内核
  652. installbbr() {
  653. kernel_version="5.9.6"
  654. bit=$(uname -m)
  655. rm -rf bbr
  656. mkdir bbr && cd bbr || exit
  657. if [[ "${OS_type}" == "CentOS" ]]; then
  658. if [[ ${version} == "7" ]]; then
  659. if [[ ${bit} == "x86_64" ]]; then
  660. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  661. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}' | awk -F '[_]' '{print $3}')
  662. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Centos_Kernel' | grep '_latest_bbr_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  663. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}')
  664. #check_empty $github_ver
  665. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  666. #kernel_version=$github_ver
  667. #detele_kernel_head
  668. #headurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}')
  669. #imgurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep -v 'headers' | grep -v 'devel' | awk -F '"' '{print $4}')
  670. #headurl=https://github.com/ylx2016/kernel/releases/download/$github_tag/kernel-headers-${github_ver}-1.x86_64.rpm
  671. #imgurl=https://github.com/ylx2016/kernel/releases/download/$github_tag/kernel-${github_ver}-1.x86_64.rpm
  672. headurl=https://github.com/ylx2016/kernel/releases/download/Centos_Kernel_6.1.35_latest_bbr_2023.06.22-0855/kernel-headers-6.1.35-1.x86_64.rpm
  673. imgurl=https://github.com/ylx2016/kernel/releases/download/Centos_Kernel_6.1.35_latest_bbr_2023.06.22-0855/kernel-6.1.35-1.x86_64.rpm
  674. check_empty $imgurl
  675. headurl=$(check_cn $headurl)
  676. imgurl=$(check_cn $imgurl)
  677. download_file $headurl kernel-headers-c7.rpm
  678. download_file $imgurl kernel-c7.rpm
  679. yum install -y kernel-c7.rpm
  680. yum install -y kernel-headers-c7.rpm
  681. else
  682. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  683. fi
  684. fi
  685. elif [[ "${OS_type}" == "Debian" ]]; then
  686. if [[ ${bit} == "x86_64" ]]; then
  687. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  688. github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Debian_Kernel' | grep '_latest_bbr_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  689. github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}' | awk -F '[_]' '{print $1}')
  690. check_empty $github_ver
  691. echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  692. kernel_version=$github_ver
  693. detele_kernel_head
  694. headurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}')
  695. imgurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep -v 'headers' | grep -v 'devel' | awk -F '"' '{print $4}')
  696. #headurl=https://github.com/ylx2016/kernel/releases/download/$github_tag/linux-headers-${github_ver}_${github_ver}-1_amd64.deb
  697. #imgurl=https://github.com/ylx2016/kernel/releases/download/$github_tag/linux-image-${github_ver}_${github_ver}-1_amd64.deb
  698. headurl=$(check_cn $headurl)
  699. imgurl=$(check_cn $imgurl)
  700. download_file $headurl linux-headers-d10.deb
  701. download_file $imgurl linux-image-d10.deb
  702. dpkg -i linux-image-d10.deb
  703. dpkg -i linux-headers-d10.deb
  704. elif [[ ${bit} == "aarch64" ]]; then
  705. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  706. github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Debian_Kernel' | grep '_arm64_' | grep '_bbr_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  707. github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}' | awk -F '[_]' '{print $1}')
  708. echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  709. kernel_version=$github_ver
  710. detele_kernel_head
  711. headurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}')
  712. imgurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep -v 'headers' | grep -v 'devel' | awk -F '"' '{print $4}')
  713. #headurl=https://github.com/ylx2016/kernel/releases/download/$github_tag/linux-headers-${github_ver}_${github_ver}-1_amd64.deb
  714. #imgurl=https://github.com/ylx2016/kernel/releases/download/$github_tag/linux-image-${github_ver}_${github_ver}-1_amd64.deb
  715. check_empty $imgurl
  716. headurl=$(check_cn $headurl)
  717. imgurl=$(check_cn $imgurl)
  718. download_file $headurl linux-headers-d10.deb
  719. download_file $imgurl linux-image-d10.deb
  720. dpkg -i linux-image-d10.deb
  721. dpkg -i linux-headers-d10.deb
  722. else
  723. echo -e "${Error} 不支持x86_64及arm64/aarch64以外的系统 !" && exit 1
  724. fi
  725. fi
  726. cd .. && rm -rf bbr
  727. detele_kernel
  728. BBR_grub
  729. echo -e "${Tip} ${Red_font_prefix}请检查上面是否有内核信息,无内核千万别重启${Font_color_suffix}"
  730. echo -e "${Tip} ${Red_font_prefix}rescue不是正常内核,要排除这个${Font_color_suffix}"
  731. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBR${Font_color_suffix}"
  732. check_kernel
  733. stty erase '^H' && read -p "需要重启VPS后,才能开启BBR,是否现在重启 ? [Y/n] :" yn
  734. [ -z "${yn}" ] && yn="y"
  735. if [[ $yn == [Yy] ]]; then
  736. echo -e "${Info} VPS 重启中..."
  737. reboot
  738. fi
  739. #echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功及手动调整内核启动顺序"
  740. }
  741. #安装BBRplus内核 4.14.129
  742. installbbrplus() {
  743. kernel_version="4.14.160-bbrplus"
  744. bit=$(uname -m)
  745. rm -rf bbrplus
  746. mkdir bbrplus && cd bbrplus || exit
  747. if [[ "${OS_type}" == "CentOS" ]]; then
  748. if [[ ${version} == "7" ]]; then
  749. if [[ ${bit} == "x86_64" ]]; then
  750. kernel_version="4.14.129_bbrplus"
  751. detele_kernel_head
  752. headurl=https://github.com/cx9208/Linux-NetSpeed/raw/master/bbrplus/centos/7/kernel-headers-4.14.129-bbrplus.rpm
  753. imgurl=https://github.com/cx9208/Linux-NetSpeed/raw/master/bbrplus/centos/7/kernel-4.14.129-bbrplus.rpm
  754. headurl=$(check_cn $headurl)
  755. imgurl=$(check_cn $imgurl)
  756. download_file $headurl kernel-headers-c7.rpm
  757. download_file $imgurl kernel-c7.rpm
  758. yum install -y kernel-c7.rpm
  759. yum install -y kernel-headers-c7.rpm
  760. else
  761. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  762. fi
  763. fi
  764. elif [[ "${OS_type}" == "Debian" ]]; then
  765. if [[ ${bit} == "x86_64" ]]; then
  766. kernel_version="4.14.129-bbrplus"
  767. detele_kernel_head
  768. headurl=https://github.com/cx9208/Linux-NetSpeed/raw/master/bbrplus/debian-ubuntu/x64/linux-headers-4.14.129-bbrplus.deb
  769. imgurl=https://github.com/cx9208/Linux-NetSpeed/raw/master/bbrplus/debian-ubuntu/x64/linux-image-4.14.129-bbrplus.deb
  770. headurl=$(check_cn $headurl)
  771. imgurl=$(check_cn $imgurl)
  772. wget -O linux-headers.deb $headurl
  773. wget -O linux-image.deb $imgurl
  774. dpkg -i linux-image.deb
  775. dpkg -i linux-headers.deb
  776. else
  777. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  778. fi
  779. fi
  780. cd .. && rm -rf bbrplus
  781. detele_kernel
  782. BBR_grub
  783. echo -e "${Tip} ${Red_font_prefix}请检查上面是否有内核信息,无内核千万别重启${Font_color_suffix}"
  784. echo -e "${Tip} ${Red_font_prefix}rescue不是正常内核,要排除这个${Font_color_suffix}"
  785. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBRplus${Font_color_suffix}"
  786. check_kernel
  787. stty erase '^H' && read -p "需要重启VPS后,才能开启BBRplus,是否现在重启 ? [Y/n] :" yn
  788. [ -z "${yn}" ] && yn="y"
  789. if [[ $yn == [Yy] ]]; then
  790. echo -e "${Info} VPS 重启中..."
  791. reboot
  792. fi
  793. #echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功及手动调整内核启动顺序"
  794. }
  795. #安装Lotserver内核
  796. installlot() {
  797. bit=$(uname -m)
  798. if [[ ${bit} != "x86_64" ]]; then
  799. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  800. fi
  801. if [[ ${bit} == "x86_64" ]]; then
  802. bit='x64'
  803. fi
  804. if [[ ${bit} == "i386" ]]; then
  805. bit='x32'
  806. fi
  807. if [[ "${OS_type}" == "CentOS" ]]; then
  808. rpm --import http://${github}/lotserver/${release}/RPM-GPG-KEY-elrepo.org
  809. yum remove -y kernel-firmware
  810. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-firmware-${kernel_version}.rpm
  811. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-${kernel_version}.rpm
  812. yum remove -y kernel-headers
  813. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-headers-${kernel_version}.rpm
  814. yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-devel-${kernel_version}.rpm
  815. fi
  816. if [[ "${OS_type}" == "Debian" ]]; then
  817. deb_issue="$(cat /etc/issue)"
  818. deb_relese="$(echo $deb_issue | grep -io 'Ubuntu\|Debian' | sed -r 's/(.*)/\L\1/')"
  819. os_ver="$(dpkg --print-architecture)"
  820. [ -n "$os_ver" ] || exit 1
  821. if [ "$deb_relese" == 'ubuntu' ]; then
  822. deb_ver="$(echo $deb_issue | grep -o '[0-9]*\.[0-9]*' | head -n1)"
  823. if [ "$deb_ver" == "14.04" ]; then
  824. kernel_version="3.16.0-77-generic" && item="3.16.0-77-generic" && ver='trusty'
  825. elif [ "$deb_ver" == "16.04" ]; then
  826. kernel_version="4.8.0-36-generic" && item="4.8.0-36-generic" && ver='xenial'
  827. elif [ "$deb_ver" == "18.04" ]; then
  828. kernel_version="4.15.0-30-generic" && item="4.15.0-30-generic" && ver='bionic'
  829. else
  830. exit 1
  831. fi
  832. url='archive.ubuntu.com'
  833. urls='security.ubuntu.com'
  834. elif [ "$deb_relese" == 'debian' ]; then
  835. deb_ver="$(echo $deb_issue | grep -o '[0-9]*' | head -n1)"
  836. if [ "$deb_ver" == "7" ]; then
  837. kernel_version="3.2.0-4-${os_ver}" && item="3.2.0-4-${os_ver}" && ver='wheezy' && url='archive.debian.org' && urls='archive.debian.org'
  838. elif [ "$deb_ver" == "8" ]; then
  839. kernel_version="3.16.0-4-${os_ver}" && item="3.16.0-4-${os_ver}" && ver='jessie' && url='archive.debian.org' && urls='archive.debian.org'
  840. elif [ "$deb_ver" == "9" ]; then
  841. kernel_version="4.9.0-4-${os_ver}" && item="4.9.0-4-${os_ver}" && ver='stretch' && url='archive.debian.org' && urls='archive.debian.org'
  842. else
  843. exit 1
  844. fi
  845. fi
  846. [ -n "$item" ] && [ -n "$urls" ] && [ -n "$url" ] && [ -n "$ver" ] || exit 1
  847. if [ "$deb_relese" == 'ubuntu' ]; then
  848. echo "deb http://${url}/${deb_relese} ${ver} main restricted universe multiverse" >/etc/apt/sources.list
  849. echo "deb http://${url}/${deb_relese} ${ver}-updates main restricted universe multiverse" >>/etc/apt/sources.list
  850. echo "deb http://${url}/${deb_relese} ${ver}-backports main restricted universe multiverse" >>/etc/apt/sources.list
  851. echo "deb http://${urls}/${deb_relese} ${ver}-security main restricted universe multiverse" >>/etc/apt/sources.list
  852. apt-get update || apt-get --allow-releaseinfo-change update
  853. apt-get install --no-install-recommends -y linux-image-${item}
  854. elif [ "$deb_relese" == 'debian' ]; then
  855. echo "deb http://${url}/${deb_relese} ${ver} main" >/etc/apt/sources.list
  856. echo "deb-src http://${url}/${deb_relese} ${ver} main" >>/etc/apt/sources.list
  857. echo "deb http://${urls}/${deb_relese}-security ${ver}/updates main" >>/etc/apt/sources.list
  858. echo "deb-src http://${urls}/${deb_relese}-security ${ver}/updates main" >>/etc/apt/sources.list
  859. if [ "$deb_ver" == "8" ]; then
  860. dpkg -l | grep -q 'linux-base' || {
  861. wget --no-check-certificate -qO '/tmp/linux-base_3.5_all.deb' 'http://snapshot.debian.org/archive/debian/20120304T220938Z/pool/main/l/linux-base/linux-base_3.5_all.deb'
  862. dpkg -i '/tmp/linux-base_3.5_all.deb'
  863. }
  864. wget --no-check-certificate -qO '/tmp/linux-image-3.16.0-4-amd64_3.16.43-2+deb8u5_amd64.deb' 'http://snapshot.debian.org/archive/debian/20171008T163152Z/pool/main/l/linux/linux-image-3.16.0-4-amd64_3.16.43-2+deb8u5_amd64.deb'
  865. dpkg -i '/tmp/linux-image-3.16.0-4-amd64_3.16.43-2+deb8u5_amd64.deb'
  866. if [ $? -ne 0 ]; then
  867. exit 1
  868. fi
  869. elif [ "$deb_ver" == "9" ]; then
  870. dpkg -l | grep -q 'linux-base' || {
  871. wget --no-check-certificate -qO '/tmp/linux-base_4.5_all.deb' 'http://snapshot.debian.org/archive/debian/20160917T042239Z/pool/main/l/linux-base/linux-base_4.5_all.deb'
  872. dpkg -i '/tmp/linux-base_4.5_all.deb'
  873. }
  874. wget --no-check-certificate -qO '/tmp/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb' 'http://snapshot.debian.org/archive/debian/20171224T175424Z/pool/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb'
  875. dpkg -i '/tmp/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb'
  876. ##备选
  877. #https://sys.if.ci/download/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb
  878. #http://mirror.cs.uchicago.edu/debian-security/pool/updates/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb
  879. #https://debian.sipwise.com/debian-security/pool/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb
  880. #http://srv24.dsidata.sk/security.debian.org/pool/updates/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb
  881. #https://pubmirror.plutex.de/debian-security/pool/updates/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb
  882. #https://packages.mendix.com/debian/pool/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3_amd64.deb
  883. #http://snapshot.debian.org/archive/debian/20171224T175424Z/pool/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3+deb9u1_amd64.deb
  884. #http://snapshot.debian.org/archive/debian/20171231T180144Z/pool/main/l/linux/linux-image-4.9.0-4-amd64_4.9.65-3_amd64.deb
  885. if [ $? -ne 0 ]; then
  886. exit 1
  887. fi
  888. else
  889. exit 1
  890. fi
  891. fi
  892. apt-get autoremove -y
  893. [ -d '/var/lib/apt/lists' ] && find /var/lib/apt/lists -type f -delete
  894. fi
  895. detele_kernel
  896. BBR_grub
  897. echo -e "${Tip} ${Red_font_prefix}请检查上面是否有内核信息,无内核千万别重启${Font_color_suffix}"
  898. echo -e "${Tip} ${Red_font_prefix}rescue不是正常内核,要排除这个${Font_color_suffix}"
  899. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}Lotserver${Font_color_suffix}"
  900. check_kernel
  901. stty erase '^H' && read -p "需要重启VPS后,才能开启Lotserver,是否现在重启 ? [Y/n] :" yn
  902. [ -z "${yn}" ] && yn="y"
  903. if [[ $yn == [Yy] ]]; then
  904. echo -e "${Info} VPS 重启中..."
  905. reboot
  906. fi
  907. #echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功及手动调整内核启动顺序"
  908. }
  909. #安装xanmod内核 from xanmod.org
  910. installxanmod() {
  911. kernel_version="5.5.1-xanmod1"
  912. bit=$(uname -m)
  913. if [[ ${bit} != "x86_64" ]]; then
  914. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  915. fi
  916. rm -rf xanmod
  917. mkdir xanmod && cd xanmod || exit
  918. if [[ "${OS_type}" == "CentOS" ]]; then
  919. if [[ ${version} == "7" ]]; then
  920. if [[ ${bit} == "x86_64" ]]; then
  921. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  922. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Centos_Kernel' | grep '_lts_latest_' | grep 'xanmod' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  923. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}')
  924. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  925. #kernel_version=$github_ver
  926. #detele_kernel_head
  927. #headurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}')
  928. #imgurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep -v 'headers' | grep -v 'devel' | awk -F '"' '{print $4}')
  929. headurl=https://github.com/ylx2016/kernel/releases/download/Centos_Kernel_5.15.95-xanmod1_lts_latest_2023.02.24-2159/kernel-headers-5.15.95_xanmod1-1.x86_64.rpm
  930. imgurl=https://github.com/ylx2016/kernel/releases/download/Centos_Kernel_5.15.95-xanmod1_lts_latest_2023.02.24-2159/kernel-5.15.95_xanmod1-1.x86_64.rpm
  931. check_empty $imgurl
  932. headurl=$(check_cn $headurl)
  933. imgurl=$(check_cn $imgurl)
  934. download_file $headurl kernel-headers-c7.rpm
  935. download_file $imgurl kernel-c7.rpm
  936. yum install -y kernel-c7.rpm
  937. yum install -y kernel-headers-c7.rpm
  938. else
  939. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  940. fi
  941. elif [[ ${version} == "8" ]]; then
  942. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  943. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Centos_Kernel' | grep '_lts_C8_latest_' | grep 'xanmod' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  944. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}')
  945. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  946. #kernel_version=$github_ver
  947. #detele_kernel_head
  948. #headurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}')
  949. #imgurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep -v 'headers' | grep -v 'devel' | awk -F '"' '{print $4}')
  950. headurl=https://github.com/ylx2016/kernel/releases/download/Centos_Kernel_5.15.81-xanmod1_lts_C8_latest_2022.12.06-1614/kernel-headers-5.15.81_xanmod1-1.x86_64.rpm
  951. imgurl=https://github.com/ylx2016/kernel/releases/download/Centos_Kernel_5.15.81-xanmod1_lts_C8_latest_2022.12.06-1614/kernel-5.15.81_xanmod1-1.x86_64.rpm
  952. check_empty $imgurl
  953. headurl=$(check_cn $headurl)
  954. imgurl=$(check_cn $imgurl)
  955. wget -O kernel-headers-c8.rpm $headurl
  956. wget -O kernel-c8.rpm $imgurl
  957. yum install -y kernel-c8.rpm
  958. yum install -y kernel-headers-c8.rpm
  959. fi
  960. elif [[ "${OS_type}" == "Debian" ]]; then
  961. if [[ ${bit} == "x86_64" ]]; then
  962. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  963. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Debian_Kernel' | grep '_lts_latest_' | grep 'xanmod' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  964. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}')
  965. #check_empty $github_ver
  966. #echo -e "获取的xanmod lts版本号为:${github_ver}"
  967. #kernel_version=$github_ver
  968. #detele_kernel_head
  969. #headurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}')
  970. #imgurl=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep -v 'headers' | grep -v 'devel' | awk -F '"' '{print $4}')
  971. headurl=https://github.com/ylx2016/kernel/releases/download/Debian_Kernel_5.15.95-xanmod1_lts_latest_2023.02.24-2210/linux-headers-5.15.95-xanmod1_5.15.95-xanmod1-1_amd64.deb
  972. imgurl=https://github.com/ylx2016/kernel/releases/download/Debian_Kernel_5.15.95-xanmod1_lts_latest_2023.02.24-2210/linux-image-5.15.95-xanmod1_5.15.95-xanmod1-1_amd64.deb
  973. check_empty $imgurl
  974. headurl=$(check_cn $headurl)
  975. imgurl=$(check_cn $imgurl)
  976. download_file $headurl linux-headers-d10.deb
  977. download_file $imgurl linux-image-d10.deb
  978. dpkg -i linux-image-d10.deb
  979. dpkg -i linux-headers-d10.deb
  980. else
  981. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  982. fi
  983. fi
  984. cd .. && rm -rf xanmod
  985. detele_kernel
  986. BBR_grub
  987. echo -e "${Tip} ${Red_font_prefix}请检查上面是否有内核信息,无内核千万别重启${Font_color_suffix}"
  988. echo -e "${Tip} ${Red_font_prefix}rescue不是正常内核,要排除这个${Font_color_suffix}"
  989. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBR${Font_color_suffix}"
  990. check_kernel
  991. stty erase '^H' && read -p "需要重启VPS后,才能开启BBR,是否现在重启 ? [Y/n] :" yn
  992. [ -z "${yn}" ] && yn="y"
  993. if [[ $yn == [Yy] ]]; then
  994. echo -e "${Info} VPS 重启中..."
  995. reboot
  996. fi
  997. #echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功及手动调整内核启动顺序"
  998. }
  999. #安装bbr2内核 集成到xanmod内核了
  1000. #安装bbrplus 新内核
  1001. #2021.3.15 开始由https://github.com/UJX6N/bbrplus-5.19 替换bbrplusnew
  1002. #2021.4.12 地址更新为https://github.com/ylx2016/kernel/releases
  1003. #2021.9.2 再次改为https://github.com/UJX6N/bbrplus
  1004. #2022.9.6 改为https://github.com/UJX6N/bbrplus-5.19
  1005. #2022.11.24 改为https://github.com/UJX6N/bbrplus-6.x_stable
  1006. installbbrplusnew() {
  1007. github_ver_plus=$(curl -s https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases | grep /bbrplus-6.x_stable/releases/tag/ | head -1 | awk -F "[/]" '{print $8}' | awk -F "[\"]" '{print $1}')
  1008. github_ver_plus_num=$(curl -s https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases | grep /bbrplus-6.x_stable/releases/tag/ | head -1 | awk -F "[/]" '{print $8}' | awk -F "[\"]" '{print $1}' | awk -F "[-]" '{print $1}')
  1009. echo -e "获取的UJX6N的bbrplus-6.x_stable版本号为:${Green_font_prefix}${github_ver_plus}${Font_color_suffix}"
  1010. echo -e "如果下载地址出错,可能当前正在更新,超过半天还是出错请反馈,大陆自行解决污染问题"
  1011. echo -e "${Green_font_prefix}安装失败这边反馈,内核问题给UJX6N反馈${Font_color_suffix}"
  1012. # kernel_version=$github_ver_plus
  1013. bit=$(uname -m)
  1014. #if [[ ${bit} != "x86_64" ]]; then
  1015. # echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  1016. #fi
  1017. rm -rf bbrplusnew
  1018. mkdir bbrplusnew && cd bbrplusnew || exit
  1019. if [[ "${OS_type}" == "CentOS" ]]; then
  1020. if [[ ${version} == "7" ]]; then
  1021. if [[ ${bit} == "x86_64" ]]; then
  1022. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Centos_Kernel' | grep '_latest_bbrplus_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  1023. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}' | awk -F '[_]' '{print $1}')
  1024. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  1025. kernel_version=${github_ver_plus_num}-bbrplus
  1026. detele_kernel_head
  1027. headurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'rpm' | grep 'headers' | grep 'el7' | awk -F '"' '{print $4}' | grep 'http')
  1028. imgurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'rpm' | grep -v 'devel' | grep -v 'headers' | grep -v 'Source' | grep 'el7' | awk -F '"' '{print $4}' | grep 'http')
  1029. headurl=$(check_cn $headurl)
  1030. imgurl=$(check_cn $imgurl)
  1031. wget -O kernel-c7.rpm $headurl
  1032. wget -O kernel-headers-c7.rpm $imgurl
  1033. yum install -y kernel-c7.rpm
  1034. yum install -y kernel-headers-c7.rpm
  1035. else
  1036. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  1037. fi
  1038. fi
  1039. if [[ ${version} == "8" ]]; then
  1040. if [[ ${bit} == "x86_64" ]]; then
  1041. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Centos_Kernel' | grep '_latest_bbrplus_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  1042. #github_ver=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'rpm' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}' | awk -F '[_]' '{print $1}')
  1043. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  1044. kernel_version=${github_ver_plus_num}-bbrplus
  1045. detele_kernel_head
  1046. headurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'rpm' | grep 'headers' | grep 'el8.x86_64' | grep 'https' | awk -F '"' '{print $4}' | grep 'http')
  1047. imgurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'rpm' | grep -v 'devel' | grep -v 'headers' | grep -v 'Source' | grep 'el8.x86_64' | grep 'https' | awk -F '"' '{print $4}' | grep 'http')
  1048. headurl=$(check_cn $headurl)
  1049. imgurl=$(check_cn $imgurl)
  1050. wget -O kernel-c8.rpm $headurl
  1051. wget -O kernel-headers-c8.rpm $imgurl
  1052. yum install -y kernel-c8.rpm
  1053. yum install -y kernel-headers-c8.rpm
  1054. else
  1055. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  1056. fi
  1057. fi
  1058. elif [[ "${OS_type}" == "Debian" ]]; then
  1059. if [[ ${bit} == "x86_64" ]]; then
  1060. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Ubuntu_Kernel' | grep '_latest_bbrplus_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  1061. #github_ver=$(curl -s 'http s://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}' | awk -F '[_]' '{print $1}')
  1062. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  1063. kernel_version=${github_ver_plus_num}-bbrplus
  1064. detele_kernel_head
  1065. headurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'https' | grep 'amd64.deb' | grep 'headers' | awk -F '"' '{print $4}' | grep 'http')
  1066. imgurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'https' | grep 'amd64.deb' | grep 'image' | awk -F '"' '{print $4}' | grep 'http')
  1067. headurl=$(check_cn $headurl)
  1068. imgurl=$(check_cn $imgurl)
  1069. download_file $headurl linux-headers-d10.deb
  1070. download_file $imgurl linux-image-d10.deb
  1071. dpkg -i linux-image-d10.deb
  1072. dpkg -i linux-headers-d10.deb
  1073. elif [[ ${bit} == "aarch64" ]]; then
  1074. #github_tag=$(curl -s 'https://api.github.com/repos/ylx2016/kernel/releases' | grep 'Ubuntu_Kernel' | grep '_latest_bbrplus_' | head -n 1 | awk -F '"' '{print $4}' | awk -F '[/]' '{print $8}')
  1075. #github_ver=$(curl -s 'http s://api.github.com/repos/ylx2016/kernel/releases' | grep ${github_tag} | grep 'deb' | grep 'headers' | awk -F '"' '{print $4}' | awk -F '[/]' '{print $9}' | awk -F '[-]' '{print $3}' | awk -F '[_]' '{print $1}')
  1076. #echo -e "获取的版本号为:${Green_font_prefix}${github_ver}${Font_color_suffix}"
  1077. kernel_version=${github_ver_plus_num}-bbrplus
  1078. detele_kernel_head
  1079. headurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'https' | grep 'arm64.deb' | grep 'headers' | awk -F '"' '{print $4}')
  1080. imgurl=$(curl -s 'https://api.github.com/repos/UJX6N/bbrplus-6.x_stable/releases' | grep ${github_ver_plus} | grep 'https' | grep 'arm64.deb' | grep 'image' | awk -F '"' '{print $4}')
  1081. headurl=$(check_cn $headurl)
  1082. imgurl=$(check_cn $imgurl)
  1083. download_file $headurl linux-headers-d10.deb
  1084. download_file $imgurl linux-image-d10.deb
  1085. dpkg -i linux-image-d10.deb
  1086. dpkg -i linux-headers-d10.deb
  1087. else
  1088. echo -e "${Error} 不支持x86_64及arm64/aarch64以外的系统 !" && exit 1
  1089. fi
  1090. fi
  1091. cd .. && rm -rf bbrplusnew
  1092. detele_kernel
  1093. BBR_grub
  1094. echo -e "${Tip} ${Red_font_prefix}请检查上面是否有内核信息,无内核千万别重启${Font_color_suffix}"
  1095. echo -e "${Tip} ${Red_font_prefix}rescue不是正常内核,要排除这个${Font_color_suffix}"
  1096. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBRplus${Font_color_suffix}"
  1097. check_kernel
  1098. stty erase '^H' && read -p "需要重启VPS后,才能开启BBRplus,是否现在重启 ? [Y/n] :" yn
  1099. [ -z "${yn}" ] && yn="y"
  1100. if [[ $yn == [Yy] ]]; then
  1101. echo -e "${Info} VPS 重启中..."
  1102. reboot
  1103. fi
  1104. #echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功及手动调整内核启动顺序"
  1105. }
  1106. #安装cloud内核
  1107. installcloud() {
  1108. # 检查当前系统发行版
  1109. local DISTRO=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
  1110. local ARCH=$(uname -m)
  1111. local VERSIONS=()
  1112. local VERSION_MAP_FILE="/tmp/version_map.txt"
  1113. # 检查架构并设置 IMAGE_URL 和 IMAGE_PATTERN
  1114. local IMAGE_URL
  1115. local IMAGE_PATTERN
  1116. if [ "$ARCH" == "x86_64" ]; then
  1117. IMAGE_URL="https://deb.debian.org/debian/pool/main/l/linux-signed-amd64/"
  1118. IMAGE_PATTERN='linux-image-[^"]+cloud-amd64_[^"]+_amd64\.deb'
  1119. elif [ "$ARCH" == "aarch64" ]; then
  1120. IMAGE_URL="https://deb.debian.org/debian/pool/main/l/linux-signed-arm64/"
  1121. IMAGE_PATTERN='linux-image-[^"]+cloud-arm64_[^"]+_arm64\.deb'
  1122. else
  1123. echo "不支持的架构:$ARCH,仅支持 x86_64 和 aarch64"
  1124. exit 1
  1125. fi
  1126. echo "检测到架构 $ARCH,正在从官方源获取cloud内核版本..."
  1127. # 获取 cloud 内核 .deb 文件列表
  1128. local DEB_FILES_RAW=$(curl -s "$IMAGE_URL" | grep -oP "$IMAGE_PATTERN")
  1129. # 清空临时映射文件
  1130. >"$VERSION_MAP_FILE"
  1131. # 提取 image 版本号并写入映射文件
  1132. while IFS= read -r file; do
  1133. if [[ "$file" =~ linux-image-([0-9]+\.[0-9]+(\.[0-9]+)?(-[0-9]+)?) ]]; then
  1134. local ver="${BASH_REMATCH[1]}"
  1135. echo "$ver:$file" >>"$VERSION_MAP_FILE"
  1136. fi
  1137. done <<<"$DEB_FILES_RAW"
  1138. # 读取排序并去重后的版本号
  1139. mapfile -t VERSIONS < <(cut -d':' -f1 "$VERSION_MAP_FILE" | sort -V -u)
  1140. # 确保有可用版本
  1141. if [ ${#VERSIONS[@]} -eq 0 ]; then
  1142. echo "未找到可用的cloud内核版本,请检查网络或反馈。"
  1143. exit 1
  1144. fi
  1145. echo "检测到 $DISTRO 系统(架构 $ARCH),以下是从 Debian 签名cloud内核列表中获取的版本(按从小到大排序,已去重):"
  1146. for i in "${!VERSIONS[@]}"; do
  1147. echo " $i) [${VERSIONS[$i]}]"
  1148. done
  1149. # 默认选择最新版本
  1150. local DEFAULT_INDEX=$((${#VERSIONS[@]} - 1))
  1151. echo "请选择要安装的cloud内核版本(10秒后默认选择最新版本回车加速 ${VERSIONS[$DEFAULT_INDEX]},输入'h'则使用apt安装非最新cloud及headers):"
  1152. read -t 10 -p "输入选项编号或'h': " CHOICE
  1153. # 检查是否使用 apt 安装 cloud 及 headers
  1154. local USE_APT=false
  1155. if [[ "$CHOICE" =~ ^[hH]$ ]]; then
  1156. USE_APT=true
  1157. if [ "$DISTRO" != "debian" ]; then
  1158. echo "错误:使用 'h' 安装 headers 仅支持 Debian 系统,当前系统为 $DISTRO"
  1159. exit 1
  1160. fi
  1161. CHOICE=$DEFAULT_INDEX
  1162. else
  1163. CHOICE=${CHOICE:-$DEFAULT_INDEX}
  1164. fi
  1165. # 验证输入
  1166. if [[ ! "$CHOICE" =~ ^[0-9]+$ ]] || [ "$CHOICE" -lt 0 ] || [ "$CHOICE" -ge "${#VERSIONS[@]}" ]; then
  1167. echo "无效选项,默认安装最新版本 ${VERSIONS[$DEFAULT_INDEX]}..."
  1168. CHOICE=$DEFAULT_INDEX
  1169. fi
  1170. local SELECTED_VERSION="${VERSIONS[$CHOICE]}"
  1171. local IMAGE_DEB_FILE=$(grep "^$SELECTED_VERSION:" "$VERSION_MAP_FILE" | tail -n 1 | cut -d':' -f2)
  1172. kernel_version=$SELECTED_VERSION
  1173. # 如果选择 'h',使用 apt 安装 cloud 内核及 headers
  1174. if [ "$USE_APT" = true ]; then
  1175. echo "正在使用 apt 安装 linux-image-cloud-${ARCH} 及 headers..."
  1176. sudo apt update
  1177. if [ "$ARCH" == "x86_64" ]; then
  1178. sudo apt install -y "linux-image-cloud-amd64" "linux-headers-cloud-amd64"
  1179. elif [ "$ARCH" == "aarch64" ]; then
  1180. sudo apt install -y "linux-image-cloud-arm64" "linux-headers-cloud-arm64"
  1181. fi
  1182. else
  1183. # 下载并安装 image
  1184. echo "正在下载 $IMAGE_URL$IMAGE_DEB_FILE ..."
  1185. curl -O "$IMAGE_URL$IMAGE_DEB_FILE"
  1186. echo "正在安装 $IMAGE_DEB_FILE ..."
  1187. sudo dpkg -i "$IMAGE_DEB_FILE"
  1188. sudo apt-get install -f -y # 解决可能的依赖问题
  1189. fi
  1190. # 清理下载的文件
  1191. rm -f "$IMAGE_DEB_FILE" "$VERSION_MAP_FILE"
  1192. detele_kernel
  1193. BBR_grub
  1194. echo -e "${Tip} ${Red_font_prefix}请检查上面是否有内核信息,无内核千万别重启${Font_color_suffix}"
  1195. echo -e "${Tip} ${Red_font_prefix}rescue不是正常内核,要排除这个${Font_color_suffix}"
  1196. echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBRplus${Font_color_suffix}"
  1197. check_kernel
  1198. stty erase '^H' && read -p "需要重启VPS后,才能开启BBRplus,是否现在重启 ? [Y/n] :" yn
  1199. [ -z "${yn}" ] && yn="y"
  1200. if [[ $yn == [Yy] ]]; then
  1201. echo -e "${Info} VPS 重启中..."
  1202. reboot
  1203. fi
  1204. }
  1205. #启用BBR+fq
  1206. startbbrfq() {
  1207. remove_bbr_lotserver
  1208. echo "net.core.default_qdisc=fq" >>/etc/sysctl.d/99-sysctl.conf
  1209. echo "net.ipv4.tcp_congestion_control=bbr" >>/etc/sysctl.d/99-sysctl.conf
  1210. sysctl --system
  1211. echo -e "${Info}BBR+FQ修改成功,重启生效!"
  1212. }
  1213. #启用BBR+fq_pie
  1214. startbbrfqpie() {
  1215. remove_bbr_lotserver
  1216. echo "net.core.default_qdisc=fq_pie" >>/etc/sysctl.d/99-sysctl.conf
  1217. echo "net.ipv4.tcp_congestion_control=bbr" >>/etc/sysctl.d/99-sysctl.conf
  1218. sysctl --system
  1219. echo -e "${Info}BBR+FQ_PIE修改成功,重启生效!"
  1220. }
  1221. #启用BBR+cake
  1222. startbbrcake() {
  1223. remove_bbr_lotserver
  1224. echo "net.core.default_qdisc=cake" >>/etc/sysctl.d/99-sysctl.conf
  1225. echo "net.ipv4.tcp_congestion_control=bbr" >>/etc/sysctl.d/99-sysctl.conf
  1226. sysctl --system
  1227. echo -e "${Info}BBR+cake修改成功,重启生效!"
  1228. }
  1229. #启用BBRplus
  1230. startbbrplus() {
  1231. remove_bbr_lotserver
  1232. echo "net.core.default_qdisc=fq" >>/etc/sysctl.d/99-sysctl.conf
  1233. echo "net.ipv4.tcp_congestion_control=bbrplus" >>/etc/sysctl.d/99-sysctl.conf
  1234. sysctl --system
  1235. echo -e "${Info}BBRplus修改成功,重启生效!"
  1236. }
  1237. #启用Lotserver
  1238. startlotserver() {
  1239. remove_bbr_lotserver
  1240. if [[ "${OS_type}" == "CentOS" ]]; then
  1241. yum install ethtool -y
  1242. else
  1243. apt-get update || apt-get --allow-releaseinfo-change update
  1244. apt-get install ethtool -y
  1245. fi
  1246. #bash <(wget -qO- https://git.io/lotServerInstall.sh) install
  1247. #echo | bash <(wget --no-check-certificate -qO- https://raw.githubusercontent.com/1265578519/lotServer/main/lotServerInstall.sh) install
  1248. echo | bash <(wget --no-check-certificate -qO- https://raw.githubusercontent.com/fei5seven/lotServer/master/lotServerInstall.sh) install
  1249. sed -i '/advinacc/d' /appex/etc/config
  1250. sed -i '/maxmode/d' /appex/etc/config
  1251. echo -e "advinacc=\"1\"
  1252. maxmode=\"1\"" >>/appex/etc/config
  1253. /appex/bin/lotServer.sh restart
  1254. start_menu
  1255. }
  1256. #启用BBR2+FQ
  1257. startbbr2fq() {
  1258. remove_bbr_lotserver
  1259. echo "net.core.default_qdisc=fq" >>/etc/sysctl.d/99-sysctl.conf
  1260. echo "net.ipv4.tcp_congestion_control=bbr2" >>/etc/sysctl.d/99-sysctl.conf
  1261. sysctl --system
  1262. echo -e "${Info}BBR2修改成功,重启生效!"
  1263. }
  1264. #启用BBR2+FQ_PIE
  1265. startbbr2fqpie() {
  1266. remove_bbr_lotserver
  1267. echo "net.core.default_qdisc=fq_pie" >>/etc/sysctl.d/99-sysctl.conf
  1268. echo "net.ipv4.tcp_congestion_control=bbr2" >>/etc/sysctl.d/99-sysctl.conf
  1269. sysctl --system
  1270. echo -e "${Info}BBR2修改成功,重启生效!"
  1271. }
  1272. #启用BBR2+CAKE
  1273. startbbr2cake() {
  1274. remove_bbr_lotserver
  1275. echo "net.core.default_qdisc=cake" >>/etc/sysctl.d/99-sysctl.conf
  1276. echo "net.ipv4.tcp_congestion_control=bbr2" >>/etc/sysctl.d/99-sysctl.conf
  1277. sysctl --system
  1278. echo -e "${Info}BBR2修改成功,重启生效!"
  1279. }
  1280. #开启ecn
  1281. startecn() {
  1282. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.d/99-sysctl.conf
  1283. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.conf
  1284. echo "net.ipv4.tcp_ecn=1" >>/etc/sysctl.d/99-sysctl.conf
  1285. sysctl --system
  1286. echo -e "${Info}开启ecn结束!"
  1287. }
  1288. #关闭ecn
  1289. closeecn() {
  1290. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.d/99-sysctl.conf
  1291. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.conf
  1292. echo "net.ipv4.tcp_ecn=0" >>/etc/sysctl.d/99-sysctl.conf
  1293. sysctl --system
  1294. echo -e "${Info}关闭ecn结束!"
  1295. }
  1296. #卸载bbr+锐速
  1297. remove_bbr_lotserver() {
  1298. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.d/99-sysctl.conf
  1299. sed -i '/net.core.default_qdisc/d' /etc/sysctl.d/99-sysctl.conf
  1300. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.d/99-sysctl.conf
  1301. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.conf
  1302. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  1303. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
  1304. sysctl --system
  1305. rm -rf bbrmod
  1306. if [[ -e /appex/bin/lotServer.sh ]]; then
  1307. echo | bash <(wget -qO- https://raw.githubusercontent.com/fei5seven/lotServer/master/lotServerInstall.sh) uninstall
  1308. fi
  1309. clear
  1310. # echo -e "${Info}:清除bbr/lotserver加速完成。"
  1311. # sleep 1s
  1312. }
  1313. #卸载全部加速
  1314. remove_all() {
  1315. rm -rf /etc/sysctl.d/*.conf
  1316. #rm -rf /etc/sysctl.conf
  1317. #touch /etc/sysctl.conf
  1318. if [ ! -f "/etc/sysctl.conf" ]; then
  1319. touch /etc/sysctl.conf
  1320. else
  1321. cat /dev/null >/etc/sysctl.conf
  1322. fi
  1323. sysctl --system
  1324. sed -i '/DefaultTimeoutStartSec/d' /etc/systemd/system.conf
  1325. sed -i '/DefaultTimeoutStopSec/d' /etc/systemd/system.conf
  1326. sed -i '/DefaultRestartSec/d' /etc/systemd/system.conf
  1327. sed -i '/DefaultLimitCORE/d' /etc/systemd/system.conf
  1328. sed -i '/DefaultLimitNOFILE/d' /etc/systemd/system.conf
  1329. sed -i '/DefaultLimitNPROC/d' /etc/systemd/system.conf
  1330. sed -i '/soft nofile/d' /etc/security/limits.conf
  1331. sed -i '/hard nofile/d' /etc/security/limits.conf
  1332. sed -i '/soft nproc/d' /etc/security/limits.conf
  1333. sed -i '/hard nproc/d' /etc/security/limits.conf
  1334. sed -i '/ulimit -SHn/d' /etc/profile
  1335. sed -i '/ulimit -SHn/d' /etc/profile
  1336. sed -i '/required pam_limits.so/d' /etc/pam.d/common-session
  1337. systemctl daemon-reload
  1338. rm -rf bbrmod
  1339. sed -i '/net.ipv4.tcp_retries2/d' /etc/sysctl.conf
  1340. sed -i '/net.ipv4.tcp_slow_start_after_idle/d' /etc/sysctl.conf
  1341. sed -i '/net.ipv4.tcp_fastopen/d' /etc/sysctl.conf
  1342. sed -i '/net.ipv4.tcp_ecn/d' /etc/sysctl.conf
  1343. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  1344. sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
  1345. sed -i '/fs.file-max/d' /etc/sysctl.conf
  1346. sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
  1347. sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
  1348. sed -i '/net.core.rmem_default/d' /etc/sysctl.conf
  1349. sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
  1350. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  1351. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  1352. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  1353. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  1354. sed -i '/net.ipv4.tcp_tw_recycle/d' /etc/sysctl.conf
  1355. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  1356. sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.conf
  1357. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  1358. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  1359. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  1360. sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf
  1361. sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf
  1362. sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.conf
  1363. sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
  1364. sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
  1365. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
  1366. sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
  1367. sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
  1368. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
  1369. sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
  1370. sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
  1371. sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
  1372. sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
  1373. sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
  1374. sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
  1375. sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
  1376. sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
  1377. sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
  1378. if [[ -e /appex/bin/lotServer.sh ]]; then
  1379. bash <(wget -qO- https://raw.githubusercontent.com/fei5seven/lotServer/master/lotServerInstall.sh) uninstall
  1380. fi
  1381. clear
  1382. echo -e "${Info}:清除加速完成。"
  1383. sleep 1s
  1384. }
  1385. optimizing_ddcc() {
  1386. sed -i '/net.ipv4.conf.all.rp_filter/d' /etc/sysctl.d/99-sysctl.conf
  1387. sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.d/99-sysctl.conf
  1388. sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.d/99-sysctl.conf
  1389. echo "net.ipv4.conf.all.rp_filter = 1" >>/etc/sysctl.d/99-sysctl.conf
  1390. echo "net.ipv4.tcp_syncookies = 1" >>/etc/sysctl.d/99-sysctl.conf
  1391. echo "net.ipv4.tcp_max_syn_backlog = 1024" >>/etc/sysctl.d/99-sysctl.conf
  1392. sysctl -p
  1393. sysctl --system
  1394. }
  1395. #更新脚本
  1396. Update_Shell() {
  1397. local shell_file
  1398. shell_file="$(readlink -f "$0")"
  1399. local shell_url="https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcp.sh"
  1400. # 下载最新版本的脚本
  1401. wget -O "/tmp/tcp.sh" "$shell_url" &>/dev/null
  1402. # 比较本地和远程脚本的 md5 值
  1403. local md5_local
  1404. local md5_remote
  1405. md5_local="$(md5sum "$shell_file" | awk '{print $1}')"
  1406. md5_remote="$(md5sum /tmp/tcp.sh | awk '{print $1}')"
  1407. if [ "$md5_local" != "$md5_remote" ]; then
  1408. # 替换本地脚本文件
  1409. cp "/tmp/tcp.sh" "$shell_file"
  1410. chmod +x "$shell_file"
  1411. echo "脚本已更新,请重新运行。"
  1412. exit 0
  1413. else
  1414. echo "脚本是最新版本,无需更新。"
  1415. fi
  1416. }
  1417. #切换到不卸载内核版本
  1418. gototcpx() {
  1419. clear
  1420. #wget -O tcpx.sh "https://github.com/ylx2016/Linux-NetSpeed/raw/master/tcpx.sh" && chmod +x tcpx.sh && ./tcpx.sh
  1421. bash <(wget -qO- https://github.com/ylx2016/Linux-NetSpeed/raw/master/tcpx.sh)
  1422. }
  1423. #切换到秋水逸冰BBR安装脚本
  1424. gototeddysun_bbr() {
  1425. clear
  1426. #wget https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh
  1427. bash <(wget -qO- https://github.com/teddysun/across/raw/master/bbr.sh)
  1428. }
  1429. #切换到一键DD安装系统脚本 新手勿入
  1430. gotodd() {
  1431. clear
  1432. echo DD使用git.beta.gs的脚本,知悉
  1433. sleep 1.5
  1434. #wget -O NewReinstall.sh https://github.com/fcurrk/reinstall/raw/master/NewReinstall.sh && chmod a+x NewReinstall.sh && bash NewReinstall.sh
  1435. bash <(wget -qO- https://github.com/fcurrk/reinstall/raw/master/NewReinstall.sh)
  1436. #wget -qO ~/Network-Reinstall-System-Modify.sh 'https://github.com/ylx2016/reinstall/raw/master/Network-Reinstall-System-Modify.sh' && chmod a+x ~/Network-Reinstall-System-Modify.sh && bash ~/Network-Reinstall-System-Modify.sh -UI_Options
  1437. }
  1438. #切换到检查当前IP质量/媒体解锁/邮箱通信脚本
  1439. gotoipcheck() {
  1440. clear
  1441. sleep 1.5
  1442. bash <(wget -qO- https://raw.githubusercontent.com/xykt/IPQuality/main/ip.sh)
  1443. #bash <(wget -qO- https://IP.Check.Place)
  1444. }
  1445. #禁用IPv6
  1446. closeipv6() {
  1447. clear
  1448. sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  1449. sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  1450. sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  1451. sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.conf
  1452. sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.conf
  1453. sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.conf
  1454. echo "net.ipv6.conf.all.disable_ipv6 = 1
  1455. net.ipv6.conf.default.disable_ipv6 = 1
  1456. net.ipv6.conf.lo.disable_ipv6 = 1" >>/etc/sysctl.d/99-sysctl.conf
  1457. sysctl --system
  1458. echo -e "${Info}禁用IPv6结束,可能需要重启!"
  1459. }
  1460. #开启IPv6
  1461. openipv6() {
  1462. clear
  1463. sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  1464. sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  1465. sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.d/99-sysctl.conf
  1466. sed -i '/net.ipv6.conf.all.disable_ipv6/d' /etc/sysctl.conf
  1467. sed -i '/net.ipv6.conf.default.disable_ipv6/d' /etc/sysctl.conf
  1468. sed -i '/net.ipv6.conf.lo.disable_ipv6/d' /etc/sysctl.conf
  1469. sed -i '/net.ipv6.conf.all.accept_ra/d' /etc/sysctl.conf
  1470. sed -i '/net.ipv6.conf.default.accept_ra/d' /etc/sysctl.conf
  1471. echo "net.ipv6.conf.all.disable_ipv6 = 0
  1472. net.ipv6.conf.default.disable_ipv6 = 0
  1473. net.ipv6.conf.lo.disable_ipv6 = 0
  1474. net.ipv6.conf.all.accept_ra = 2
  1475. net.ipv6.conf.default.accept_ra = 2" >>/etc/sysctl.d/99-sysctl.conf
  1476. sysctl --system
  1477. echo -e "${Info}开启IPv6结束,可能需要重启!"
  1478. }
  1479. #开始菜单
  1480. start_menu() {
  1481. clear
  1482. echo && echo -e " TCP加速 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix} from blog.ylx.me 母鸡慎用
  1483. ${Green_font_prefix}0.${Font_color_suffix} 升级脚本
  1484. ${Green_font_prefix}9.${Font_color_suffix} 切换到不卸载内核版本 ${Green_font_prefix}10.${Font_color_suffix} 切换到一键DD系统脚本
  1485. ${Green_font_prefix}60.${Font_color_suffix} 切换到检查当前IP质量/媒体解锁/邮箱通信脚本
  1486. ${Green_font_prefix}1.${Font_color_suffix} 安装 BBR原版内核
  1487. ${Green_font_prefix}2.${Font_color_suffix} 安装 BBRplus版内核 ${Green_font_prefix}5.${Font_color_suffix} 安装 BBRplus新版内核
  1488. ${Green_font_prefix}3.${Font_color_suffix} 安装 Lotserver(锐速)内核
  1489. ${Green_font_prefix}8.${Font_color_suffix} 安装 官方cloud内核 (支持debian系列)
  1490. ${Green_font_prefix}11.${Font_color_suffix} 使用BBR+FQ加速 ${Green_font_prefix}12.${Font_color_suffix} 使用BBR+FQ_PIE加速
  1491. ${Green_font_prefix}13.${Font_color_suffix} 使用BBR+CAKE加速 ${Green_font_prefix}14.${Font_color_suffix} 使用BBR2+FQ加速
  1492. ${Green_font_prefix}15.${Font_color_suffix} 使用BBR2+FQ_PIE加速 ${Green_font_prefix}16.${Font_color_suffix} 使用BBR2+CAKE加速
  1493. ${Green_font_prefix}17.${Font_color_suffix} 开启ECN ${Green_font_prefix}18.${Font_color_suffix} 关闭ECN
  1494. ${Green_font_prefix}19.${Font_color_suffix} 使用BBRplus+FQ版加速
  1495. ${Green_font_prefix}20.${Font_color_suffix} 使用Lotserver(锐速)加速
  1496. ${Green_font_prefix}21.${Font_color_suffix} 系统配置优化旧 ${Green_font_prefix}22.${Font_color_suffix} 系统配置优化新
  1497. ${Green_font_prefix}27.${Font_color_suffix} 系统配置优化激进方案
  1498. ${Green_font_prefix}23.${Font_color_suffix} 禁用IPv6 ${Green_font_prefix}24.${Font_color_suffix} 开启IPv6
  1499. ${Green_font_prefix}25.${Font_color_suffix} 卸载全部加速 ${Green_font_prefix}99.${Font_color_suffix} 退出脚本
  1500. ————————————————————————————————————————————————————————————————" &&
  1501. check_status
  1502. get_system_info
  1503. echo -e " 系统信息: ${Font_color_suffix}$opsy ${Green_font_prefix}$virtual${Font_color_suffix} $arch ${Green_font_prefix}$kern${Font_color_suffix} "
  1504. if [[ ${kernel_status} == "noinstall" ]]; then
  1505. echo -e " 当前状态: ${Green_font_prefix}未安装${Font_color_suffix} 加速内核 ${Red_font_prefix}请先安装内核${Font_color_suffix}"
  1506. else
  1507. echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} ${Red_font_prefix}${kernel_status}${Font_color_suffix} 加速内核 , ${Green_font_prefix}${run_status}${Font_color_suffix}"
  1508. fi
  1509. echo -e " 当前拥塞控制算法为: ${Green_font_prefix}${net_congestion_control}${Font_color_suffix} 当前队列算法为: ${Green_font_prefix}${net_qdisc}${Font_color_suffix} "
  1510. read -p " 请输入数字 :" num
  1511. case "$num" in
  1512. 0)
  1513. Update_Shell
  1514. ;;
  1515. 1)
  1516. check_sys_bbr
  1517. ;;
  1518. 2)
  1519. check_sys_bbrplus
  1520. ;;
  1521. 3)
  1522. check_sys_Lotsever
  1523. ;;
  1524. 5)
  1525. check_sys_bbrplusnew
  1526. ;;
  1527. 8)
  1528. check_sys_cloud
  1529. ;;
  1530. 9)
  1531. gototcpx
  1532. ;;
  1533. 10)
  1534. gotodd
  1535. ;;
  1536. 60)
  1537. gotoipcheck
  1538. ;;
  1539. 11)
  1540. startbbrfq
  1541. ;;
  1542. 12)
  1543. startbbrfqpie
  1544. ;;
  1545. 13)
  1546. startbbrcake
  1547. ;;
  1548. 14)
  1549. startbbr2fq
  1550. ;;
  1551. 15)
  1552. startbbr2fqpie
  1553. ;;
  1554. 16)
  1555. startbbr2cake
  1556. ;;
  1557. 17)
  1558. startecn
  1559. ;;
  1560. 18)
  1561. closeecn
  1562. ;;
  1563. 19)
  1564. startbbrplus
  1565. ;;
  1566. 20)
  1567. startlotserver
  1568. ;;
  1569. 21)
  1570. optimizing_system
  1571. ;;
  1572. 22)
  1573. optimizing_system_johnrosen1
  1574. ;;
  1575. 23)
  1576. closeipv6
  1577. ;;
  1578. 24)
  1579. openipv6
  1580. ;;
  1581. 25)
  1582. remove_all
  1583. ;;
  1584. 26)
  1585. optimizing_ddcc
  1586. ;;
  1587. 27)
  1588. optimizing_system_radicalizate
  1589. ;;
  1590. 99)
  1591. exit 1
  1592. ;;
  1593. *)
  1594. clear
  1595. echo -e "${Error}:请输入正确数字 [0-99]"
  1596. sleep 5s
  1597. start_menu
  1598. ;;
  1599. esac
  1600. }
  1601. #############内核管理组件#############
  1602. #删除多余内核
  1603. detele_kernel() {
  1604. if [[ "${OS_type}" == "CentOS" ]]; then
  1605. rpm_total=$(rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l)
  1606. if [ "${rpm_total}" ] >"1"; then
  1607. echo -e "检测到 ${rpm_total} 个其余内核,开始卸载..."
  1608. for ((integer = 1; integer <= ${rpm_total}; integer++)); do
  1609. rpm_del=$(rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer})
  1610. echo -e "开始卸载 ${rpm_del} 内核..."
  1611. rpm --nodeps -e ${rpm_del}
  1612. echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
  1613. done
  1614. echo --nodeps -e "内核卸载完毕,继续..."
  1615. else
  1616. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  1617. fi
  1618. elif [[ "${OS_type}" == "Debian" ]]; then
  1619. deb_total=$(dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l)
  1620. if [ "${deb_total}" ] >"1"; then
  1621. echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
  1622. for ((integer = 1; integer <= ${deb_total}; integer++)); do
  1623. deb_del=$(dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer})
  1624. echo -e "开始卸载 ${deb_del} 内核..."
  1625. apt-get purge -y ${deb_del}
  1626. apt-get autoremove -y
  1627. echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
  1628. done
  1629. echo -e "内核卸载完毕,继续..."
  1630. else
  1631. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  1632. fi
  1633. fi
  1634. }
  1635. detele_kernel_head() {
  1636. if [[ "${OS_type}" == "CentOS" ]]; then
  1637. rpm_total=$(rpm -qa | grep kernel-headers | grep -v "${kernel_version}" | grep -v "noarch" | wc -l)
  1638. if [ "${rpm_total}" ] >"1"; then
  1639. echo -e "检测到 ${rpm_total} 个其余head内核,开始卸载..."
  1640. for ((integer = 1; integer <= ${rpm_total}; integer++)); do
  1641. rpm_del=$(rpm -qa | grep kernel-headers | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer})
  1642. echo -e "开始卸载 ${rpm_del} headers内核..."
  1643. rpm --nodeps -e ${rpm_del}
  1644. echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
  1645. done
  1646. echo --nodeps -e "内核卸载完毕,继续..."
  1647. else
  1648. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  1649. fi
  1650. elif [[ "${OS_type}" == "Debian" ]]; then
  1651. deb_total=$(dpkg -l | grep linux-headers | awk '{print $2}' | grep -v "${kernel_version}" | wc -l)
  1652. if [ "${deb_total}" ] >"1"; then
  1653. echo -e "检测到 ${deb_total} 个其余head内核,开始卸载..."
  1654. for ((integer = 1; integer <= ${deb_total}; integer++)); do
  1655. deb_del=$(dpkg -l | grep linux-headers | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer})
  1656. echo -e "开始卸载 ${deb_del} headers内核..."
  1657. apt-get purge -y ${deb_del}
  1658. apt-get autoremove -y
  1659. echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
  1660. done
  1661. echo -e "内核卸载完毕,继续..."
  1662. else
  1663. echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
  1664. fi
  1665. fi
  1666. }
  1667. #更新引导
  1668. BBR_grub() {
  1669. if [[ "${OS_type}" == "CentOS" ]]; then
  1670. if [[ ${version} == "6" ]]; then
  1671. if [ -f "/boot/grub/grub.conf" ]; then
  1672. sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
  1673. elif [ -f "/boot/grub/grub.cfg" ]; then
  1674. grub-mkconfig -o /boot/grub/grub.cfg
  1675. grub-set-default 0
  1676. elif [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
  1677. grub-mkconfig -o /boot/efi/EFI/centos/grub.cfg
  1678. grub-set-default 0
  1679. elif [ -f "/boot/efi/EFI/redhat/grub.cfg" ]; then
  1680. grub-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  1681. grub-set-default 0
  1682. else
  1683. echo -e "${Error} grub.conf/grub.cfg 找不到,请检查."
  1684. exit
  1685. fi
  1686. elif [[ ${version} == "7" ]]; then
  1687. if [ -f "/boot/grub2/grub.cfg" ]; then
  1688. grub2-mkconfig -o /boot/grub2/grub.cfg
  1689. grub2-set-default 0
  1690. elif [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
  1691. grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
  1692. grub2-set-default 0
  1693. elif [ -f "/boot/efi/EFI/redhat/grub.cfg" ]; then
  1694. grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  1695. grub2-set-default 0
  1696. else
  1697. echo -e "${Error} grub.cfg 找不到,请检查."
  1698. exit
  1699. fi
  1700. elif [[ ${version} == "8" ]]; then
  1701. if [ -f "/boot/grub2/grub.cfg" ]; then
  1702. grub2-mkconfig -o /boot/grub2/grub.cfg
  1703. grub2-set-default 0
  1704. elif [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
  1705. grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
  1706. grub2-set-default 0
  1707. elif [ -f "/boot/efi/EFI/redhat/grub.cfg" ]; then
  1708. grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  1709. grub2-set-default 0
  1710. else
  1711. echo -e "${Error} grub.cfg 找不到,请检查."
  1712. exit
  1713. fi
  1714. grubby --info=ALL | awk -F= '$1=="kernel" {print i++ " : " $2}'
  1715. fi
  1716. elif [[ "${OS_type}" == "Debian" ]]; then
  1717. if _exists "update-grub"; then
  1718. update-grub
  1719. elif [ -f "/usr/sbin/update-grub" ]; then
  1720. /usr/sbin/update-grub
  1721. else
  1722. apt install grub2-common -y
  1723. update-grub
  1724. fi
  1725. #exit 1
  1726. fi
  1727. }
  1728. #简单的检查内核
  1729. check_kernel() {
  1730. if [[ -z "$(find /boot -type f -name 'vmlinuz-*' ! -name 'vmlinuz-*rescue*')" ]]; then
  1731. echo -e "\033[0;31m警告: 未发现内核文件,请勿重启系统,不卸载内核版本选择30安装默认内核救急!\033[0m"
  1732. else
  1733. echo -e "\033[0;32m发现内核文件,看起来可以重启。\033[0m"
  1734. fi
  1735. }
  1736. #############内核管理组件#############
  1737. #############系统检测组件#############
  1738. #检查系统
  1739. check_sys() {
  1740. if [[ -f /etc/redhat-release ]]; then
  1741. release="centos"
  1742. elif grep -qi "debian" /etc/issue; then
  1743. release="debian"
  1744. elif grep -qi "ubuntu" /etc/issue; then
  1745. release="ubuntu"
  1746. elif grep -qi -E "centos|red hat|redhat" /etc/issue || grep -qi -E "centos|red hat|redhat" /proc/version; then
  1747. release="centos"
  1748. fi
  1749. if [[ -f /etc/debian_version ]]; then
  1750. OS_type="Debian"
  1751. echo "检测为Debian通用系统,判断有误请反馈"
  1752. elif [[ -f /etc/redhat-release || -f /etc/centos-release || -f /etc/fedora-release ]]; then
  1753. OS_type="CentOS"
  1754. echo "检测为CentOS通用系统,判断有误请反馈"
  1755. else
  1756. echo "Unknown"
  1757. fi
  1758. #from https://github.com/oooldking
  1759. _exists() {
  1760. local cmd="$1"
  1761. if eval type type >/dev/null 2>&1; then
  1762. eval type "$cmd" >/dev/null 2>&1
  1763. elif command >/dev/null 2>&1; then
  1764. command -v "$cmd" >/dev/null 2>&1
  1765. else
  1766. which "$cmd" >/dev/null 2>&1
  1767. fi
  1768. local rt=$?
  1769. return ${rt}
  1770. }
  1771. get_opsy() {
  1772. if [ -f /etc/os-release ]; then
  1773. awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release
  1774. elif [ -f /etc/lsb-release ]; then
  1775. awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release
  1776. elif [ -f /etc/system-release ]; then
  1777. cat /etc/system-release | awk '{print $1,$2}'
  1778. fi
  1779. }
  1780. get_system_info() {
  1781. opsy=$(get_opsy)
  1782. arch=$(uname -m)
  1783. kern=$(uname -r)
  1784. virt_check
  1785. }
  1786. # from LemonBench
  1787. virt_check() {
  1788. if [ -f "/usr/bin/systemd-detect-virt" ]; then
  1789. Var_VirtType="$(/usr/bin/systemd-detect-virt)"
  1790. # 虚拟机检测
  1791. if [ "${Var_VirtType}" = "qemu" ]; then
  1792. virtual="QEMU"
  1793. elif [ "${Var_VirtType}" = "kvm" ]; then
  1794. virtual="KVM"
  1795. elif [ "${Var_VirtType}" = "zvm" ]; then
  1796. virtual="S390 Z/VM"
  1797. elif [ "${Var_VirtType}" = "vmware" ]; then
  1798. virtual="VMware"
  1799. elif [ "${Var_VirtType}" = "microsoft" ]; then
  1800. virtual="Microsoft Hyper-V"
  1801. elif [ "${Var_VirtType}" = "xen" ]; then
  1802. virtual="Xen Hypervisor"
  1803. elif [ "${Var_VirtType}" = "bochs" ]; then
  1804. virtual="BOCHS"
  1805. elif [ "${Var_VirtType}" = "uml" ]; then
  1806. virtual="User-mode Linux"
  1807. elif [ "${Var_VirtType}" = "parallels" ]; then
  1808. virtual="Parallels"
  1809. elif [ "${Var_VirtType}" = "bhyve" ]; then
  1810. virtual="FreeBSD Hypervisor"
  1811. # 容器虚拟化检测
  1812. elif [ "${Var_VirtType}" = "openvz" ]; then
  1813. virtual="OpenVZ"
  1814. elif [ "${Var_VirtType}" = "lxc" ]; then
  1815. virtual="LXC"
  1816. elif [ "${Var_VirtType}" = "lxc-libvirt" ]; then
  1817. virtual="LXC (libvirt)"
  1818. elif [ "${Var_VirtType}" = "systemd-nspawn" ]; then
  1819. virtual="Systemd nspawn"
  1820. elif [ "${Var_VirtType}" = "docker" ]; then
  1821. virtual="Docker"
  1822. elif [ "${Var_VirtType}" = "rkt" ]; then
  1823. virtual="RKT"
  1824. # 特殊处理
  1825. elif [ -c "/dev/lxss" ]; then # 处理WSL虚拟化
  1826. Var_VirtType="wsl"
  1827. virtual="Windows Subsystem for Linux (WSL)"
  1828. # 未匹配到任何结果, 或者非虚拟机
  1829. elif [ "${Var_VirtType}" = "none" ]; then
  1830. Var_VirtType="dedicated"
  1831. virtual="None"
  1832. local Var_BIOSVendor
  1833. Var_BIOSVendor="$(dmidecode -s bios-vendor)"
  1834. if [ "${Var_BIOSVendor}" = "SeaBIOS" ]; then
  1835. Var_VirtType="Unknown"
  1836. virtual="Unknown with SeaBIOS BIOS"
  1837. else
  1838. Var_VirtType="dedicated"
  1839. virtual="Dedicated with ${Var_BIOSVendor} BIOS"
  1840. fi
  1841. fi
  1842. elif [ ! -f "/usr/sbin/virt-what" ]; then
  1843. Var_VirtType="Unknown"
  1844. virtual="[Error: virt-what not found !]"
  1845. elif [ -f "/.dockerenv" ]; then # 处理Docker虚拟化
  1846. Var_VirtType="docker"
  1847. virtual="Docker"
  1848. elif [ -c "/dev/lxss" ]; then # 处理WSL虚拟化
  1849. Var_VirtType="wsl"
  1850. virtual="Windows Subsystem for Linux (WSL)"
  1851. else # 正常判断流程
  1852. Var_VirtType="$(virt-what | xargs)"
  1853. local Var_VirtTypeCount
  1854. Var_VirtTypeCount="$(echo $Var_VirtTypeCount | wc -l)"
  1855. if [ "${Var_VirtTypeCount}" -gt "1" ]; then # 处理嵌套虚拟化
  1856. virtual="echo ${Var_VirtType}"
  1857. Var_VirtType="$(echo ${Var_VirtType} | head -n1)" # 使用检测到的第一种虚拟化继续做判断
  1858. elif [ "${Var_VirtTypeCount}" -eq "1" ] && [ "${Var_VirtType}" != "" ]; then # 只有一种虚拟化
  1859. virtual="${Var_VirtType}"
  1860. else
  1861. local Var_BIOSVendor
  1862. Var_BIOSVendor="$(dmidecode -s bios-vendor)"
  1863. if [ "${Var_BIOSVendor}" = "SeaBIOS" ]; then
  1864. Var_VirtType="Unknown"
  1865. virtual="Unknown with SeaBIOS BIOS"
  1866. else
  1867. Var_VirtType="dedicated"
  1868. virtual="Dedicated with ${Var_BIOSVendor} BIOS"
  1869. fi
  1870. fi
  1871. fi
  1872. }
  1873. #检查依赖
  1874. if [[ "${OS_type}" == "CentOS" ]]; then
  1875. # 检查是否安装了 ca-certificates 包,如果未安装则安装
  1876. if ! rpm -q ca-certificates >/dev/null; then
  1877. echo '正在安装 ca-certificates 包...'
  1878. yum install ca-certificates -y
  1879. update-ca-trust force-enable
  1880. fi
  1881. echo 'CA证书检查OK'
  1882. # 检查并安装 curl、wget 和 dmidecode 包
  1883. for pkg in curl wget dmidecode redhat-lsb-core; do
  1884. if ! type $pkg >/dev/null 2>&1; then
  1885. echo "未安装 $pkg,正在安装..."
  1886. yum install $pkg -y
  1887. else
  1888. echo "$pkg 已安装。"
  1889. fi
  1890. done
  1891. if [ -x "$(command -v lsb_release)" ]; then
  1892. echo "lsb_release 已安装"
  1893. else
  1894. echo "lsb_release 未安装,现在开始安装..."
  1895. yum install epel-release -y
  1896. yum install redhat-lsb-core -y
  1897. fi
  1898. elif [[ "${OS_type}" == "Debian" ]]; then
  1899. # 检查是否安装了 ca-certificates 包,如果未安装则安装
  1900. if ! dpkg-query -W ca-certificates >/dev/null; then
  1901. echo '正在安装 ca-certificates 包...'
  1902. apt-get update || apt-get --allow-releaseinfo-change update && apt-get install ca-certificates -y
  1903. update-ca-certificates
  1904. fi
  1905. echo 'CA证书检查OK'
  1906. # 检查并安装 curl、wget 和 dmidecode 包
  1907. for pkg in curl wget dmidecode; do
  1908. if ! type $pkg >/dev/null 2>&1; then
  1909. echo "未安装 $pkg,正在安装..."
  1910. apt-get update || apt-get --allow-releaseinfo-change update && apt-get install $pkg -y
  1911. else
  1912. echo "$pkg 已安装。"
  1913. fi
  1914. done
  1915. if [ -x "$(command -v lsb_release)" ]; then
  1916. echo "lsb_release 已安装"
  1917. else
  1918. echo "lsb_release 未安装,现在开始安装..."
  1919. apt-get install lsb-release -y
  1920. fi
  1921. else
  1922. echo "不支持的操作系统发行版:${release}"
  1923. exit 1
  1924. fi
  1925. }
  1926. #检查Linux版本
  1927. check_version() {
  1928. if [[ -s /etc/redhat-release ]]; then
  1929. version=$(grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1)
  1930. else
  1931. version=$(grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1)
  1932. fi
  1933. bit=$(uname -m)
  1934. check_github
  1935. }
  1936. #检查安装bbr的系统要求
  1937. check_sys_bbr() {
  1938. check_version
  1939. if [[ "${OS_type}" == "CentOS" ]]; then
  1940. if [[ ${version} == "7" ]]; then
  1941. installbbr
  1942. else
  1943. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1944. fi
  1945. elif [[ "${OS_type}" == "Debian" ]]; then
  1946. apt-get --fix-broken install -y && apt-get autoremove -y
  1947. installbbr
  1948. else
  1949. echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1950. fi
  1951. }
  1952. check_sys_bbrplus() {
  1953. check_version
  1954. if [[ "${OS_type}" == "CentOS" ]]; then
  1955. if [[ ${version} == "7" ]]; then
  1956. installbbrplus
  1957. else
  1958. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1959. fi
  1960. elif [[ "${OS_type}" == "Debian" ]]; then
  1961. apt-get --fix-broken install -y && apt-get autoremove -y
  1962. installbbrplus
  1963. else
  1964. echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1965. fi
  1966. }
  1967. check_sys_bbrplusnew() {
  1968. check_version
  1969. if [[ "${OS_type}" == "CentOS" ]]; then
  1970. #if [[ ${version} == "7" ]]; then
  1971. if [[ ${version} == "7" || ${version} == "8" ]]; then
  1972. installbbrplusnew
  1973. else
  1974. echo -e "${Error} BBRplusNew内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1975. fi
  1976. elif [[ "${OS_type}" == "Debian" ]]; then
  1977. apt-get --fix-broken install -y && apt-get autoremove -y
  1978. installbbrplusnew
  1979. else
  1980. echo -e "${Error} BBRplusNew内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1981. fi
  1982. }
  1983. check_sys_xanmod() {
  1984. check_version
  1985. if [[ "${OS_type}" == "CentOS" ]]; then
  1986. if [[ ${version} == "7" || ${version} == "8" ]]; then
  1987. installxanmod
  1988. else
  1989. echo -e "${Error} xanmod内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1990. fi
  1991. elif [[ "${OS_type}" == "Debian" ]]; then
  1992. apt-get --fix-broken install -y && apt-get autoremove -y
  1993. installxanmod
  1994. else
  1995. echo -e "${Error} xanmod内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  1996. fi
  1997. }
  1998. check_sys_cloud() {
  1999. check_version
  2000. if [[ "${OS_type}" == "Debian" ]]; then
  2001. apt-get --fix-broken install -y && apt-get autoremove -y
  2002. installcloud
  2003. else
  2004. echo -e "${Error} cloud内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  2005. fi
  2006. }
  2007. #检查安装Lotsever的系统要求
  2008. check_sys_Lotsever() {
  2009. check_version
  2010. bit=$(uname -m)
  2011. if [[ ${bit} != "x86_64" ]]; then
  2012. echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
  2013. fi
  2014. if [[ "${OS_type}" == "CentOS" ]]; then
  2015. if [[ ${version} == "6" ]]; then
  2016. kernel_version="2.6.32-504"
  2017. installlot
  2018. elif [[ ${version} == "7" ]]; then
  2019. yum -y install net-tools
  2020. kernel_version="4.11.2-1"
  2021. installlot
  2022. else
  2023. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  2024. fi
  2025. elif [[ "${release}" == "debian" ]]; then
  2026. if [[ ${version} == "7" || ${version} == "8" ]]; then
  2027. if [[ ${bit} == "x86_64" ]]; then
  2028. kernel_version="3.16.0-4"
  2029. installlot
  2030. elif [[ ${bit} == "i386" ]]; then
  2031. kernel_version="3.2.0-4"
  2032. installlot
  2033. fi
  2034. elif [[ ${version} == "9" ]]; then
  2035. if [[ ${bit} == "x86_64" ]]; then
  2036. kernel_version="4.9.0-4"
  2037. installlot
  2038. fi
  2039. else
  2040. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  2041. fi
  2042. elif [[ "${release}" == "ubuntu" ]]; then
  2043. if [[ ${version} -ge "12" ]]; then
  2044. if [[ ${bit} == "x86_64" ]]; then
  2045. kernel_version="4.4.0-47"
  2046. installlot
  2047. elif [[ ${bit} == "i386" ]]; then
  2048. kernel_version="3.13.0-29"
  2049. installlot
  2050. fi
  2051. else
  2052. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  2053. fi
  2054. else
  2055. echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
  2056. fi
  2057. }
  2058. #检查系统当前状态
  2059. check_status() {
  2060. kernel_version=$(uname -r | awk -F "-" '{print $1}')
  2061. kernel_version_full=$(uname -r)
  2062. net_congestion_control=$(cat /proc/sys/net/ipv4/tcp_congestion_control | awk '{print $1}')
  2063. net_qdisc=$(cat /proc/sys/net/core/default_qdisc | awk '{print $1}')
  2064. if [[ ${kernel_version_full} == *bbrplus* ]]; then
  2065. kernel_status="BBRplus"
  2066. elif [[ ${kernel_version_full} == *4.9.0-4* || ${kernel_version_full} == *4.15.0-30* || ${kernel_version_full} == *4.8.0-36* || ${kernel_version_full} == *3.16.0-77* || ${kernel_version_full} == *3.16.0-4* || ${kernel_version_full} == *3.2.0-4* || ${kernel_version_full} == *4.11.2-1* || ${kernel_version_full} == *2.6.32-504* || ${kernel_version_full} == *4.4.0-47* || ${kernel_version_full} == *3.13.0-29 || ${kernel_version_full} == *4.4.0-47* ]]; then
  2067. kernel_status="Lotserver"
  2068. 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" ]] || [[ $(echo ${kernel_version} | awk -F'.' '{print $1}') == "6" ]]; then
  2069. kernel_status="BBR"
  2070. else
  2071. kernel_status="noinstall"
  2072. fi
  2073. if [[ ${kernel_status} == "BBR" ]]; then
  2074. run_status=$(cat /proc/sys/net/ipv4/tcp_congestion_control | awk '{print $1}')
  2075. if [[ ${run_status} == "bbr" ]]; then
  2076. run_status=$(cat /proc/sys/net/ipv4/tcp_congestion_control | awk '{print $1}')
  2077. if [[ ${run_status} == "bbr" ]]; then
  2078. run_status="BBR启动成功"
  2079. else
  2080. run_status="BBR启动失败"
  2081. fi
  2082. elif [[ ${run_status} == "bbr2" ]]; then
  2083. run_status=$(cat /proc/sys/net/ipv4/tcp_congestion_control | awk '{print $1}')
  2084. if [[ ${run_status} == "bbr2" ]]; then
  2085. run_status="BBR2启动成功"
  2086. else
  2087. run_status="BBR2启动失败"
  2088. fi
  2089. elif [[ ${run_status} == "tsunami" ]]; then
  2090. run_status=$(lsmod | grep "tsunami" | awk '{print $1}')
  2091. if [[ ${run_status} == "tcp_tsunami" ]]; then
  2092. run_status="BBR魔改版启动成功"
  2093. else
  2094. run_status="BBR魔改版启动失败"
  2095. fi
  2096. elif [[ ${run_status} == "nanqinlang" ]]; then
  2097. run_status=$(lsmod | grep "nanqinlang" | awk '{print $1}')
  2098. if [[ ${run_status} == "tcp_nanqinlang" ]]; then
  2099. run_status="暴力BBR魔改版启动成功"
  2100. else
  2101. run_status="暴力BBR魔改版启动失败"
  2102. fi
  2103. else
  2104. run_status="未安装加速模块"
  2105. fi
  2106. elif [[ ${kernel_status} == "Lotserver" ]]; then
  2107. if [[ -e /appex/bin/lotServer.sh ]]; then
  2108. run_status=$(bash /appex/bin/lotServer.sh status | grep "LotServer" | awk '{print $3}')
  2109. if [[ ${run_status} == "running!" ]]; then
  2110. run_status="启动成功"
  2111. else
  2112. run_status="启动失败"
  2113. fi
  2114. else
  2115. run_status="未安装加速模块"
  2116. fi
  2117. elif [[ ${kernel_status} == "BBRplus" ]]; then
  2118. run_status=$(cat /proc/sys/net/ipv4/tcp_congestion_control | awk '{print $1}')
  2119. if [[ ${run_status} == "bbrplus" ]]; then
  2120. run_status=$(cat /proc/sys/net/ipv4/tcp_congestion_control | awk '{print $1}')
  2121. if [[ ${run_status} == "bbrplus" ]]; then
  2122. run_status="BBRplus启动成功"
  2123. else
  2124. run_status="BBRplus启动失败"
  2125. fi
  2126. elif [[ ${run_status} == "bbr" ]]; then
  2127. run_status="BBR启动成功"
  2128. else
  2129. run_status="未安装加速模块"
  2130. fi
  2131. fi
  2132. }
  2133. #############系统检测组件#############
  2134. check_sys
  2135. check_version
  2136. [[ "${OS_type}" == "Debian" ]] && [[ "${OS_type}" == "CentOS" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
  2137. check_github
  2138. start_menu