更新后不要重新创建存储库 [英] Do not re-create repositories after updating
问题描述
我们管理系统,因此也管理存储库。我们删除 /etc/yum.repos.d/<file>
We manage systems and thus manage repositories. We remove repositories which we do not use, present in /etc/yum.repos.d/<file>
我们的问题是:系统更新/升级后,CentOS会自动重新创建已删除的存储库,这对我们来说是个问题。
Our problem is: after an update/upgrade of the system, CentOS automatically re-creates the repositories which were removed, which is an issue for us.
问题:是否有命令/方法来确保在CentOS 7系统上升级后不会重新创建存储库。
Question: Is there a command / method to ensure repositories are not re-created after an upgrade on CentOS 7 systems.
推荐答案
这些存储库是
要么通过更新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:
-
从中排除
centos-release
通过将
exclude = centos-release
添加到/ etc / yum中来进行升级。 conf
(用空格分隔的列表),但这可能会破坏某些更新;
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 <保存/ code>,因此您将拥有:
%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/ 。
这篇关于更新后不要重新创建存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!