Redhat安装yum源

环境
  • 系统:Red Hat Enterprise Linux Server release 7.5 (Maipo)
  • 测试yum能否使用:
[root@localhost ~]# yum install tree
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

可以看出yum无法使用。(Redhat只有在注册了之后才可以使用yum,我们替换为centos的yum源)

操作
  1. 检查是否安装yum包
[root@localhost ~]# rpm -qa | grep yum
yum-utils-1.1.31-45.el7.noarch
yum-rhn-plugin-2.0.1-10.el7.noarch
PackageKit-yum-1.1.5-1.el7.x86_64
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-langpacks-0.4.2-7.el7.noarch
yum-3.4.3-158.el7.noarch
[root@localhost ~]# 
  1. 删除自带的yum包
[root@localhost ~]# rpm -qa|grep yum|xargs rpm -e --nodeps
warning: /etc/yum/pluginconf.d/langpacks.conf saved as /etc/yum/pluginconf.d/langpacks.conf.rpmsave
[root@localhost ~]# 
[root@localhost ~]# rpm -qa | grep yum
[root@localhost ~]# 
  1. 下载yum包
[root@localhost ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
[root@localhost ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-163.el7.centos.noarch.rpm
[root@localhost ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
  1. 解压yum包
    这里我的python-iniparse-0.4-9.el7之前已经安装了。
[root@localhost ~]# rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm 
warning: python-iniparse-0.4-9.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
 package python-iniparse-0.4-9.el7.noarch is already installed
 file /usr/lib/python2.7/site-packages/iniparse/ini.pyc from install of python-iniparse-0.4-9.el7.noarch conflicts with file from package python-iniparse-0.4-9.el7.noarch
 file /usr/lib/python2.7/site-packages/iniparse/ini.pyo from install of python-iniparse-0.4-9.el7.noarch conflicts with file from package python-iniparse-0.4-9.el7.noarch

[root@localhost ~]# rpm -ivh yum-*
warning: yum-3.4.3-163.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 ################################# [ 33%]
   2:yum-plugin-fastestmirror-1.1.31-5################################# [ 67%]
   3:yum-3.4.3-163.el7.centos         ################################# [100%]
  1. 替换yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim rhel-source.repo
#rhel-source.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

baseurl=http://mirrors.163.com/centos/7/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7

#released updates

[updates]

name=CentOS-7 - Updates - 163.com

baseurl=http://mirrors.163.com/centos/7/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7


#additional packages that may be useful

[extras]


name=CentOS-7 - Extras - 163.com

baseurl=http://mirrors.163.com/centos/7/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
  1. 清理并重建缓存
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks, 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
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
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                                                                                                                                                               | 165 kB  00:00:00     
(2/10): base/x86_64/primary_db                                                                                                                                                             | 6.0 MB  00:00:01     
(3/10): base/x86_64/filelists_db                                                                                                                                                           | 7.3 MB  00:00:02     
(4/10): extras/x86_64/primary_db                                                                                                                                                           | 164 kB  00:00:00     
(5/10): extras/x86_64/other_db                                                                                                                                                             | 107 kB  00:00:00     
(6/10): base/x86_64/other_db                                                                                                                                                               | 2.6 MB  00:00:00     
(7/10): extras/x86_64/filelists_db                                                                                                                                                         | 217 kB  00:00:00     
(8/10): updates/x86_64/filelists_db                                                                                                                                                        | 4.5 MB  00:00:03     
(9/10): updates/x86_64/other_db                                                                                                                                                            | 573 kB  00:00:00     
(10/10): updates/x86_64/primary_db                                                                                                                                                         | 7.6 MB  00:00:05     
Metadata Cache Created
[root@localhost ~]# yum update -y

再次尝试使用yum安装tree:

Redhat安装yum源

到此,完成。

上一篇:Linux(17)——Mysql配置


下一篇:Centos, Redhat, ubuntu, linux根目录扩容