使用 Linux Shell 脚本在 CentOS Linux 6 / 7 上安装 BBR(来自 Google 的 TCP 拥塞控制算法)

本文最后一次更新于:2018 年 10 月 11 日 14:12:28

BBR 介绍:

相对于传统的 TCP 拥塞控制算法,BBR 在充分利用网络带宽的同时,还能够大幅减少不必要的丢包。具体请参见该篇文章《 BBR 拥塞控制算法解析(来自 Google 的 TCP 拥塞控制算法)》。

之前写过一篇文章《 CentOS Linux 6 / 7 安装 BBR(来自 Google 的 TCP 拥塞控制算法)》,但为了方便批量安装于是写了一个自动化安装 BBR 的 Linux Shell 脚本,同时考虑到了一些细节问题(如在 CentOS Linux 6.x 上安装 BBR 前更新 nss ),在这里跟大家做一个分享。

安装:

目前 Linux Kernel 4.9 及其以上版本已经集成了 BBR ,所以只需要升级 Kernel 即可。

安装过程还是非常简单的,支持 CentOS Linux 6.x 和 7.x 。如果您的服务器已经接入互联网,那么执行以下脚本并没有什么问题;如果您的服务器位于内网,请看 “ 讲解 ” 部分并根据实际需要进行相应地修改。

Ricky 个人是喜欢把一些临时文件放到 /tmp 目录下,所以进入 /tmp 目录,使用 wget 命令把安装脚本下载到这里,并执行脚本即可:

[root@host ~]# cd /tmp
[root@host ~]# yum -y install wget zip unzip
[root@host ~]# wget --no-check-certificate https://ccie.lol/wp-content/uploads/2018/09/install_bbr.zip
[root@host ~]# unzip install_bbr.zip -d . && rm -f install_bbr.zip && sh install_bbr.sh

讲解:

以下是该 Linux Shell 脚本的代码:

#!/bin/bash

# 0.check the system and bbr

# 检查 OS 的版本号
OS_VERSION="0"
if grep -Eqi "release 4\." /etc/redhat-release ; then
	#OS_VERSION="4"
	echo Sorry , BBR does not support CentOS Liunx 4.x
	exit
elif grep -Eqi "release 5\." /etc/redhat-release ; then
        #OS_VERSION="5"
	echo Sorry , BBR does not support CentOS Liunx 5.x
	exit
elif grep -Eqi "release 6\." /etc/redhat-release ; then
        OS_VERSION="6"
elif grep -Eqi "release 7\." /etc/redhat-release ; then
        OS_VERSION="7"
else
	echo Sorry , The current system is unknown .	
	exit
fi

# 检查是否已经安装了 BBR
if lsmod | grep -Eqi "bbr" ; then
        echo The server already installed BBR .
        exit
fi

# 1.check network ,检查是否可以访问互联网
CHANGE_FLAG="0"
CODE=`curl -I -m 30 -o /dev/null -s -w %{http_code} http://www.baidu.com`
if [ "$CODE" != "200" ] ; then
	# 如果不可以访问互联网,就去 192.168.1.1 上开启 IP 路由转发和 NAT ,然后把 192.168.1.1 当做这台服务器的网关
	echo "WARNING !接下来要做 NAT ,请不要同时在多台服务器上同时跑这个脚本!因为当某台服务器安装完 BBR 后会去清理掉 NAT ,其他服务器将无法通过 NAT 继续访问互联网。 "
	read -p "Presses Y to continue , presses E to exit ..." IS_CONTINUE
	if [ "$IS_CONTINUE" != "Y" -a "$IS_CONTINUE" != "y" ] ; then
                exit
        fi
        CHANGE_FLAG="1"

	# 选择内网网卡,好往这个网卡的配置文件里添加一行网关的配置( GATEWAY=192.168.1.1 ),然后重启网络服务让配置生效,这样服务器就可以通过 192.168.1.1 访问互联网了。
        echo network-scripts list :
        ls /etc/sysconfig/network-scripts/ | grep ifcfg-

        NETWORK_CONFIG_DIR="/etc/sysconfig/network-scripts/"
        NETWORK_CONFIG_NAME="NULL"
        while [ ! -f "$NETWORK_CONFIG_DIR$NETWORK_CONFIG_NAME" ] ; do
                read -p "Please input the private network config name (eg:ifcfg-eth1) : " NETWORK_CONFIG_NAME
        done

	cp -f $NETWORK_CONFIG_DIR$NETWORK_CONFIG_NAME /tmp/network_config.bak

	echo
	echo 'please input the root password:123456'
	# 此处 eth0 需要是能够访问外部网络的网卡接口
	ssh -t root@192.168.1.1 'iptables -t nat -F && iptables -P FORWARD ACCEPT && iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE && echo "1" > /proc/sys/net/ipv4/ip_forward'

	sed -i "/GATEWAY=/d" $NETWORK_CONFIG_DIR$NETWORK_CONFIG_NAME
	echo "GATEWAY=192.168.1.1" >> $NETWORK_CONFIG_DIR$NETWORK_CONFIG_NAME
	service network restart
fi


CODE=`curl -I -m 30 -o /dev/null -s -w %{http_code} http://www.baidu.com`
if [ "$CODE" == "200" ] ; then

# 2.install BBR ,安装 BBR

	if [ "$OS_VERSION" = "6" ] ; then
		echo
		echo The Server running CentOS Linux 6.x
		echo
                
                # 如果不升级 nss 的话,在访问一些 https 站点时可能会报错
		yum update -y nss
		rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
                rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
		yum --enablerepo=elrepo-kernel -y install kernel-ml kernel-ml-devel
			
		sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
		sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
		sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf

		echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
		echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
		
	elif [ "$OS_VERSION" = "7" ] ; then
		echo
		echo The Server running CentOS Linux 7.x
		echo

		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 --enablerepo=elrepo-kernel install kernel-ml -y
		
		egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
		grub2-set-default 0

		echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
		echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
	fi
else
	# 网络还是不通
	echo Sorry ! Network connection failure , please check it !
fi

# 3.clear the network config ,清理相关网络配置,恢复原样
if [ "$CHANGE_FLAG" == "1" ] ; then
	echo
	echo 'please input the root password:123456'
	ssh -t root@192.168.1.1 'iptables -t nat -F && echo "0" > /proc/sys/net/ipv4/ip_forward'

	mv -f /tmp/network_config.bak $NETWORK_CONFIG_DIR$NETWORK_CONFIG_NAME
	service network restart

	# 这个 yum 源需要通过互联网才能访问到,如果内网机器平常不会连接互联网,那么最好改下这个文件名,防止这个 yum 源生效
	mv /etc/yum.repos.d/elrepo.repo /etc/yum.repos.d/elrepo.repo_bak
fi

# 4.hint ,安装完 BBR 并重新启动服务器后,可使用下列命令来查看 BBR 是否安装成功
echo
echo '==========================

Check the BBR command :

cat /etc/redhat-release
uname -r
lsmod | grep bbr
sysctl net.ipv4.tcp_available_congestion_control

=========================='

# 5.reboot the server ,重启服务器
echo
read -p "Presses Y to reboot system ..."  IS_REBOOT
if [ "$IS_REBOOT" == "Y" -o "$IS_REBOOT" == "y" ] ; then
	reboot
fi

( 1 )找一台服务器临时充当网关:

在安装 BBR 前该脚本会检查服务器是否可以访问互联网( 1.check network 部分),如果您的服务器已经接入互联网,那么直接跑上述脚本一般是没有什么问题的;但如果该服务器没有接入互联网,该脚本也提供了一个解决方法:

假设需要安装 BBR 的服务器是 192.168.1.2 ,该服务器没有接入互联网;但是有一台 CentOS Linux 服务器 192.168.1.1 是接入了互联网的。那么可以在 192.168.1.1 上开启 IP 路由转发和 NAT 功能(如何在 CentOS Linux 上开启 IP 路由转发和 NAT ?详情请点击这里),再把 192.168.1.1 设置为 192.168.1.2 的网关,这样 192.168.1.2 就可以接入互联网了。当 BBR 安装完毕后再关闭 192.168.1.1 上的 IP 路由转发和 NAT 功能,再恢复 192.168.1.2 的网卡配置即可。

需要自行修改的地方:

  1. 您临时充当网关的服务器不一定是 192.168.1.1 ,所以在使用上述功能前请根据实际情况全文替换掉这个 IP 地址;您可以使用以下命令来进行一个批量替换的操作:
    sed -i "s#192.168.1.1#x.x.x.x#g"  /tmp/install_bbr.sh
  2. 脚本中的 123456 是 192.168.1.1 的 root 密码,为了方便您可以将密码写到脚本中;但如果从安全的角度考虑,您可以不用写入。
  3. 如下所示,此处 eth0 需要是服务器 192.168.1.1 上能够访问外部网络的网卡接口,请根据实际情况进行相应地修改:
    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

( 2 )关于 yum 源 elrepo.repo 是否需要改名的问题:

如果您的服务器已经接入互联网,加入这个 elrepo.repo 的 yum 源本身并没有什么问题;但如果您的服务器是通过 “ ( 1 )找一台服务器临时充当网关 ” 中描述的那样来安装 BBR 的,那么当服务器恢复到无法访问互联网的时候,这个 elrepo.repo 的 yum 源是无法使用的,所以需要进行如下所示的改名操作,防止这个 elrepo.repo 的 yum 源生效:

mv /etc/yum.repos.d/elrepo.repo /etc/yum.repos.d/elrepo.repo_bak

( 3 )关于检测互联网是否能访问的问题:

上述脚本会去访问 http://www.baidu.com 这个网址,如果能访问则判定互联网是可以访问的,您可以根据实际情况修改这个网址。

( 4 )请检查 DNS 域名解析是否能正常工作:

如果您的服务器已经接入互联网但是没法解析域名 www.elrepo.org ,那么 BBR 内核也是没法下载并更新的。此时服务器的表现为:外网 IP 地址可以 ping 通(如 ping 47.88.138.127 ),但是域名 ping 不通(如 ping ccie.lol )。

回滚内核:

( 1 )CentOS Linux 7 回滚内核:

先执行以下两条命令清理掉开启 BBR 的配置:

[root@host ~]# sed -i "/net.core.default_qdisc = fq/d" /etc/sysctl.conf
[root@host ~]# sed -i "/net.ipv4.tcp_congestion_control = bbr/d" /etc/sysctl.conf

接着使用如下命令查看当前 CentOS Linux 7 都安装了哪些内核:

[root@host ~]# egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
CentOS Linux (4.18.12-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux, with Linux 3.10.0-123.el7.x86_64
CentOS Linux, with Linux 0-rescue-ba3855e0f00f4ccdba0eabea711139b1
[root@host ~]#

如需选择版本号为 3.10.0-123 的内核,则执行以下命令并重启服务器即可:

[root@host ~]# grub2-set-default 1
[root@host ~]# reboot

即第一个内核的序号为 0 ,第二个内核的序号为 1 。

重启后使用 uname -r 命令即可查看当前运行的内核的版本号:

[root@host ~]# uname -r
3.10.0-123.el7.x86_64
[root@host ~]#

( 2 )CentOS Linux 6 回滚内核:

抱歉,关于 CentOS Linux 6 回滚内核的操作暂时还没有研究。

示例:

( 1 )CentOS Linux 6.2 安装示例(服务器位于内网,需要一台 CentOS Linux 充当网关):

[root@host ~]# cat /etc/redhat-release 
CentOS release 6.2 (Final)
[root@host ~]# 
[root@host ~]# sh install_bbr.sh 
WARNING !接下来要做 NAT ,请不要同时在多台服务器上同时跑这个脚本!因为当某台服务器安装完 BBR 后会去清理掉 NAT ,其他服务器将无法通过 NAT 继续访问互联网。 
Presses Y to continue , presses E to exit ...q
[root@host ~]# 
[root@host ~]# sh install_bbr.sh 
WARNING !接下来要做 NAT ,请不要同时在多台服务器上同时跑这个脚本!因为当某台服务器安装完 BBR 后会去清理掉 NAT ,其他服务器将无法通过 NAT 继续访问互联网。 
Presses Y to continue , presses E to exit ...y  
network-scripts list :
ifcfg-eth0
ifcfg-eth1
ifcfg-lo
Please input the private network config name (eg:ifcfg-eth1) : 
Please input the private network config name (eg:ifcfg-eth1) : ifcfg-eth2
Please input the private network config name (eg:ifcfg-eth1) : test
Please input the private network config name (eg:ifcfg-eth1) : ifcfg-eth1   

please input the root password:123456
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is aa:bb:cc:dd:ee:ff:gg:hh:ii:jj:kk:ll:mm:96:8e:80.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
root@192.168.1.1's password: 
Connection to 192.168.1.1 closed.
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
FATAL: Module off not found.
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth1:                                [  OK  ]
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
FATAL: Module off not found.

The Server running CentOS Linux 6.x

Loaded plugins: fastestmirror, security
Determining fastest mirrors
base                                                                                                                                                                              | 3.7 kB     00:00     
base/primary_db                                                                                                                                                                   | 4.7 MB     00:00     
extras                                                                                                                                                                            | 3.4 kB     00:00     
extras/primary_db                                                                                                                                                                 |  26 kB     00:00     
updates                                                                                                                                                                           | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                | 1.2 MB     00:00     
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package nss.x86_64 0:3.14.3-4.el6_4 will be updated
--> Processing Dependency: nss = 3.14.3-4.el6_4 for package: nss-sysinit-3.14.3-4.el6_4.x86_64
--> Processing Dependency: nss = 3.14.3-4.el6_4 for package: nss-tools-3.14.3-4.el6_4.x86_64
---> Package nss.x86_64 0:3.36.0-8.el6 will be an update
--> Processing Dependency: nss-util >= 3.36.0 for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: nss-softokn(x86-64) >= 3.14.3-22 for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: nspr >= 4.19.0 for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.33)(64bit) for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.31)(64bit) for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.24)(64bit) for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.21)(64bit) for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.17.1)(64bit) for package: nss-3.36.0-8.el6.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.15)(64bit) for package: nss-3.36.0-8.el6.x86_64
--> Running transaction check
---> Package nspr.x86_64 0:4.9.5-2.el6_4 will be updated
---> Package nspr.x86_64 0:4.19.0-1.el6 will be an update
---> Package nss-softokn.x86_64 0:3.14.3-3.el6_4 will be updated
---> Package nss-softokn.x86_64 0:3.14.3-23.3.el6_8 will be an update
--> Processing Dependency: nss-softokn-freebl(x86-64) >= 3.14.3-23.3.el6_8 for package: nss-softokn-3.14.3-23.3.el6_8.x86_64
---> Package nss-sysinit.x86_64 0:3.14.3-4.el6_4 will be updated
---> Package nss-sysinit.x86_64 0:3.36.0-8.el6 will be an update
---> Package nss-tools.x86_64 0:3.14.3-4.el6_4 will be updated
---> Package nss-tools.x86_64 0:3.36.0-8.el6 will be an update
---> Package nss-util.x86_64 0:3.14.3-3.el6_4 will be updated
---> Package nss-util.x86_64 0:3.36.0-1.el6 will be an update
--> Running transaction check
---> Package nss-softokn-freebl.x86_64 0:3.14.3-3.el6_4 will be updated
---> Package nss-softokn-freebl.x86_64 0:3.14.3-23.3.el6_8 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================================================
 Package                                                Arch                                       Version                                                Repository                                Size
=========================================================================================================================================================================================================
Updating:
 nss                                                    x86_64                                     3.36.0-8.el6                                           base                                     865 k
Updating for dependencies:
 nspr                                                   x86_64                                     4.19.0-1.el6                                           base                                     114 k
 nss-softokn                                            x86_64                                     3.14.3-23.3.el6_8                                      base                                     262 k
 nss-softokn-freebl                                     x86_64                                     3.14.3-23.3.el6_8                                      base                                     168 k
 nss-sysinit                                            x86_64                                     3.36.0-8.el6                                           base                                      52 k
 nss-tools                                              x86_64                                     3.36.0-8.el6                                           base                                     460 k
 nss-util                                               x86_64                                     3.36.0-1.el6                                           base                                      72 k

Transaction Summary
=========================================================================================================================================================================================================
Upgrade       7 Package(s)

Total download size: 1.9 M
Downloading Packages:
(1/7): nspr-4.19.0-1.el6.x86_64.rpm                                                                                                                                               | 114 kB     00:00     
(2/7): nss-3.36.0-8.el6.x86_64.rpm                                                                                                                                                | 865 kB     00:00     
(3/7): nss-softokn-3.14.3-23.3.el6_8.x86_64.rpm                                                                                                                                   | 262 kB     00:00     
(4/7): nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64.rpm                                                                                                                            | 168 kB     00:00     
(5/7): nss-sysinit-3.36.0-8.el6.x86_64.rpm                                                                                                                                        |  52 kB     00:00     
(6/7): nss-tools-3.36.0-8.el6.x86_64.rpm                                                                                                                                          | 460 kB     00:00     
(7/7): nss-util-3.36.0-1.el6.x86_64.rpm                                                                                                                                           |  72 kB     00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                     35 MB/s | 1.9 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : nspr-4.19.0-1.el6.x86_64                                                                                                                                                             1/14 
  Updating   : nss-util-3.36.0-1.el6.x86_64                                                                                                                                                         2/14 
  Updating   : nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64                                                                                                                                          3/14 
  Updating   : nss-softokn-3.14.3-23.3.el6_8.x86_64                                                                                                                                                 4/14 
  Updating   : nss-sysinit-3.36.0-8.el6.x86_64                                                                                                                                                      5/14 
  Updating   : nss-3.36.0-8.el6.x86_64                                                                                                                                                              6/14 
  Updating   : nss-tools-3.36.0-8.el6.x86_64                                                                                                                                                        7/14 
  Cleanup    : nss-tools-3.14.3-4.el6_4.x86_64                                                                                                                                                      8/14 
  Cleanup    : nss-sysinit-3.14.3-4.el6_4.x86_64                                                                                                                                                    9/14 
  Cleanup    : nss-3.14.3-4.el6_4.x86_64                                                                                                                                                           10/14 
  Cleanup    : nss-softokn-3.14.3-3.el6_4.x86_64                                                                                                                                                   11/14 
  Cleanup    : nss-util-3.14.3-3.el6_4.x86_64                                                                                                                                                      12/14 
  Cleanup    : nspr-4.9.5-2.el6_4.x86_64                                                                                                                                                           13/14 
  Cleanup    : nss-softokn-freebl-3.14.3-3.el6_4.x86_64                                                                                                                                            14/14 

Updated:
  nss.x86_64 0:3.36.0-8.el6                                                                                                                                                                              

Dependency Updated:
  nspr.x86_64 0:4.19.0-1.el6        nss-softokn.x86_64 0:3.14.3-23.3.el6_8    nss-softokn-freebl.x86_64 0:3.14.3-23.3.el6_8    nss-sysinit.x86_64 0:3.36.0-8.el6    nss-tools.x86_64 0:3.36.0-8.el6   
  nss-util.x86_64 0:3.36.0-1.el6   

Complete!
Retrieving http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
Preparing...                ########################################### [100%]
   1:elrepo-release         ########################################### [100%]
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * elrepo: elrepo.org
 * elrepo-kernel: elrepo.org
elrepo                                                                                                                                                                            | 2.9 kB     00:00     
elrepo/primary_db                                                                                                                                                                 | 682 kB     00:01     
elrepo-kernel                                                                                                                                                                     | 2.9 kB     00:00     
elrepo-kernel/primary_db                                                                                                                                                          |  22 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:4.18.10-1.el6.elrepo will be installed
---> Package kernel-ml-devel.x86_64 0:4.18.10-1.el6.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================================================
 Package                                           Arch                                     Version                                                Repository                                       Size
=========================================================================================================================================================================================================
Installing:
 kernel-ml                                         x86_64                                   4.18.10-1.el6.elrepo                                   elrepo-kernel                                    45 M
 kernel-ml-devel                                   x86_64                                   4.18.10-1.el6.elrepo                                   elrepo-kernel                                    12 M

Transaction Summary
=========================================================================================================================================================================================================
Install       2 Package(s)

Total download size: 57 M
Installed size: 246 M
Downloading Packages:
(1/2): kernel-ml-4.18.10-1.el6.elrepo.x86_64.rpm                                                                                                                                  |  45 MB     00:04     
(2/2): kernel-ml-devel-4.18.10-1.el6.elrepo.x86_64.rpm                                                                                                                            |  12 MB     00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                    9.5 MB/s |  57 MB     00:06     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : kernel-ml-devel-4.18.10-1.el6.elrepo.x86_64                                                                                                                                           1/2 
  Installing : kernel-ml-4.18.10-1.el6.elrepo.x86_64                                                                                                                                                 2/2 

Installed:
  kernel-ml.x86_64 0:4.18.10-1.el6.elrepo                                                          kernel-ml-devel.x86_64 0:4.18.10-1.el6.elrepo                                                         

Complete!

please input the root password:123456
root@192.168.1.1's password: 
Connection to 192.168.1.1 closed.
Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
FATAL: Module off not found.
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth1:                                [  OK  ]
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
FATAL: Module off not found.

==========================

Check the BBR command :

cat /etc/redhat-release
uname -r
lsmod | grep bbr
sysctl net.ipv4.tcp_available_congestion_control

==========================

Presses Y to reboot system ...y
[root@host ~]# 
Broadcast message from root@host
        (/dev/pts/0) at 17:10 ...

The system is going down for reboot NOW!
Connection to 192.168.1.2 closed by remote host.
Connection to 192.168.1.2 closed.
[huangyj@other ~]$ 
[huangyj@other ~]$ ssh root@192.168.1.2
root@192.168.1.2's password: 
Last login: Sat Sep 29 14:07:32 2018
[root@host ~]# 
[root@host ~]# cat /etc/redhat-release
CentOS release 6.2 (Final)
[root@host ~]# uname -r
4.18.10-1.el6.elrepo.x86_64
[root@host ~]# lsmod | grep bbr
tcp_bbr                20480  14 
[root@host ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic bbr
[root@host ~]# 
[root@host ~]# 
[root@host ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 
DEVICE="eth1"
NM_CONTROLLED="yes"
ONBOOT="yes"
NETMASK="255.255.255.0"
BOOTPROTO="static"
IPADDR="192.168.1.2"
[root@host ~]#

如上所示,执行完该脚本后重启服务器,再次登录上来发现 BBR 已经安装成功了,同时 ifcfg-eth1 这个网卡配置文件也恢复到了最初的状态(最初就没有设置 GATEWAY )。

( 2 )CentOS Linux 7.0 安装示例(服务器位于内网,需要一台 CentOS Linux 充当网关):

[root@host ~]# cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core) 
[root@host ~]#
[root@host ~]# sh install_bbr.sh 
WARNING !接下来要做 NAT ,请不要同时在多台服务器上同时跑这个脚本!因为当某台服务器安装完 BBR 后会去清理掉 NAT ,其他服务器将无法通过 NAT 继续访问互联网。 
Presses Y to continue , presses E to exit ...y
network-scripts list :
ifcfg-eth0
ifcfg-eth1
ifcfg-lo
Please input the private network config name (eg:ifcfg-eth1) : ifcfg-eth1

please input the root password:123456
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
ECDSA key fingerprint is aa:bb:cc:dd:ee:ff:gg:hh:ii:jj:kk:ll:mm:af:e9:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.1' (ECDSA) to the list of known hosts.
root@192.168.1.1's password: 
Connection to 192.168.1.1 closed.
Restarting network (via systemctl):                        [  OK  ]

The Server running CentOS Linux 7.x

curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s).
error: https://www.elrepo.org/RPM-GPG-KEY-elrepo.org: import read failed(2).
Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
warning: /var/tmp/rpm-tmp.mA4dco: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:elrepo-release-7.0-3.el7.elrepo  ################################# [100%]
Loaded plugins: fastestmirror
base                                                                                                                                                                              | 3.6 kB  00:00:00     
elrepo                                                                                                                                                                            | 2.9 kB  00:00:00     
elrepo-kernel                                                                                                                                                                     | 2.9 kB  00:00:00     
extras                                                                                                                                                                            | 3.4 kB  00:00:00     
tyrepo                                                                                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                                                                                           | 3.4 kB  00:00:00     
(1/7): base/7/x86_64/group_gz                                                                                                                                                     | 166 kB  00:00:00     
(2/7): tyrepo/7/x86_64/primary_db                                                                                                                                                 | 7.2 kB  00:00:00     
(3/7): extras/7/x86_64/primary_db                                                                                                                                                 | 187 kB  00:00:00     
(4/7): updates/7/x86_64/primary_db                                                                                                                                                | 6.0 MB  00:00:00     
(5/7): base/7/x86_64/primary_db                                                                                                                                                   | 5.9 MB  00:00:00     
(6/7): elrepo/primary_db                                                                                                                                                          | 489 kB  00:00:02     
(7/7): elrepo-kernel/primary_db                                                                                                                                                   | 1.8 MB  00:00:02     
Determining fastest mirrors
 * elrepo: hkg.mirror.rackspace.com
 * elrepo-kernel: hkg.mirror.rackspace.com
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:4.18.11-1.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================================================
 Package                                      Arch                                      Version                                                   Repository                                        Size
=========================================================================================================================================================================================================
Installing:
 kernel-ml                                    x86_64                                    4.18.11-1.el7.elrepo                                      elrepo-kernel                                     45 M

Transaction Summary
=========================================================================================================================================================================================================
Install  1 Package

Total download size: 45 M
Installed size: 203 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/elrepo-kernel/packages/kernel-ml-4.18.11-1.el7.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY===========-    ]  11 MB/s |  43 MB  00:00:00 ETA 
Public key for kernel-ml-4.18.11-1.el7.elrepo.x86_64.rpm is not installed
kernel-ml-4.18.11-1.el7.elrepo.x86_64.rpm                                                                                                                                         |  45 MB  00:00:02     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Importing GPG key 0xBAADAE52:
 Userid     : "elrepo.org (RPM Signing Key for elrepo.org) <secure@elrepo.org>"
 Fingerprint: 96c0 104f 6315 4731 1e0b b1ae 309b c305 baad ae52
 Package    : elrepo-release-7.0-3.el7.elrepo.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : kernel-ml-4.18.11-1.el7.elrepo.x86_64                                                                                                                                                 1/1 
  Verifying  : kernel-ml-4.18.11-1.el7.elrepo.x86_64                                                                                                                                                 1/1 

Installed:
  kernel-ml.x86_64 0:4.18.11-1.el7.elrepo                                                                                                                                                                

Complete!
CentOS Linux (4.18.11-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux, with Linux 3.10.0-123.el7.x86_64
CentOS Linux, with Linux 0-rescue-ba3855e0f00f4ccdba0eabea711139b1

please input the root password:123456
root@192.168.1.1's password: 
Connection to 192.168.1.1 closed.
Restarting network (via systemctl):                        [  OK  ]

==========================

Check the BBR command :

cat /etc/redhat-release
uname -r
lsmod | grep bbr
sysctl net.ipv4.tcp_available_congestion_control

==========================

Presses Y to reboot system ...y
Connection to 192.168.1.2 closed by remote host.
Connection to 192.168.1.2 closed. 
[huangyj@other ~]$ 
[huangyj@other ~]$ ssh root@192.168.1.2
root@192.168.1.2's password: 
Last login: Sun Sep 30 10:26:22 2018 from 19.2.108.41
[root@host ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core) 
[root@host ~]# uname -r
4.18.11-1.el7.elrepo.x86_64
[root@host ~]# lsmod | grep bbr
tcp_bbr                20480  19 
[root@host ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic bbr
[root@host ~]# 
[root@host ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 
DEVICE="eth1"
NM_CONTROLLED="yes"
ONBOOT="yes"
NETMASK="255.255.255.0"
BOOTPROTO="static"
IPADDR="192.168.1.2"
[root@host ~]#

如上所示,执行完该脚本后重启服务器,再次登录上来发现 BBR 已经安装成功了,同时 ifcfg-eth1 这个网卡配置文件也恢复到了最初的状态(最初就没有设置 GATEWAY )。

打赏作者
这里是 “ CCIE 工程师社区 ” 官方的捐款通道,您是否可以考虑请我们喝杯咖啡呢?

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏

Article Attachments

Was this article helpful?

Related Articles

1 Comment

  1. 2018 年 10 月 11 日 14:12:28 ,添加 “ 回滚内核 ” 的相关内容。

Leave A Comment?

This site uses Akismet to reduce spam. Learn how your comment data is processed.