在 Debian 系统中,“缓存优化”通常涉及 APT 软件包缓存 和 系统/磁盘缓存 两个层面。下面按使用场景给你一套实用优化方案。
sudo apt clean
/var/cache/apt/archives/ 下的所有 .deb 包sudo apt autoclean
clean 安全sudo apt autoremove
编辑源列表:
sudo nano /etc/apt/sources.list
示例(清华源,Debian 12 bookworm):
deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main
deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main
更新:
sudo apt update
sudo nano /etc/apt/apt.conf.d/99parallel
加入:
Acquire::Queue-mode "host";
Acquire::Retries "3";
对高延迟网络效果明显
apt-cacher-ng适合:
安装:
sudo apt install apt-cacher-ng
客户端配置:
Acquire::http::Proxy "http://缓存服务器IP:3142";
Linux 会自动使用空闲内存做磁盘缓存(page cache),通常 不需要手动干预。
查看:
free -h
cat /proc/sys/vm/swappiness
默认通常是 60,可改为 10:
sudo nano /etc/sysctl.conf
加入:
vm.swappiness=10
生效:
sudo sysctl -p
确保挂载参数合理:
mount | grep ext4
推荐参数(/etc/fstab):
noatime,errors=remount-ro
sudo journalctl --vacuum-time=7d
Docker 示例:
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
sudo apt update
sudo apt upgrade
sudo apt autoremove
sudo apt autoclean
你可以补充:
我可以直接给你定制方案。