以下内容均以debian 13 2H4G进行,全程使用su用户,如不是su用户请自行添加sudo
设置swap
虽然服务器是有4G内存,但是设置swap还是能保证一些特殊情况
其中4G内存我是直接分配的4G swap,大概4G及一下设置4G swap比较好一些x
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
|
当前debian 13对/etc/sysctl.conf进行了修改,现在需要前往/etc/sysctl.d文件夹中创建对应的conf才能读取
其中需要配置的是系统使用swap的比例vm.swappiness,如果比例过高可能会导致高负载情况下直接将硬盘IO直接吃满导致宕机,vm.swappiness默认为60,越高越倾向于使用swap,设置为10比较好
cd /etc/sysctl.d vim 50-swap.conf
vm.swappiness = 10
vm.vfs_cache_pressure = 50
vm.dirty_ratio = 20 vm.dirty_background_ratio = 5
sysctl --system
|
设置XanMod Kernel
为了以防万一请先运行下方命令查看到底是否为debian 13
. /etc/os-release && echo "$VERSION_CODENAME"
|
接下来配置仓库
apt update apt install --no-install-recommends curl ca-certificates gpg lsb-release
awk -f <(wget -qO- https://dl.xanmod.org/check_x86-64_psabi.sh)
install -d -m 0755 /etc/apt/keyrings curl -fsSL https://dl.xanmod.org/archive.key | gpg --dearmor -o /etc/apt/keyrings/xanmod-archive-keyring.gpg chmod 0644 /etc/apt/keyrings/xanmod-archive-keyring.gpg
CODENAME="$(. /etc/os-release; echo "$VERSION_CODENAME")" sudo tee /etc/apt/sources.list.d/xanmod.sources >/dev/null <<EOF Types: deb URIs: http://deb.xanmod.org Suites: ${CODENAME} Components: main Architectures: amd64 Signed-By: /etc/apt/keyrings/xanmod-archive-keyring.gpg EOF
sudo apt update && sudo apt install linux-xanmod-edge-x64v3
sudo reboot
uname -r
|
开启BBRv3
刚刚装的xanmod内核内置了BBRv3,但是并没有默认启动,需要自行添加配置文件
vim /etc/sysctl.d/99-bbrv3-optimizations.conf
net.core.default_qdisc = fq_pie
net.ipv4.tcp_congestion_control = bbr
net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 8192
net.core.somaxconn = 8192
sysctl --system
|
磁盘 I/O 挂载优化
Linux 默认在每次读取文件时都会更新文件的最后访问时间 (atime),这会导致不必要的开销
vim /etc/fstab
UUID=xxx-xxx-xxx-xxx-xxx / ext4 errors=remount-ro,noatime 0 1
mount -o remount / systemctl daemon-reload
|