关闭 CentOS 的后台更新服务 dnf makecache 停止系统在后台跑流量

新服务器上的dnf-makecache.service服务定期更新元数据,导致未安装软件的服务器消耗大量流量。通过禁用dnf-makecache.timer定时器,可以避免不必要的流量消耗。

现象

新创建的一台服务器并关联了一个流量包,因为有其他事单个了就啥都没装,结果第二天发现流量包被消耗了1个G。

原因

经过查看系统日志发现,dnf-makecache.service服务一直定期的更新元数据导致消耗流量。

不太能理解的是 dnf 命令执行的时候每次都强制更新,为什么还要有个计划任务一直跑~

Fri 2020-06-19 01:55:13 CST dev-node init.scope[1]: Starting dnf makecache...
Fri 2020-06-19 01:55:13 CST dev-node dnf-makecache.service[5033]: CentOS-8 - AppStream                            257 kB/s | 4.3 kB     00:00
Fri 2020-06-19 01:55:13 CST dev-node dnf-makecache.service[5033]: CentOS-8 - Base                                 341 kB/s | 3.9 kB     00:00
Fri 2020-06-19 01:55:13 CST dev-node dnf-makecache.service[5033]: CentOS-8 - Extras                               130 kB/s | 1.5 kB     00:00
Fri 2020-06-19 01:55:13 CST dev-node dnf-makecache.service[5033]: Extra Packages for Enterprise Linux 8 - x86_64  466 kB/s | 4.7 kB     00:00
Fri 2020-06-19 01:55:13 CST dev-node dnf-makecache.service[5033]: Docker CE Stable - x86_64                       122 kB/s | 3.5 kB     00:00
......

解决方案

执行下面的命令关闭并禁用掉这个定时器。

  • systemctl stop dnf-makecache.timer
  • systemctl disable dnf-makecache.timer
[root@dev-node ~]# systemctl stop dnf-makecache.timer
[root@dev-node ~]# systemctl disable dnf-makecache.timer
Removed /etc/systemd/system/multi-user.target.wants/dnf-makecache.timer.

外网也有人对此问题进行过反馈

# 添加阿里云CentOS 8源(根据实际系统版本调整) sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo # 重建缓存 sudo dnf clean all sudo dnf makecache --2025-10-26 13:25:12-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 116.163.26.61, 182.91.247.74, 36.250.255.64 正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|116.163.26.61|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:2495 (2.4K) [application/octet-stream] 正在保存至: “/etc/yum.repos.d/CentOS-Base.repo” /etc/yum.repos.d/CentOS-Base.repo 100%[===============================================================================================================================>] 2.44K --.-KB/s 用时 0.02s 2025-10-26 13:25:17 (103 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2495/2495]) 正在更新 Subscription Management 软件仓库。 无法读取客户身份 This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register. 正在等待 pid 为3387的进程退出。 正在等待 pid 为3387的进程退出。 正在等待 pid 为3387的进程退出。 ^Z [12]+ 已停止 sudo dnf clean all 正在更新 Subscription Management 软件仓库。 无法读取客户身份 This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register. 正在等待 pid 为3387的进程退出。 ^Z [13]+ 已停止 sudo dnf makecache [root@localhost ~]# # 添加阿里云CentOS 8源(根据实际系统版本调整) sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo # 重建缓存 sudo dnf clean all sudo dnf makecache --2025-10-26 13:25:12-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo 正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 116.163.26.61, 182.91.247.74, 36.250.255.64 正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|116.163.26.61|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:2495 (2.4K) [application/octet-stream] 正在保存至: “/etc/yum.repos.d/CentOS-Base.repo” /etc/yum.repos.d/CentOS-Base.repo 100%[===============================================================================================================================>] 2.44K --.-KB/s 用时 0.02s 2025-10-26 13:25:17 (103 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2495/2495]) 正在更新 Subscription Management 软件仓库。 无法读取客户身份 This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register. 正在等待 pid 为3387的进程退出。 正在等待 pid 为3387的进程退出。 正在等待 pid 为3387的进程退出。 ^Z [12]+ 已停止 sudo dnf clean all 正在更新 Subscription Management 软件仓库。 无法读取客户身份 This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register. 正在等待 pid 为3387的进程退出。 ^Z [13]+ 已停止 sudo dnf makecache [root@localhost ~]#
最新发布
10-27
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值