温馨提示×

ubuntu缓存为何不生效

小樊
34
2026-09-25 04:12:42
栏目: 智能运维

“Ubuntu 缓存不生效”这个问题范围比较广,需要先明确你指的是哪一种缓存。下面我按常见场景分类说明,你可以对照看看是哪一种,以及可能原因和排查办法。


一、APT 软件源缓存(/var/cache/apt/archives)

表现:
sudo apt install xxx 每次都重新下载,之前装过的 .deb 没被复用。

常见原因:

  1. apt-get clean 或 apt clean 清掉了缓存
  2. 使用了 --no-cache / -o Acquire::http::No-Cache=True
  3. 软件源更新导致版本变化
  4. 缓存目录权限异常

排查:

ls -lh /var/cache/apt/archives/
cat /etc/apt/apt.conf.d/* | grep -i cache

解决:

  • 不要随便 apt clean
  • 确认没有禁用缓存配置

二、DNS 缓存(systemd-resolved)

表现:
修改了 /etc/hosts 或 DNS 后不生效,或解析很慢。

常见原因:

  • systemd-resolved 未启用
  • 使用了 dnsmasq 但配置错误
  • 浏览器自己有 DNS 缓存

排查:

systemctl status systemd-resolved
resolvectl status

解决:

sudo systemctl restart systemd-resolved

三、文件系统缓存 / 页缓存(Page Cache)

表现:
多次读文件速度没有变快。

常见原因:

  1. 内存太小,缓存被快速回收
  2. 使用了 direct I/O
  3. 文件在 tmpfs / 网络文件系统上
  4. 刚执行过 echo 3 > /proc/sys/vm/drop_caches

排查:

free -h
cat /proc/meminfo | grep Cache

四、应用层缓存(如 Nginx / Redis / Docker / 浏览器)

表现:
配置了缓存但请求仍打到后端。

常见原因:

  • 缓存目录不可写
  • 缓存 key 设计不合理
  • TTL 设为 0
  • Docker 未挂载 volume,容器重启缓存丢失

五、你可能是说「Ubuntu 系统更新 / 软件安装慢,缓存好像没用」

这通常不是“缓存不生效”,而是:

  • 镜像源慢
  • 缓存已被清
  • 网络问题

建议:

sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sudo apt update

建议你补充的信息

为了更准确帮你,可以告诉我:

  1. 你说的是 哪种缓存?(APT / DNS / 文件 / 应用)
  2. 具体现象是什么?
  3. Ubuntu 版本(lsb_release -a)
  4. 相关配置文件或命令

我可以直接帮你定位并给修复方案。

0 踩