介绍
我们有时候贪便宜买了垃圾小鸡,128M,256M的,突然发现内存总是炸,Alpine Linux又用不来,还是大便大法好,直到有老哥给我安利了cloud内核,说可能有奇效。
cloud内核官方介绍:
This package depends on the latest Linux kernel and modules for use on Amazon EC2, Google Compute Engine and Microsoft Azure cloud platforms.
即是为这些云平台而优化的。这样好似会增加一些模块,裁剪的部分在哪?可以从 News from the Debian Cloud Team 中一探究竟:
A cloud-specific Linux package (linux-image-cloud) allowed us to disable features that are not relevant in cloud environments and enable what is really important. For example, features related to bluetooth and sound support are disabled and some drivers needed by the cloud providers are enabled. To illustrate that, Amazon EC2 uses Elastic Network Adapter (ENA) support and Intel Corporation 82599 Ethernet Controller Virtual Function, and Microsoft Azure uses Mellanox Technologies MT27500/MT27520 Family [ConnectX-3/ConnectX-3 Pro Virtual Function], all of them are enabled by default in linux-image-cloud package (and are not needed at all by regular Debian users).
大意是说,有些特性是云环境不需要的,像蓝牙、声音支持。看来,-cloud 内核剔除了这些无用模块(同时添加了几乎只有云平台会用到的驱动程序)。
我们再来看下对比:
源 | 内核 | 版本号 | 软件包大小* | 安装后大小* |
---|---|---|---|---|
jessie | linux-image-amd64 | 3.16 | 33MB | 160MB |
stretch | linux-image-amd64 | 4.9 | 37MB | 184MB |
stretch-backports | linux-image-amd64 | 4.19 | 45MB | 253MB |
stretch-backports | linux-image-cloud-amd64 | 4.19 | 15MB | 65MB |
buster | linux-image-amd64 | 4.19 | 46MB | 256MB |
buster | linux-image-cloud-amd64 | 4.19 | 15MB | 66MB |
buster-backports** | linux-image-amd64 | 5.3 | 47MB | 263MB |
buster-backports** | linux-image-cloud-amd64 | 5.3 | 15MB | 69MB |
从上表可以看到,就大小来讲,-cloud 内核可谓轻量极了。5.3 的 -cloud 内核比 3.16 原版内核还要小,就算把安装后全部文件丢到内存都不怕,难怪可以在极小内存的 VPS 上启动。
安装
cloud 内核的包名是 linux-image-cloud-amd64,可以直接从官方源安装,也可以从backports源安装更高的版本。我们以Debian10和Debian11为例
Debian10
apt update -y
apt install linux-image-cloud-amd64 -y
Debian 10 安装完的内核为4.19.0-17-cloud-amd64
,具体可参考官方的软件包
如果需要安装5.10内核,则需要从 backports 源安装,先直接换下源:
cat > /etc/apt/sources.list << EOF
deb http://deb.debian.org/debian/ buster main contrib non-free
deb-src http://deb.debian.org/debian/ buster main contrib non-free
deb http://deb.debian.org/debian/ buster-updates main contrib non-free
deb-src http://deb.debian.org/debian/ buster-updates main contrib non-free
deb http://deb.debian.org/debian/ buster-backports main contrib non-free
deb-src http://deb.debian.org/debian/ buster-backports main contrib non-free
deb http://deb.debian.org/debian-security/ buster/updates main contrib non-free
deb-src http://deb.debian.org/debian-security/ buster/updates main contrib non-free
EOF
apt update -y
apt -t buster-backports install linux-image-cloud-amd64 -y
Debian11
官方源一样的命令:
apt update -y
apt install linux-image-cloud-amd64 -y
backports 源安装:
cat > /etc/apt/sources.list <<EOF
deb http://deb.debian.org/debian/ bullseye main non-free contrib
deb http://deb.debian.org/debian/ bullseye-updates main non-free contrib
deb-src http://deb.debian.org/debian/ bullseye main non-free contrib
deb-src http://deb.debian.org/debian/ bullseye-updates main non-free contrib
deb http://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb http://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb-src http://deb.debian.org/debian-security/ bullseye-security main contrib non-free
EOF
apt -t bullseye-backports install linux-image-cloud-amd64 -y
更新grub
sudo update-grub
重启
reboot
八、验证是否成功
uname -r
手动开启BBR
重启后一键开启BBR:
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf && echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf && sysctl -p
检查BBR是否启动
lsmod | grep bbr lsmod | grep bbr
最后
要是apt update时遇到软件包签名错误,可以查看这篇教程:
参考文献:
https://shansing.com/read/486/
https://www.uskvm.com/p/253.html
https://blog.wittoy.com/archives/linux-cloud-kernel/
https://bobqu.cyou/2022/07/06/69.html
https://hostloc.com/thread-1196296-1-1.html