Centos7網速過慢,如何提速?


Centos7使用瀏覽器打開網頁速度實在是太慢了,打開博客園首頁,需要6~7妙才能顯示完大部分內容,實在受不了.畢竟普通人打開打開一個網頁的耐心時間為3妙以內.在網上看到了BBR加速,是了一下,效果很明顯,配置之后,網頁打開速度明顯改善了,加速到可接受范圍內,不至於打開網頁后還要呆呆地看着一片空白頁面發呆.

BBR 是 Google 提出的一種新型擁塞控制算法,可以使 Linux 服務器顯著地提高吞吐量和減少 TCP 連接的延遲。

開啟 BBR 要求 4.10 以上版本 Linux 內核

 

升級內核:

uname -r  #如果低於4.10,則進行以下步驟

sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org    #添加更新源

sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm  #安裝源

sudo yum --enablerepo=elrepo-kernel install kernel-ml -y    #啟用內核yum源的同時安裝內核

rpm -qa | grep kernel      #看一下是內核版本是否比之前的內核版本更新,內核版本更新,符合大於4.10,則說明內核升級成功

配置系統默認啟動內核版本

(1)普通方法(但是這個不適用於我的系統,我沒有grub2.cfg文件)

sudo egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'  #看一下類似kernel-ml-4.11.0-1.el7.elrepo.x86_64之類的內容在哪行,第一行為0,第二行為1,以此類推

sudo grub2-set-default 1  #1為上面內容所在的行數

(2)我的方法

修改/etc/grub2-efi.cfg文件,將3.10內核部分注釋,部分內容截圖

###menuentry 'CentOS Linux (3.10.0-1062.18.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1062.el7.x86_64-advanced-07f41014-2c86-4b18-96f7-5a9e50a0f13e' {
###    load_video
###    set gfxpayload=keep
###    insmod gzio
###    insmod part_gpt
###    insmod xfs
###    set root='hd1,gpt2'
###    if [ x$feature_platform_search_hint = xy ]; then
###      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt2 --hint-efi=hd1,gpt2 --hint-baremetal=ahci1,gpt2  463082c5-cd34-4a98-8683-69f3258937d0
###    else
###      search --no-floppy --fs-uuid --set=root 463082c5-cd34-4a98-8683-69f3258937d0
###    fi
###    linuxefi /vmlinuz-3.10.0-1062.18.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=zh_CN.utf8
###    initrdefi /initramfs-3.10.0-1062.18.1.el7.x86_64.img
###}
menuentry 'CentOS Linux (5.4.12-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1062.el7.x86_64-advanced-07f41014-2c86-4b18-96f7-5a9e50a0f13e' {
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_gpt
    insmod xfs
    set root='hd1,gpt2'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt2 --hint-efi=hd1,gpt2 --hint-baremetal=ahci1,gpt2  463082c5-cd34-4a98-8683-69f3258937d0
    else
      search --no-floppy --fs-uuid --set=root 463082c5-cd34-4a98-8683-69f3258937d0
    fi
    linuxefi /vmlinuz-5.4.12-1.el7.elrepo.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
    initrdefi /initramfs-5.4.12-1.el7.elrepo.x86_64.img
}

reboot      #重啟服務器,使用新內核

uname -r   #顯示4.10以上的版本正常

 

配置BBR

終端執行以下命令

echo 'net.core.default_qdisc=fq' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
sudo sysctl net.ipv4.tcp_available_congestion_control
sudo sysctl -n net.ipv4.tcp_congestion_controllsmod | grep bbr  #返回內容則說明正常

測試以下ping值.如果沒有明顯變快,建議重啟電腦

我的ping值從沒有做該配置前的五六百毫秒延遲,到正常的三四十毫秒延遲,效果可想而知

 

參考鏈接: https://laod.cn/black-technology/centos7-google-bbr-vps.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM