CentOS/Redhat:保护Yum Repo的软件包

时间:2020-01-09 10:43:20  来源:igfitidea点击:

在CentOS/RHEL/Redhat Enterprise Linux下,如何通过yum命令本身来保护/替换某些仓库的yum仓库软件包?

您需要安装yum-protectbase plugin软件包:

该插件允许某些存储库受到保护。
即使非受保护的存储库具有更高版本,受保护的存储库中的软件包也不能被非受保护的存储库中的软件包覆盖。

步骤1:安装yum-protectbase

以root用户身份执行以下命令:

# yum install yum-protectbase

输出示例:

Loaded plugins: downloadonly, rhnplugin, security, verify
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum-protectbase.noarch 0:1.1.16-13.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package                                Arch                          Version                               Repository                                   Size
==============================================================================================================================================================
Installing:
yum-protectbase                        noarch                        1.1.16-13.el5                         rhel-x86_64-server-5                         11 k

Transaction Summary
==============================================================================================================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 11 k
Is this ok [y/N]: y
Downloading Packages:
yum-protectbase-1.1.16-13.el5.noarch.rpm                                                                                               |  11 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : yum-protectbase                                                                                                                        1/1 

Installed:
  yum-protectbase.noarch 0:1.1.16-13.el5                                                                                                                      

Complete!

步骤2:启用插件

编辑/etc/yum/pluginconf.d/protectbase.conf,执行:

# vi /etc/yum/pluginconf.d/protectbase.conf

确保已将启用设置为1:

[main]
enabled = 1

保存并关闭文件。

如何保护基本Repo协议?

将目录更改为/etc/yum.repos.d,执行:

# cd /etc/yum.repos.d
# ls -l

输出示例:

total 16
-rw-r--r-- 1 root root  954 Apr 25  2008 epel.repo
-rw-r--r-- 1 root root 1054 Apr 25  2008 epel-testing.repo
-rw-r--r-- 1 root root  254 Aug  4 03:24 rhel-debuginfo.repo
-rw-r--r-- 1 root root  235 Mar  3  2009 rhel-src.repo

您还可以使用yum repolist命令显示Repo列表:

# yum repolist
Loaded plugins: downloadonly, protectbase, rhnplugin, security, verify
repo id                                                   repo name                                                                             status
epel                                                      Extra Packages for Enterprise Linux 5 - x86_64                                        enabled: 4,512
rhel-src                                                  Red Hat Enterprise Linux 5Server - x86_64 - Source                                    enabled: 2,733
rhel-x86_64-server-5                                      Red Hat Enterprise Linux (v. 5 for 64-bit x86_64)                                     enabled: 8,117
rhel-x86_64-server-vt-5                                   RHEL Virtualization (v. 5 for 64-bit x86_64)                                          enabled:   250
repolist: 15,612

要保护epel.repo存储库,请编辑epel.repo文件,执行:

# vi epel.repo

向每个Repo部分添加保护= 1,如下所示:

[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
protect = 1

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

保存并关闭文件。
现在,epel存储库将受到保护,不会被不受保护的存储库中的更新软件包更新。