CentOS/RHEL/OEL 中“yum clean all”不清除 yum 存储库缓存
on  it road.com

解决方案

“yum clean”删除在 /etc/yum.repos.d/*.repo 中启用的存储库缓存。
从 yum 的手册页:

# man yum
....
CLEAN OPTIONS
The following are the ways which you can invoke yum in clean mode. Note that "all files" in the commands below means "all files in currently enabled
repositories". If you want to also clean any (temporarily) disabled repositories you need to use --enablerepo=’*’ option.

请按照以下步骤进行故障排除:

  1. 暂时启用存储库以清除 yum 缓存。
# yum clean all --enablerepo="repository_label"

或者

# vi /etc/yum.repos.d/[filename].repo
...
enabled = 1    ### Add this for the respective repository.

如果 /etc/yum.repos.d/*.repo 文件中没有关于存储库的信息怎么办?
在这种情况下,存储库文件中带有存储库标签名称的临时条目将有助于清除缓存。

问题

对于使用 Oracle 公共 yum 存储库或者本地 yum 存储库的 orcle Linux 服务器,“Yum clean all”不清除 /var/cache/yum 下的 yum 缓存信息。

# yum repolist
Loaded plugins: refresh-packagekit, security, ulninfo
public_ol6_UEK_latest | 1.2 kB 00:00
public_ol6_UEK_latest/primary | 26 MB 00:04
public_ol6_UEK_latest 554/554
public_ol6_latest | 1.4 kB 00:00
public_ol6_latest/primary | 58 MB 00:04
public_ol6_latest 36051/36051
repo id repo name status
public_ol6_UEK_latest Latest Unbreakable Enterprise Kernel for Oracle Linux 6Ser 554
public_ol6_latest Oracle Linux 6Server Latest (x86_64) 36,051
repolist: 36,605
# du -sh /var/cache/yum/x86_64/6Server/*
864K /var/cache/yum/x86_64/6Server/ol6_addons
973M /var/cache/yum/x86_64/6Server/ol6_latest
367M /var/cache/yum/x86_64/6Server/ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_latest
8.0K /var/cache/yum/x86_64/6Server/public_ol6_UEK_latest
45MB /var/cache/yum/x86_64/6Server/public_ol6_UEKR3_latest
# yum clean all
Loaded plugins: refresh-packagekit, security, ulninfo
Cleaning repos: public_ol6_UEK_latest public_ol6_latest
Cleaning up Everything
# du -sh /var/cache/yum/x86_64/6Server/*
864K /var/cache/yum/x86_64/6Server/ol6_addons
973M /var/cache/yum/x86_64/6Server/ol6_latest
367M /var/cache/yum/x86_64/6Server/ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_latest
8.0K /var/cache/yum/x86_64/6Server/public_ol6_UEK_latest
45MB /var/cache/yum/x86_64/6Server/public_ol6_UEKR3_latest

调试

在以下示例中,仅启用了两个存储库,例如:“public_ol6_UEK_latest、public_ol6_latest”,而 yum 缓存信息可用于少数其他存储库。

让我们假设“public_ol6_UEKR3_latest”存储库被禁用并且“ol6_UEK_latest, ol6_latest”在 /etc/yum.repos.d/*.repo 文件中没有条目。

# yum repolist
Loaded plugins: refresh-packagekit, security, ulninfo
public_ol6_UEK_latest | 1.2 kB 00:00
public_ol6_UEK_latest/primary | 26 MB 00:04
public_ol6_UEK_latest 554/554
public_ol6_latest | 1.4 kB 00:00
public_ol6_latest/primary | 58 MB 00:04
public_ol6_latest 36051/36051
repo id repo name status
public_ol6_UEK_latest Latest Unbreakable Enterprise Kernel for Oracle Linux 6Ser 554
public_ol6_latest Oracle Linux 6Server Latest (x86_64) 36,051
repolist: 36,
# du -sh /var/cache/yum/x86_64/6Server/*
864K /var/cache/yum/x86_64/6Server/ol6_addons
973M /var/cache/yum/x86_64/6Server/ol6_latest
367M /var/cache/yum/x86_64/6Server/ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_latest
8.0K /var/cache/yum/x86_64/6Server/public_ol6_UEK_latest
45MB /var/cache/yum/x86_64/6Server/public_ol6_UEKR3_latest

清除在 /etc/yum.repos.d/*.repo 文件中有条目的禁用存储库的缓存信息。
例如:public_ol6_UEKR3_latest:

# yum clean all --enablerepo="public_ol6_UEKR3_latest"
# du -sh /var/cache/yum/x86_64/6Server/*
864K /var/cache/yum/x86_64/6Server/ol6_addons
973M /var/cache/yum/x86_64/6Server/ol6_latest
367M /var/cache/yum/x86_64/6Server/ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_latest
8.0K /var/cache/yum/x86_64/6Server/public_ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_UEKR3_latest

要清除“/etc/yum.repos.d/*.repo”中没有条目的其他两个存储库的缓存,可以手动删除它或者在配置文件中添加一个临时条目。

# rm -rf /var/cache/yum/x86_64/6Server/ol6_latest /var/cache/yum/x86_64/6Server/ol6_latest

或者

# vi /etc/yum.repos.d/public.repo
[ol6_latest]
enabled = 1
[ol6_UEK_latest]    
enabled = 1
# yum clean all
# du -sh /var/cache/yum/x86_64/6Server/*
864K /var/cache/yum/x86_64/6Server/ol6_addons
12.0K /var/cache/yum/x86_64/6Server/ol6_latest
8.0K /var/cache/yum/x86_64/6Server/ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_latest
8.0K /var/cache/yum/x86_64/6Server/public_ol6_UEK_latest
12K /var/cache/yum/x86_64/6Server/public_ol6_UEKR3_latest
日期:2020-09-17 00:14:16 来源:oir作者:oir