-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcentos7-debian9-ubuntu.sh
842 lines (793 loc) · 31.3 KB
/
centos7-debian9-ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================
# System Required: CentOS 6+,Debian7+,Ubuntu12+
# Description: BBR+BBR魔改版+Lotserver
# Version: 1.1.9
# Author: 千影
# Blog: https://www.94ish.me/
#=================================================
sh_ver="1.1.9"
github="raw.githubusercontent.com/zxlhhyccc/-BBR-/master"
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
Error="${Red_font_prefix}[错误]${Font_color_suffix}"
Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
#安装BBRPLUS内核
installbbrplus(){
kernel_version="4.14.90"
if [[ "${release}" == "centos" ]]; then
yum install -y http://${github}/bbrpluskernel/${release}/kernel-${kernel_version}.rpm
yum remove -y kernel-headers
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
mkdir bbrplus && cd bbrplus
wget -N --no-check-certificate http://${github}/bbrpluskernel/debian_ubuntu/linux-headers-${kernel_version}.deb
wget -N --no-check-certificate http://${github}/bbrpluskernel/debian_ubuntu/linux-image-${kernel_version}.deb
dpkg -i linux-headers-${kernel_version}.deb
dpkg -i linux-image-${kernel_version}.deb
cd .. && rm -rf bbrplus
fi
detele_kernel
BBR_grub
echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBRPLUS魔改版${Font_color_suffix}"
stty erase '^H' && read -p "需要重启VPS后,才能开启BBR/BBR魔改版,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
#安装BBR内核
installbbr(){
if [[ "${release}" == "centos" ]]; then
kernel_version="4.20.0"
rpm --import http://${github}/RPM-GPG-KEY-elrepo.org
yum install -y http://${github}/kernel/${release}/kernel-ml-${kernel_version}.rpm
yum remove -y kernel-headers
yum install -y http://${github}/kernel/${release}/kernel-ml-headers-${kernel_version}.rpm
yum install -y http://${github}/kernel/${release}/kernel-ml-devel-${kernel_version}.rpm
yum install -y http://${github}/kernel/${release}/kernel-ml-tools-libs-${kernel_version}.rpm
yum install -y http://${github}/kernel/${release}/kernel-ml-tools-${kernel_version}.rpm
elif [[ "${release}" == "debian" ]]; then
kernel_version="4.9.147"
mkdir bbr && cd bbr
wget -N --no-check-certificate -O libssl1.1_amd64.deb http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.0j-1~deb9u1_amd64.deb
wget -N --no-check-certificate -O linux-headers_all.deb http://${github}/kernel/${release}/linux-headers-${kernel_version}_all.deb
wget -N --no-check-certificate -O linux-headers_amd64.deb http://${github}/kernel/${release}/linux-headers-${kernel_version}-generic_amd64.deb
wget -N --no-check-certificate -O linux-image-generic_amd64.deb http://${github}/kernel/${release}/linux-image-${kernel_version}-generic_amd64.deb
dpkg -i libssl1.1_amd64.deb
dpkg -i linux-headers_all.deb
dpkg -i linux-headers_amd64.deb
dpkg -i linux-image-generic_amd64.deb
cd .. && rm -rf bbr
elif [[ "${release}" == "ubuntu" ]]; then
kernel_version="4.19.13"
mkdir bbr && cd bbr
wget -N --no-check-certificate -O libssl1.1_amd64.deb http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.1_1.1.0j-1~deb9u1_amd64.deb
wget -N --no-check-certificate -O linux-headers_all.deb http://${github}/kernel/${release}/linux-headers-${kernel_version}_all.deb
wget -N --no-check-certificate -O linux-headers_amd64.deb http://${github}/kernel/${release}/linux-headers-${kernel_version}-generic_amd64.deb
wget -N --no-check-certificate -O linux-modules-generic_amd64.deb http://${github}/kernel/${release}/linux-modules-${kernel_version}-generic_amd64.deb
wget -N --no-check-certificate -O linux-image-generic_amd64.deb http://${github}/kernel/${release}/linux-image-unsigned-${kernel_version}-generic_amd64.deb
dpkg -i libssl1.1_amd64.deb
dpkg -i linux-headers_all.deb
dpkg -i linux-headers_amd64.deb
dpkg -i linux-modules-generic_amd64.deb
dpkg -i linux-image-generic_amd64.deb
cd .. && rm -rf bbr
fi
detele_kernel
BBR_grub
echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}BBR/BBR魔改版${Font_color_suffix}"
stty erase '^H' && read -p "需要重启VPS后,才能开启BBR/BBR魔改版,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
# 一键启用root帐号命令
Modify_root(){
if [[ "${release}" == "centos" || "${release}" == "debian" ]]; then
# 修改root 密码
echo "请输入 passwd 命令修改root用户的密码"
passwd root
# 启用root密码登陆
sed -i "s/PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
sed -i "s/PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
# 重启ssh服务
systemctl restart sshd
elif [[ "${release}" == "ubuntu" ]]; then
# 修改root 密码
echo "请输入 passwd 命令修改root用户的密码"
passwd root
# 启用root密码登陆
sed -i "s/#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
sed -i "s/PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
# 重启ssh服务
systemctl restart sshd
fi
}
#安装nginx
install_nginx(){
if [[ "${release}" == "centos" ]]; then
setsebool -P httpd_can_network_connect 1
touch /etc/yum.repos.d/nginx.repo
cat <<EOF > /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/\$basearch/
gpgcheck=0
enabled=1
EOF
yum -y install nginx
elif [[ "${release}" == "debian" ]]; then
echo "deb http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
wget http://nginx.org/keys/nginx_signing.key >/dev/null 2>&1
apt-key add nginx_signing.key >/dev/null 2>&1
apt-get update
apt-get -y install nginx
rm -rf add nginx_signing.key >/dev/null 2>&1
elif [[ "${release}" == "ubuntu" ]]; then
echo "deb http://nginx.org/packages/mainline/ubuntu/ bionic nginx" >> /etc/apt/sources.list
echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ bionic nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list
wget -N --no-check-certificate https://nginx.org/keys/nginx_signing.key >/dev/null 2>&1
apt-key add nginx_signing.key >/dev/null 2>&1
apt-get update
apt-get -y install nginx
rm -rf add nginx_signing.key >/dev/null 2>&1
fi
}
#安装Lotserver内核
installlot(){
if [[ "${release}" == "centos" ]]; then
rpm --import http://${github}/lotserver/${release}/RPM-GPG-KEY-elrepo.org
yum remove -y kernel-firmware
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-firmware-${kernel_version}.rpm
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-${kernel_version}.rpm
yum remove -y kernel-headers
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-headers-${kernel_version}.rpm
yum install -y http://${github}/lotserver/${release}/${version}/${bit}/kernel-devel-${kernel_version}.rpm
elif [[ "${release}" == "ubuntu" ]]; then
mkdir bbr && cd bbr
wget -N --no-check-certificate http://${github}/lotserver/${release}/${bit}/linux-headers-${kernel_version}-all.deb
wget -N --no-check-certificate http://${github}/lotserver/${release}/${bit}/linux-headers-${kernel_version}.deb
wget -N --no-check-certificate http://${github}/lotserver/${release}/${bit}/linux-image-${kernel_version}.deb
dpkg -i linux-headers-${kernel_version}-all.deb
dpkg -i linux-headers-${kernel_version}.deb
dpkg -i linux-image-${kernel_version}.deb
cd .. && rm -rf bbr
elif [[ "${release}" == "debian" ]]; then
mkdir bbr && cd bbr
wget -N --no-check-certificate http://${github}/lotserver/${release}/${bit}/linux-image-${kernel_version}.deb
dpkg -i linux-image-${kernel_version}.deb
cd .. && rm -rf bbr
fi
detele_kernel
BBR_grub
echo -e "${Tip} 重启VPS后,请重新运行脚本开启${Red_font_prefix}Lotserver${Font_color_suffix}"
stty erase '^H' && read -p "需要重启VPS后,才能开启Lotserver,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
#启用BBR
startbbr(){
remove_all
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p
echo -e "${Info}BBR启动成功!"
}
#编译并启用BBR魔改(cent0s7/debian9)
startbbrmod(){
remove_all
if [[ "${release}" == "centos" ]]; then
yum install -y make gcc wget elfutils-libelf-devel
mkdir bbrmod && cd bbrmod
wget -N --no-check-certificate https://raw.githubusercontent.com/zxlhhyccc/TCP_BBR/master/v4.19/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
chmod +x ./tcp_tsunami.ko
cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
insmod tcp_tsunami.ko
depmod -a
else
apt-get update
if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
apt-get -y install build-essential
apt-get -y install software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test -y
apt-get update
fi
apt-get -y install make gcc libelf-dev
mkdir bbrmod && cd bbrmod
wget -N --no-check-certificate https://raw.githubusercontent.com/zxlhhyccc/CBBR/master/debian9-bbr/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
install tcp_tsunami.ko /lib/modules/$(uname -r)/kernel
cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a
fi
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=tsunami" >> /etc/sysctl.conf
sysctl -p
cd .. && rm -rf bbrmod
echo -e "${Info}魔改版BBR启动成功!"
}
#编译并启用BBRPULS
startbbrplusmod(){
remove_all
echo -e "启用模块..."
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbrplus" >> /etc/sysctl.conf
sysctl -p
echo -e "${Info}BBRPLUS启动成功!"
}
#编译并启用BBR魔改(ubuntu18.04)
startbbrmod_ubuntu18.04(){
remove_all
if [[ "${release}" == "ubuntu" ]]; then
apt-get update
if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
apt-get -y install build-essential
apt-get -y install software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test -y
apt-get update
fi
apt-get -y install make gcc libelf-dev
mkdir bbrmod && cd bbrmod
wget -N --no-check-certificate https://raw.githubusercontent.com/zxlhhyccc/TCP_BBR/master/v4.19/tcp_tsunami.c
echo "obj-m:=tcp_tsunami.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
install tcp_tsunami.ko /lib/modules/$(uname -r)/kernel
cp -rf ./tcp_tsunami.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a
fi
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=tsunami" >> /etc/sysctl.conf
sysctl -p
cd .. && rm -rf bbrmod
echo -e "${Info}魔改版BBR启动成功!"
}
#编译并启用BBR暴力魔改(cent0s7/debian9)
startbbrmod_nanqinlang(){
remove_all
if [[ "${release}" == "centos" ]]; then
yum install -y make gcc wget elfutils-libelf-devel
mkdir bbrmod && cd bbrmod
wget -N --no-check-certificate https://raw.githubusercontent.com/zxlhhyccc/TCP_BBR/master/v4.19/tcp_nanqinlang.c
echo "obj-m := tcp_nanqinlang.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
chmod +x ./tcp_nanqinlang.ko
cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
insmod tcp_nanqinlang.ko
depmod -a
else
apt-get update
if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
apt-get -y install build-essential
apt-get -y install software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test -y
apt-get update
fi
apt-get -y install make gcc libelf-dev
mkdir bbrmod && cd bbrmod
wget -N --no-check-certificate https://raw.githubusercontent.com/zxlhhyccc/CBBR/master/debian9-bbr/tcp_nanqinlang.c
echo "obj-m := tcp_nanqinlang.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
install tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel
cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a
fi
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=nanqinlang" >> /etc/sysctl.conf
sysctl -p
cd .. && rm -rf bbrmod
echo -e "${Info}魔改版BBR启动成功!"
}
#编译并启用BBR暴力魔改(ubuntu18.04)
startbbrmod_nanqinlang_ubuntu18.04(){
remove_all
if [[ "${release}" == "ubuntu" ]]; then
apt-get update
if [[ "${release}" == "ubuntu" && "${version}" = "14" ]]; then
apt-get -y install build-essential
apt-get -y install software-properties-common
add-apt-repository ppa:ubuntu-toolchain-r/test -y
apt-get update
fi
apt-get -y install make gcc libelf-dev
mkdir bbrmod && cd bbrmod
wget -N --no-check-certificate https://raw.githubusercontent.com/zxlhhyccc/TCP_BBR/master/v4.19/tcp_nanqinlang.c
echo "obj-m := tcp_nanqinlang.o" > Makefile
make -C /lib/modules/$(uname -r)/build M=`pwd` modules CC=/usr/bin/gcc
install tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel
cp -rf ./tcp_nanqinlang.ko /lib/modules/$(uname -r)/kernel/net/ipv4
depmod -a
fi
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=nanqinlang" >> /etc/sysctl.conf
sysctl -p
cd .. && rm -rf bbrmod
echo -e "${Info}魔改版BBR启动成功!"
}
#启用Lotserver
startlotserver(){
remove_all
if [[ "${release}" == "centos" ]]; then
yum install -y unzip
else
apt-get update
apt-get install -y unzip
fi
wget --no-check-certificate -O appex.sh https://raw.githubusercontent.com/zxlhhyccc/-BBR-/master/appex.sh && chmod +x appex.sh && bash appex.sh install
rm -f appex.sh
start_menu
}
#卸载全部加速
remove_all(){
rm -rf bbrmod
sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
sed -i '/fs.file-max/d' /etc/sysctl.conf
sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
sed -i '/net.core.rmem_default/d' /etc/sysctl.conf
sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_tw_recycle/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_keepalive_time/d' /etc/sysctl.conf
sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_rmem/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_wmem/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_mtu_probing/d' /etc/sysctl.conf
sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_fastopen/d' /etc/sysctl.conf
sed -i '/vm.swappiness/d' /etc/sysctl.conf
if [[ -e /appex/bin/serverSpeeder.sh ]]; then
wget --no-check-certificate -O appex.sh https://raw.githubusercontent.com/zxlhhyccc/-BBR-/master/appex.sh && chmod +x appex.sh && bash appex.sh uninstall
rm -f appex.sh
fi
clear
echo -e "${Info}:清除加速完成。"
sleep 1s
}
#优化系统配置
optimizing_system(){
sed -i '/fs.file-max/d' /etc/sysctl.conf
sed -i '/fs.inotify.max_user_instances/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_syncookies/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_fin_timeout/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_tw_reuse/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_syn_backlog/d' /etc/sysctl.conf
sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_tw_buckets/d' /etc/sysctl.conf
sed -i '/net.ipv4.route.gc_timeout/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_synack_retries/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_syn_retries/d' /etc/sysctl.conf
sed -i '/net.core.somaxconn/d' /etc/sysctl.conf
sed -i '/net.core.netdev_max_backlog/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_timestamps/d' /etc/sysctl.conf
sed -i '/net.ipv4.tcp_max_orphans/d' /etc/sysctl.conf
sed -i '/net.ipv4.ip_forward/d' /etc/sysctl.conf
echo "fs.file-max = 1000000
fs.inotify.max_user_instances = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 32768
net.core.netdev_max_backlog = 32768
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_max_orphans = 32768
# forward ipv4
net.ipv4.ip_forward = 1">>/etc/sysctl.conf
sysctl -p
echo "* soft nofile 1000000
* hard nofile 1000000">/etc/security/limits.conf
echo "ulimit -SHn 1000000">>/etc/profile
read -p "需要重启VPS后,才能生效系统优化配置,是否现在重启 ? [Y/n] :" yn
[ -z "${yn}" ] && yn="y"
if [[ $yn == [Yy] ]]; then
echo -e "${Info} VPS 重启中..."
reboot
fi
}
#更新脚本
Update_Shell(){
echo -e "当前版本为 [ ${sh_ver} ],开始检测最新版本..."
sh_new_ver=$(wget --no-check-certificate -qO- "http://${github}/tcp.sh"|grep 'sh_ver="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
[[ -z ${sh_new_ver} ]] && echo -e "${Error} 检测最新版本失败 !" && start_menu
if [[ ${sh_new_ver} != ${sh_ver} ]]; then
echo -e "发现新版本[ ${sh_new_ver} ],是否更新?[Y/n]"
read -p "(默认: y):" yn
[[ -z "${yn}" ]] && yn="y"
if [[ ${yn} == [Yy] ]]; then
wget -N --no-check-certificate http://${github}/tcp.sh && chmod +x tcp.sh
echo -e "脚本已更新为最新版本[ ${sh_new_ver} ] !"
else
echo && echo " 已取消..." && echo
fi
else
echo -e "当前已是最新版本[ ${sh_new_ver} ] !"
sleep 5s
fi
}
#开始菜单
start_menu(){
clear
echo && echo -e " TCP加速 一键安装管理脚本 ${Red_font_prefix}[v${sh_ver}]${Font_color_suffix}
-- 就是爱生活 | 94ish.me --
${Green_font_prefix}0.${Font_color_suffix} 升级脚本(请不要升级脚本,否则需重新配置)
————————————内核管理————————————
${Green_font_prefix}1.${Font_color_suffix} 安装 BBR/BBR魔改版内核
${Green_font_prefix}2.${Font_color_suffix} 安装 BBR/BBRPULS内核(centOS7/debian9/ubuntu14.04/16.04使用)
${Green_font_prefix}3.${Font_color_suffix} 安装 Lotserver(锐速)内核(仅支持低版本内核)
————————————加速管理————————————
${Green_font_prefix}4.${Font_color_suffix} 使用BBR加速
${Green_font_prefix}5.${Font_color_suffix} 使用BBRPLUS加速
${Green_font_prefix}6.${Font_color_suffix} 使用BBR魔改版加速(centos7/debian9使用)
${Green_font_prefix}7.${Font_color_suffix} 使用暴力BBR魔改版加速(不支持部分系统,centos7/debian9使用)
${Green_font_prefix}8.${Font_color_suffix} 使用Lotserver(锐速)加速(仅支持低版本内核)
${Green_font_prefix}9.${Font_color_suffix} 使用BBR魔改版加速(ubuntu16.04/18.04/18.10使用)
${Green_font_prefix}10.${Font_color_suffix} 使用暴力BBR魔改版加速(不支持部分系统,ubuntu16.04/18.04/18.10使用)
————————————杂项管理————————————
${Green_font_prefix}11.${Font_color_suffix} 卸载全部加速
${Green_font_prefix}12.${Font_color_suffix} 系统配置优化
${Green_font_prefix}13.${Font_color_suffix} 设置root用户登录
${Green_font_prefix}14.${Font_color_suffix} 安装nginx(安装nginx1.14及以上支持TLSv1.3)
${Green_font_prefix}15.${Font_color_suffix} 退出脚本
————————————————————————————————" && echo
check_status
if [[ ${kernel_status} == "noinstall" ]]; then
echo -e " 当前状态: ${Green_font_prefix}未安装${Font_color_suffix} 加速内核 ${Red_font_prefix}请先安装内核${Font_color_suffix}"
else
echo -e " 当前状态: ${Green_font_prefix}已安装${Font_color_suffix} ${_font_prefix}${kernel_status}${Font_color_suffix} 加速内核 , ${Green_font_prefix}${run_status}${Font_color_suffix}"
fi
echo
read -p " 请输入数字 [0-15]:" num
case "$num" in
0)
Update_Shell
;;
1)
check_sys_bbr
;;
2)
check_sys_bbrplus
;;
3)
check_sys_Lotsever
;;
4)
startbbr
;;
5)
startbbrplusmod
;;
6)
startbbrmod
;;
7)
startbbrmod_nanqinlang
;;
8)
startlotserver
;;
9)
startbbrmod_ubuntu18.04
;;
10)
startbbrmod_nanqinlang_ubuntu18.04
;;
11)
remove_all
;;
12)
optimizing_system
;;
13)
Modify_root
;;
14)
install_nginx
;;
15)
exit 1
;;
*)
clear
echo -e "${Error}:请输入正确数字 [0-15]"
sleep 5s
start_menu
;;
esac
}
#############内核管理组件#############
#删除多余内核
detele_kernel(){
if [[ "${release}" == "centos" ]]; then
rpm_total=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l`
if [ "${rpm_total}" > "1" ]; then
echo -e "检测到 ${rpm_total} 个其余内核,开始卸载..."
for((integer = 1; integer <= ${rpm_total}; integer++)); do
rpm_del=`rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer}`
echo -e "开始卸载 ${rpm_del} 内核..."
yum remove -y ${rpm_del}
echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
done
echo -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
deb_total=`dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
if [ "${deb_total}" > "1" ]; then
echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
for((integer = 1; integer <= ${deb_total}; integer++)); do
deb_del=`dpkg -l|grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
echo -e "开始卸载 ${deb_del} 内核..."
apt-get purge -y ${deb_del}
echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
done
echo -e "内核卸载完毕,继续..."
fi
deb_total=`dpkg -l | grep linux-headers | awk '{print $2}' | grep -v "${kernel_version}" | wc -l`
if [ "${deb_total}" > "1" ]; then
echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
for((integer = 1; integer <= ${deb_total}; integer++)); do
deb_del=`dpkg -l|grep linux-headers | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer}`
apt-get purge -y ${deb_del}
echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
done
echo -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
fi
}
#更新引导
BBR_grub(){
if [[ "${release}" == "centos" ]]; then
if [[ ${version} = "6" ]]; then
if [ ! -f "/boot/grub/grub.conf" ]; then
echo -e "${Error} /boot/grub/grub.conf 找不到,请检查."
exit 1
fi
sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
elif [[ ${version} = "7" ]]; then
if [ ! -f "/boot/grub2/grub.cfg" ]; then
echo -e "${Error} /boot/grub2/grub.cfg 找不到,请检查."
exit 1
fi
grub2-set-default 0
fi
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
/usr/sbin/update-grub
#apt remove -y grub-pc-bin
fi
}
#############内核管理组件#############
#############系统检测组件#############
#检查系统
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
}
#检查Linux版本
check_version(){
if [[ -s /etc/redhat-release ]]; then
version=`grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1`
else
version=`grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1`
fi
bit=`uname -m`
if [[ ${bit} = "x86_64" ]]; then
bit="x64"
else
bit="x32"
fi
}
#检查安装bbr的系统要求
check_sys_bbrplus(){
check_version
if [[ "${release}" == "centos" ]]; then
if [[ ${version} -ge "6" ]]; then
installbbrplus
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "debian" ]]; then
if [[ ${version} -ge "8" ]]; then
installbbrplus
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "ubuntu" ]]; then
if [[ ${version} -ge "14" ]]; then
installbbrplus
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
else
echo -e "${Error} BBRplus内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
}
#检查安装bbr的系统要求
check_sys_bbr(){
check_version
if [[ "${release}" == "centos" ]]; then
if [[ ${version} -ge "6" ]]; then
installbbr
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "debian" ]]; then
if [[ ${version} -ge "8" ]]; then
installbbr
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "ubuntu" ]]; then
if [[ ${version} -ge "14" ]]; then
installbbr
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
else
echo -e "${Error} BBR内核不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
}
#检查安装Lotsever的系统要求
check_sys_Lotsever(){
check_version
if [[ "${release}" == "centos" ]]; then
if [[ ${version} == "6" ]]; then
kernel_version="2.6.32-504"
installlot
elif [[ ${version} == "7" ]]; then
yum -y install net-tools
kernel_version="3.10.0-327"
installlot
else
echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "debian" ]]; then
if [[ ${version} -ge "7" ]]; then
if [[ ${bit} == "x64" ]]; then
kernel_version="3.16.0-4"
installlot
elif [[ ${bit} == "x32" ]]; then
kernel_version="3.2.0-4"
installlot
fi
else
echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
elif [[ "${release}" == "ubuntu" ]]; then
if [[ ${version} -ge "12" ]]; then
if [[ ${bit} == "x64" ]]; then
kernel_version="4.4.0-47"
installlot
elif [[ ${bit} == "x32" ]]; then
kernel_version="3.13.0-29"
installlot
fi
else
echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
else
echo -e "${Error} Lotsever不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
}
check_status(){
kernel_version=`uname -r | awk -F "-" '{print $1}'`
if [[ ${kernel_version} = "4.14.90" ]]; then
kernel_status="BBRplus"
elif [[ ${kernel_version} = "3.10.0" || ${kernel_version} = "3.16.0" || ${kernel_version} = "3.2.0" || ${kernel_version} = "4.4.0" || ${kernel_version} = "3.13.0" || ${kernel_version} = "2.6.32" ]]; then
kernel_status="Lotserver"
elif [[ `echo ${kernel_version} | awk -F'.' '{print $1}'` == "4" ]] && [[ `echo ${kernel_version} | awk -F'.' '{print $2}'` -ge 9 ]]; then
kernel_status="BBR"
else
kernel_status="noinstall"
fi
if [[ ${kernel_status} == "Lotserver" ]]; then
if [[ -e /appex/bin/serverSpeeder.sh ]]; then
run_status=`bash /appex/bin/serverSpeeder.sh status | grep "ServerSpeeder" | awk '{print $3}'`
if [[ ${run_status} = "running!" ]]; then
run_status="启动成功"
else
run_status="启动失败"
fi
else
run_status="未安装加速模块"
fi
elif [[ ${kernel_status} == "BBR" ]]; then
run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
if [[ ${run_status} == "bbr" ]]; then
run_status=`lsmod | grep "bbr" | awk '{print $1}'`
if [[ ${run_status} == "tcp_bbr" ]]; then
run_status="BBR启动成功"
else
run_status="BBR启动失败"
fi
elif [[ ${run_status} == "tsunami" ]]; then
run_status=`lsmod | grep "tsunami" | awk '{print $1}'`
if [[ ${run_status} == "tcp_tsunami" ]]; then
run_status="BBR魔改版启动成功"
else
run_status="BBR魔改版启动失败"
fi
elif [[ ${run_status} == "nanqinlang" ]]; then
run_status=`lsmod | grep "nanqinlang" | awk '{print $1}'`
if [[ ${run_status} == "tcp_nanqinlang" ]]; then
run_status="暴力BBR魔改版启动成功"
else
run_status="暴力BBR魔改版启动失败"
fi
else
run_status="未安装加速模块"
fi
elif [[ ${kernel_status} == "BBRplus" ]]; then
run_status=`grep "net.ipv4.tcp_congestion_control" /etc/sysctl.conf | awk -F "=" '{print $2}'`
if [[ ${run_status} == "bbrplus" ]]; then
run_status=`lsmod | grep "bbrplus" | awk '{print $1}'`
if [[ ${run_status} == "tcp_bbrplus" ]]; then
run_status="BBRplus启动成功"
else
run_status="BBRplus启动失败"
fi
else
run_status="未安装加速模块"
fi
fi
}
#############系统检测组件#############
check_sys
check_version
[[ ${release} != "debian" ]] && [[ ${release} != "ubuntu" ]] && [[ ${release} != "centos" ]] && echo -e "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
start_menu