mirror of
https://github.com/teddysun/across.git
synced 2025-01-18 22:09:35 +08:00
update comments
check tcp_available_congestion_control, if BBR has been installed, skipped installation; check kernel version at first, if kernel version is greater than 4.9, directly setting TCP BBR. Signed-off-by: Teddysun <i@teddysun.com>
This commit is contained in:
parent
bc1fb1fa53
commit
b2b6aaab1c
72
bbr.sh
72
bbr.sh
@ -14,6 +14,8 @@ green='\033[0;32m'
|
|||||||
yellow='\033[0;33m'
|
yellow='\033[0;33m'
|
||||||
plain='\033[0m'
|
plain='\033[0m'
|
||||||
|
|
||||||
|
cur_dir=$(pwd)
|
||||||
|
|
||||||
[[ $EUID -ne 0 ]] && echo -e "${red}Error:${plain} This script must be run as root!" && exit 1
|
[[ $EUID -ne 0 ]] && echo -e "${red}Error:${plain} This script must be run as root!" && exit 1
|
||||||
|
|
||||||
[[ -d "/proc/vz" ]] && echo -e "${red}Error:${plain} Your VPS is based on OpenVZ, not be supported." && exit 1
|
[[ -d "/proc/vz" ]] && echo -e "${red}Error:${plain} Your VPS is based on OpenVZ, not be supported." && exit 1
|
||||||
@ -99,12 +101,21 @@ centosversion() {
|
|||||||
|
|
||||||
check_bbr_status() {
|
check_bbr_status() {
|
||||||
local param=$(sysctl net.ipv4.tcp_available_congestion_control | awk '{print $3}')
|
local param=$(sysctl net.ipv4.tcp_available_congestion_control | awk '{print $3}')
|
||||||
if uname -r | grep -Eqi "4.10."; then
|
if [[ "${param}" == "bbr" ]]; then
|
||||||
if [[ "${param}" == "bbr" ]]; then
|
return 0
|
||||||
return 0
|
else
|
||||||
else
|
return 1
|
||||||
return 1
|
fi
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
version_ge(){
|
||||||
|
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_kernel_version() {
|
||||||
|
local kernel_version=$(uname -r | cut -d- -f1)
|
||||||
|
if version_ge ${kernel_version} 4.9; then
|
||||||
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -131,6 +142,14 @@ install_elrepo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sysctl_config() {
|
||||||
|
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
|
||||||
|
sysctl -p >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
install_config() {
|
install_config() {
|
||||||
if [[ "${release}" == "centos" ]]; then
|
if [[ "${release}" == "centos" ]]; then
|
||||||
if centosversion 6; then
|
if centosversion 6; then
|
||||||
@ -149,20 +168,34 @@ install_config() {
|
|||||||
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
|
elif [[ "${release}" == "debian" || "${release}" == "ubuntu" ]]; then
|
||||||
/usr/sbin/update-grub
|
/usr/sbin/update-grub
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
|
reboot_os() {
|
||||||
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
|
echo
|
||||||
echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
|
echo -e "${green}Info:${plain} The system needs to reboot."
|
||||||
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
|
read -p "Do you want to restart system? [y/n]" is_reboot
|
||||||
sysctl -p >/dev/null 2>&1
|
if [[ ${is_reboot} == "y" || ${is_reboot} == "Y" ]]; then
|
||||||
|
reboot
|
||||||
|
else
|
||||||
|
echo -e "${green}Info:${plain} Reboot has been canceled..."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_bbr() {
|
install_bbr() {
|
||||||
check_bbr_status
|
check_bbr_status
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo
|
echo
|
||||||
echo -e "${green}Info:${plain} TCP BBR has been successfully installed. nothing to do..."
|
echo -e "${green}Info:${plain} TCP BBR has been installed. nothing to do..."
|
||||||
exit
|
exit 0
|
||||||
|
fi
|
||||||
|
check_kernel_version
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo
|
||||||
|
echo -e "${green}Info:${plain} Your kernel version is greater than 4.9, directly setting TCP BBR..."
|
||||||
|
sysctl_config
|
||||||
|
echo -e "${green}Info:${plain} Setting TCP BBR completed..."
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${release}" == "centos" ]]; then
|
if [[ "${release}" == "centos" ]]; then
|
||||||
@ -189,8 +222,11 @@ install_bbr() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
install_config
|
install_config
|
||||||
|
sysctl_config
|
||||||
|
reboot_os
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
clear
|
clear
|
||||||
echo "---------- System Information ----------"
|
echo "---------- System Information ----------"
|
||||||
echo " OS : $opsy"
|
echo " OS : $opsy"
|
||||||
@ -205,12 +241,4 @@ echo
|
|||||||
echo "Press any key to start...or Press Ctrl+C to cancel"
|
echo "Press any key to start...or Press Ctrl+C to cancel"
|
||||||
char=`get_char`
|
char=`get_char`
|
||||||
|
|
||||||
install_bbr
|
install_bbr 2>&1 | tee ${cur_dir}/install_bbr.log
|
||||||
|
|
||||||
echo
|
|
||||||
read -p "Info: The system needs to be restart. Do you want to reboot? [y/n]" is_reboot
|
|
||||||
if [[ ${is_reboot} == "y" || ${is_reboot} == "Y" ]]; then
|
|
||||||
reboot
|
|
||||||
else
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user