基于Debian的系统高并发环境并启用BBR

system

基于Debian的系统高并发环境并启用BBR

2023-10-26 06:52


                                            




设置高并发环境并启用BBR:

#!/bin/bash

 

# 更新系统并安装必要的软件

sudo apt update && sudo apt upgrade -y

 

# 安装最新的稳定内核

sudo apt install --install-recommends linux-generic-hwe-20.04 -y

 

# 修改sysctl配置以增加并发和性能相关的值

cat <<EOL | sudo tee /etc/sysctl.conf

# Increase system file descriptor limit

fs.file-max = 100000

 

# Increase number of incoming connections

net.core.somaxconn = 4096

 

# Increase number of incoming connections backlog

net.core.netdev_max_backlog = 65536

 

# Increase the maximum number of option memory buffers

net.core.optmem_max = 25165824

 

# Increase the read-buffer space allocatable

net.ipv4.tcp_rmem = 2048 87380 16777216

net.ipv4.tcp_wmem = 2048 65536 16777216

 

# Increase the maximum total buffer-space allocatable

net.ipv4.tcp_mem = 65536 131072 262144

 

# Enable BBR for TCP

net.core.default_qdisc=fq

net.ipv4.tcp_congestion_control=bbr

EOL

 

# 应用配置

sudo sysctl -p

 

echo "Reboot the machine for the changes to take effect."

 

```

 

此脚本首先更新了系统并安装了最新的稳定内核。接着,它修改了一系列`sysctl`配置值,以增加系统的并发处理能力,并启用了BBR。

 

注意:

 

1. 以上脚本假定您使用的是基于Debian的系统,如Ubuntu。如果您使用的是其他发行版,例如CentOS或Fedora,需要相应地调整包管理命令。

2. 重启您的机器后,新内核会生效,并且您的系统会使用新的并发和BBR设置。

3. 在执行任何脚本之前,请确保备份所有重要数据,并在沙盒或测试环境中进行测试。