unix - 更新后不要重新创建存储库
问题描述
我们管理系统,从而管理存储库。我们删除了我们不使用的存储库,存在于/etc/yum.repos.d/<file>
我们的问题是:系统更新/升级后,CentOS 会自动重新创建被删除的存储库,这对我们来说是个问题。
问题:是否有命令/方法来确保在 CentOS 7 系统上升级后不会重新创建存储库。
解决方案
这些存储库是由某人创建的,操作系统不会重新创建它们。
它们要么通过更新 RPM 包(例如,centos-release
您设置/运行的自动脚本(ansible?))来恢复。
我不知道删除回购的自动方法;我看到了几个解决方案:
通过添加到(空格分隔列表)
centos-release
从可升级包中排除,但这可能会破坏一些更新;
exclude=centos-release
/etc/yum.conf
禁用它们:
# yum-config-manager --disable base,updates,extras,centosplus,epel,whatever
(这可以很容易地编写脚本并放入 cron 或您的 ansible 剧本中)
编写一个小脚本并将其放入
/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.html或https://serverfault.com/a/48819/。
推荐阅读
- python - Python FTPlib 正在使用 unix clrf 而不是 windows cldf 创建文件
- python - Pandas to openpyxl Workbook 以在 Flask 中下载文件
- neo4j - 如何在节点之间创建随机关系?
- elasticsearch - 将索引从旧版本的 elasticsearch 迁移到 elasticsearch 7.9
- cuda - 如何确保 Vulkan 使用与 CUDA 相同的 GPU?
- c++ - 查找路径是否存在的最有效算法
- reactjs - React JSX Button with Image inside,点击返回值
- google-apps-script - 如何在工作表中指定子范围以执行 sendEmails
- python - 使用中间件重定向到登录页面导致“重定向过多”问题
- pyspark - 使用两个日期列作为范围匹配日期