Press "Enter" to skip to content

CentOS 7 开启BBR加速

Google BBR 是一款免费开源的TCP拥塞控制传输控制协议, 可以使 Linux 服务器显著提高吞吐量和减少 TCP 连接的延迟。 项目地址:https://github.com/google/bbr

CentOS开启BBR

Step1:安装BBR

执行以下脚本,会提示你选择操作步骤,第一次选择步骤1,更新系统,会自动重启。

重启完成后再次执行脚本,选择步骤2,会进行包含bbr内核安装

  • 这一步会进行两次的用户手工输入,第一次输入是选择最新内核所代表的最前面的数字,以便程序确认最新内核位置;
  • 第二步输入确认是否内核已经切换为第一步所输的数字,如果saved_entry=X中的X为第一步所输入的数字,即可输入y进行切换内核重启。

#!/bin/bash
#
# Title: CentOS7.6_x64_upgrade_kernel_script
# Author: ZNing
# Date: 2019-7-3 23:13:09
# Pass on the Tencent Cloud CentOS7.6 x64
# You should run this script three times. The first is yum update, the second is kernel upgrade to 5, the final one is optional when you decided to maunal which is deleting old kernel.
# Having fun to using it. (*^▽^*) Best wishes from Misaka Mikoto and Misaka 10086. 

clear;

function upgradeYum()
{
    yum clean all;
    yum update -y;
    reboot;
}

function upgradeKernel()
{
    rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org;
    rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm;
    yum --disablerepo="*" --enablerepo="elrepo-kernel" list available;
    yum --enablerepo=elrepo-kernel install -y kernel-ml;
    grub2-mkconfig -o /boot/grub2/grub.cfg;
    grub2-editenv list;
    awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg;
    echo -n  "please enter the latest kernel number ->";
    read  num;
    grub2-set-default $num;
    grub2-editenv list;
}

function confirmKernel()
{
    echo -n  "are the kernel changed? If it is, plz input(y),else(n) ->";
    read confirmInput;
    if [ "$confirmInput" == 'y' ]; then
		reboot;
	elif [ "$selected" == 'n' ]; then
		exit;
	else
		confirmKernel;
		return;
	fi;
}

function removeOldKernel()
{
    IFS=$'\n';
    for LINE in `rpm -qa | grep kernel- | grep 3.`; do
        #Do some works on "${LINE}"
        yum -y remove ${LINE};
    done;
    reboot;
}

function checkSystem()
{
    cat /etc/redhat-release;
    uname -sr;
    uname -a;
    echo "[Notice] Confirm Upgrade Kernel? please select: (1~4)"
    select selected in 'Upgrade Step 1' 'Upgrade Step 2' 'Delete Old Kernel' 'Exit'; do break; done;
	[ "$selected" == 'Exit' ] && echo 'Exit Upgrade.' && exit;
	if [ "$selected" == 'Upgrade Step 1' ]; then
		upgradeYum;
	elif [ "$selected" == 'Upgrade Step 2' ]; then
		upgradeKernel;
        confirmKernel;
	elif [ "$selected" == 'Delete Old Kernel' ]; then
		removeOldKernel;
	else
		ConfirmInstall;
		return;
	fi;
	echo "[OK] You Selected: ${selected}";
}

checkSystem;

Step2: 设置BBR

1、编辑配置文件

vi /etc/sysctl.conf

2、添加如下内容

net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

3、加载系统参数(正常情况下会输出我们之前加入的内容)

sysctl -p

Step3:验证bbr是否已经开启

1、输入

sysctl net.ipv4.tcp_available_congestion_control

如果返回

net.ipv4.tcp_available_congestion_control = reno cubic bbr

则安装 成功


2、输入

lsmod | grep bbr

如果返回

tcp_bbr                20480  2

则安装 成功

本文转载自:https://blog.51cto.com/bella41981/2501890

参考资料:https://cloud.tencent.com/developer/article/1623563?utm_source=cyhour.com

发表评论

电子邮件地址不会被公开。 必填项已用*标注