Red Hat 7 配置 CentOS 7 的 yum 源
由于redhat 的更新包只对注册的用户生效,所以需要自己手动更改成CentOS 的更新包,CentOS几乎和redhat是一样的,所以无需担心软件包是否可安装,下面是安装步骤。
首先查看 RedHat 7.9 系统本身所安装的 yum 软件包
1
2
3
4# rpm -qa |grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-3.4.3-168.el7.noarch
yum-rhn-plugin-2.0.1-10.el7.noarch卸载这些软件包
1
2
3rpm -e yum-metadata-parser-1.1.4-10.el7.x86_64 \
yum-3.4.3-168.el7.noarch \
yum-rhn-plugin-2.0.1-10.el7.noarch --nodeps再次检查,是否卸载干净
1
# rpm -qa |grep yum
下载 CentOS 7.9 相关的 yum 软件包
1
2
3wget http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-rhn-plugin-2.0.1-10.el7.noarch.rpm
wget http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm如果没有 wget 命令可以使用 curl 命令
1
2
3
4curl -O http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
curl -O http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-rhn-plugin-2.0.1-10.el7.noarch.rpm
curl -O http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
curl -O http://mirrors.ustc.edu.cn/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm注意: 如果不下载 yum-plugin-fastestmirror 软件包,安装时可能会报如下错误
1
2
3
4# rpm -ivh yum-*.rpm
warning: yum-3.4.3-168.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
yum-plugin-fastestmirror is needed by yum-3.4.3-168.el7.centos.noarch查看下载好的文件
1
2
3
4
5# ll
-rw-r--r--. 1 root root 1298856 Mar 22 17:13 yum-3.4.3-168.el7.centos.noarch.rpm
-rw-r--r--. 1 root root 28348 Mar 22 17:14 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 35216 Mar 22 17:16 yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
-rw-r--r--. 1 root root 83040 Mar 22 17:14 yum-rhn-plugin-2.0.1-10.el7.noarch.rpm安装软件包
1
2
3
4
5
6
7
8# rpm -ivh yum-*.rpm
warning: yum-3.4.3-168.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%]
2:yum-plugin-fastestmirror-1.1.31-5################################# [ 50%]
3:yum-3.4.3-168.el7.centos ################################# [ 75%]
4:yum-rhn-plugin-2.0.1-10.el7 ################################# [100%]创建 Repo 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44cat > /etc/yum.repos.d/CentOS-Base.repo <<EOF
#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-\$7 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=\$7&arch=\$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-\$7 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=\$7&arch=\$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-\$7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=\$7&arch=\$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
EOF关闭
Red Hat Subscription Manager
订阅管理器,否则它会让你一直 register,如下1
2
3
4
5
6# yum clean all
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: base extras updates执行以下命令禁用它即可
1
sed -i 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/subscription-manager.conf
再次清理缓存,重建元数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22# yum clean all
Loaded plugins: fastestmirror, product-id, search-disabled-repos
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
# yum makecache all
Loaded plugins: fastestmirror, product-id, search-disabled-repos
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/x86_64/primary_db | 6.1 MB 00:00:15
(3/10): extras/x86_64/filelists_db | 277 kB 00:00:00
(4/10): extras/x86_64/primary_db | 246 kB 00:00:00
(5/10): extras/x86_64/other_db | 147 kB 00:00:00
(6/10): base/x86_64/other_db | 2.6 MB 00:00:05
(7/10): base/x86_64/filelists_db | 7.2 MB 00:00:22
(8/10): updates/x86_64/filelists_db | 7.8 MB 00:00:17
(9/10): updates/x86_64/other_db | 1.0 MB 00:00:00
(10/10): updates/x86_64/primary_db | 14 MB 00:00:26
Metadata Cache Created查看 yum 仓库信息
1
2
3
4
5
6
7
8# yum repolist
Loaded plugins: fastestmirror, product-id, search-disabled-repos
Loading mirror speeds from cached hostfile
repo id repo name status
base/x86_64 CentOS-$7 - Base - 163.com 10,072
extras/x86_64 CentOS-$7 - Extras - 163.com 509
updates/x86_64 CentOS-$7 - Updates - 163.com 3,573
repolist: 14,154测试使用 yum 安装软件
1
# yum install -y vim wget bash-completion epel-release