首页 > 解决方案 > 更新后不要重新创建存储库

问题描述

我们管理系统,从而管理存储库。我们删除了我们不使用的存储库,存在于/etc/yum.repos.d/<file>

我们的问题是:系统更新/升级后,CentOS 会自动重新创建被删除的存储库,这对我们来说是个问题。

问题:是否有命令/方法来确保在 CentOS 7 系统上升级后不会重新创建存储库。

标签: unixcentos

解决方案


这些存储库是由某人创建的,操作系统不会重新创建它们。
它们要么通过更新 RPM 包(例如,centos-release您设置/运行的自动脚本(ansible?))来恢复。

我不知道删除回购的自动方法;我看到了几个解决方案:

  1. 通过添加到(空格分隔列表)centos-release从可升级包中排除,但这可能会破坏一些更新;
    exclude=centos-release
    /etc/yum.conf

  2. 禁用它们:

    # yum-config-manager --disable base,updates,extras,centosplus,epel,whatever
    

    (这可以很容易地编写脚本并放入 cron 或您的 ansible 剧本中)

  3. 编写一个小脚本并将其放入/etc/cron.hourly/,例如/etc/cron.hourly/wipe_repos,包含:

    #!/usr/bin/env bash
    rm -f /etc/yum.repos.d/CentOS-Base.repo 
    

    或更好:

    #!/usr/bin/env bash
    yum-config-manager --disable base,updates,extras,centosplus,epel,whatever
    

我建议使用解决方案 2,因为 repo 文件不会被更新覆盖,但新版本与旧.rpmnew文件一起放置。

%config(noreplace)这是由源 rpm 中的标志保证的centos-release,适用于/etc/yum.repos.d/. 您可以通过下载 .src.rpm 并打开centos-release.spec文件来检查这一点。

$ mkdir test && cd test
$ yumdownloader --source centos-release
$ rpm2cpio centos-release*.rpm | cpio -idmv
$ cat centos-release.spec

(或在线搜索软件包并下载 src.rpm)

然后向下滚动到部分%files,您会注意到:

%config(noreplace) /etc/yum.repos.d/*

%config(noreplace)意味着所有这些文件都不会被更新中的新文件替换,但新 rpm 中的文件以扩展名保存.rpmnew,因此您将拥有:

$ ls /etc/yum.repos.d/
CentOS-Base.repo          <-- here you set them as disabled
CentOS-Base.repo.rpmnew   <-- this comes from the update, but yum will ignore it

如需参考,请参阅http://people.ds.cam.ac.uk/jw35/docs/rpm_config.htmlhttps://serverfault.com/a/48819/


推荐阅读