且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新后不要重新创建存储库

更新时间:2023-01-22 14:26:38

这些存储库是

要么通过更新RPM软件包(例如 centos-release 或通过您设置/运行的自动脚本(可以吗?)。

Those repositories are created by someone, the OS doesn't recreate them.
Either they are restored by an update of a RPM package such as centos-release or by an automatic script you setup/run (ansible?).

我不知道删除存储库的自动方法;我看到了几种解决方案:

I'm not aware of an automatic method to delete a repo; I see a couple of solutions:


  1. 从中排除 centos-release 通过将

    exclude = centos-release

    添加到 / etc / yum中来进行升级。 conf (用空格分隔的列表),但这可能会破坏某些更新;

  1. Exclude centos-release from the upgradable packages, by adding
    exclude=centos-release
    to /etc/yum.conf (space separated list), but this could break some updates;

使用以下命令禁用它们:

Disable them with:

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

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

(this can be easily scripted and put in a cron or in your ansible playbook)

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

Write a small script and place it in /etc/cron.hourly/, e.g. /etc/cron.hourly/wipe_repos, containing:

#!/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,因为回购文件不会被更新覆盖,但是新版本将旧版本放在 .rpmnew $ c $中c>文件。

I would suggest to use solution 2, since the repo files aren't overwritten by updates, but the new versions are placed along the old in .rpmnew files.

这由%config(noreplace)标志在 centos-release ,应用于 /etc/yum.repos.d / 中的所有文件。
您可以通过下载.src.rpm并打开 centos-release.spec 文件来进行检查。

This is guaranteed by the flag %config(noreplace) in the source rpm of centos-release, applied to all files in /etc/yum.repos.d/. You can check this by downloading the .src.rpm and opening the centos-release.spec file.

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

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

(or search for the package online and download the src.rpm)

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

Then scroll down to section %files and you'll notice:

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

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

%config(noreplace) means that all those files are not replaced with new files from an update, but the files from the new rpm are saved with the extension .rpmnew, so you'll have:

$ 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_conf ig.html https://serverfault.com/a/48819/