81 lines
2.2 KiB
Bash
81 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
# Install script for BBR base on CentOS 7 by xiaosong
|
|
CentOS_Version=`cat /etc/redhat-release | grep -oE '[0-9]+\.[0-9]+' | cut -d'.' -f1`
|
|
KVersion=4.13.0-1
|
|
|
|
if [ -z ${CentOS_Version} ]
|
|
then
|
|
CentOS_Version=0
|
|
fi
|
|
|
|
if [ ${CentOS_Version} -lt 6 ]
|
|
then
|
|
echo "Sorry, I can only support CentOS 6/7 yet."
|
|
exit
|
|
fi
|
|
|
|
if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then
|
|
BIT_VER=x64
|
|
else
|
|
BIT_VER=x86
|
|
fi
|
|
|
|
if [ ${BIT_VER} != 'x64' ]
|
|
then
|
|
echo "Sorry, I can only support x64 yet."
|
|
exit
|
|
fi
|
|
|
|
function modifySysctl() {
|
|
if [ ! `cat /etc/sysctl.conf | grep -i -E "net.core.default_qdisc = fq"` ]; then
|
|
echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
|
|
fi
|
|
if [ ! `cat /etc/sysctl.conf | grep -i -E "net.ipv4.tcp_congestion_control = bbr"` ]; then
|
|
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
|
|
fi
|
|
}
|
|
|
|
echo "Now I will replace the system kernel to ${KVersion}..."
|
|
echo "Start installing"
|
|
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
|
|
if [ ${CentOS_Version} -eq 7 ]
|
|
then
|
|
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
|
|
else
|
|
rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
|
|
fi
|
|
yum --enablerepo=elrepo-kernel install -y kernel-ml
|
|
echo "Checking if the installtion is ok"
|
|
KGRUB2=`ls /etc/grub2.cfg|wc -l`
|
|
if [ ${KGRUB2} -eq 1 ]
|
|
then
|
|
INS_OK=`awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg | grep ${KVersion} | grep -i -v debug | grep -i -v rescue | cut -d' ' -f1`
|
|
if [ -z ${INS_OK} ]
|
|
then
|
|
echo "Sorry, install failed, please contact the author"
|
|
exit
|
|
fi
|
|
yum install -y grub2-tools
|
|
grub2-set-default ${INS_OK}
|
|
modifySysctl
|
|
else
|
|
KGRUB=`ls /boot/grub/grub.conf|wc -l`
|
|
if [ ${KGRUB} -eq 1 ]
|
|
then
|
|
INS_OK=`grep '^title ' /boot/grub/grub.conf | awk -F'title ' '{print i++ " : " $2}' | grep ${KVersion} | grep -i -v debug | grep -i -v rescue | cut -d' ' -f1`
|
|
if [ -z ${INS_OK} ]
|
|
then
|
|
echo "Sorry, install failed, please contact the author"
|
|
exit
|
|
fi
|
|
sed -i "s/^default.*/default=${INS_OK}/" /boot/grub/grub.conf
|
|
modifySysctl
|
|
fi
|
|
fi
|
|
|
|
echo " "
|
|
echo "Installation is completed, now you can reboot the system. "
|
|
echo "You should check BBR after the rebooting using command: "
|
|
echo " "
|
|
echo " sysctl -a|grep congestion_control" |